Package com.nomagic.uml2.ext.jmi.helpers
Class ModelHelper
- java.lang.Object
-
@OpenApiAll public class ModelHelper extends InstanceSpecificationHelper
Model Utility class.
-
-
Constructor Summary
Constructors Constructor Description ModelHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
canAssignType(TypedElement typedElement, Type type)
Check if given Type can be assigned to a given TypedElement.static boolean
canChangeNavigability(Property property)
Checks if navigability of the association end property can be inverted - navigable to non-navigable and vice versa.static boolean
canChangeOwnerTo(Property property, boolean toAssociation)
Checks if association end can be owned by association or connected element.static void
changeOwnerTo(Property property, boolean toAssociation)
Changes ownership of the association end.static Image
createImage(ElementsFactory factory, java.io.File file)
Creates image model element from a given image found in a file.static Image
createImage(ElementsFactory factory, java.lang.String url)
Creates image model element from a given image found at url.static Behavior
findBehaviorFor(Element element)
Finds a defining behavior for a given element.static Deployment
findDeployment(DeploymentTarget deploymentTarget, DeployedArtifact artifact)
Find existing deployment among target and artifactstatic NamedElement
findOwner(Property property, boolean association)
Finds preferred owner element for the association end.static java.util.List<ActivityParameterNode>
getActivityParameterNodes(Activity activity)
Gets activity parameter nodes from a given activity.static BehavioredClassifier
getContext(Behavior behavior)
The classifier that is the context for the execution of the behavior.static ConnectorEnd
getFirstEnd(Connector connector)
Return a first connector endstatic ConnectorEnd
getOppositeEnd(ConnectorEnd end)
Gets opposite connector end for a given connector end.static ConnectorEnd
getSecondEnd(Connector connector)
Return a second connector endstatic boolean
isAggregation(Association association, AggregationKind aggregationKind)
Determines if association is of specified aggregation kind.static boolean
isDirectedAssociation(Association association)
Check if association is directedstatic boolean
isNonNavigableAssociation(Association association)
Check if association is non-navigablestatic boolean
isPropertyEqual(Property p1, Property p2)
Compare the two given Property.static void
setNavigable(Property property, boolean navigable)
Sets navigability of the specified association end.static void
setNavigable(Property property, boolean navigable, boolean automaticOwnership)
Sets navigability of the specified association end.-
Methods inherited from class com.nomagic.uml2.ext.jmi.helpers.InstanceSpecificationHelper
collectAllInstances, createSlot, createSlotsForDefaultValues, createSlotsForDefaultValues, findSlot, getAssignableAssociationsForLink, getAssociationOfLink, getLinksBetweenInstances, getNestedSlot, getSlot, getSlot, getValueBySlot, isInstanceSpecificationCompatibleWithType, isInstanceSpecificationCompatibleWithType, isLink, setClassifierForInstanceSpecification, setClassifierForInstanceSpecification, setSlotValue
-
Methods inherited from class com.nomagic.uml2.ext.jmi.helpers.ClassifierHelper
areEqualParameterTypes, areEqualParameterTypes, associations, associationsIncludingInherited, attributes, checkForDerivedClassifier, collectBaseClassInheritableAttributes, collectCommonAssociations, collectDerivedClassifiersRecursively, collectGeneralClassifiersAndRealizedInterfacesRecursively, collectGeneralClassifiersRecursively, collectInheritedAttributes, collectInheritedBehaviors, collectInheritedEnumerationLiterals, collectInheritedExtensionPoints, collectInheritedOperations, collectInheritedPorts, collectInheritedPureAttributes, collectInheritedPureAttributes, collectInheritedRealizedInterfaces, collectInheritedReceptions, collectInheritedRelations, collectRealizedInterfaces, findAssociationEndForType, findGeneralization, findInterfaceRealization, getAllLiterals, getAssociationEndOwnedByAssociation, getClassifiersIncludingDerived, getClassifiersIncludingDerivedRecursively, getClassifiersIncludingGeneralRecursively, getClassifiersIncludingGeneralRecursively, getDerivedClassifiers, getDerivedClassifiersRecursively, getGeneralClassifiers, getGeneralClassifiersRecursively, getImplementedClasses, getInheritanceDeep, getParameters, getPropertiesWithoutRedefined, getProvided, getRealizedInterfaces, getReturnParameter, getReturnParameter, getReturnParameter, getReturnParameters, isBehavioralFeatureEqual, isClassifierOfType, isClassifierOfType, isDerivedClassifier, isDerivedOrRealizes, isLegalInheritance, isLegalInheritance, isOperationEqual, isReturnParameter, isSameOrDerivedClassifier, isSameOrRedefined, isSecondTypeCompatibleToFirst, isSecondTypeCompatibleToFirst, operations, ports, pureAttributes, receptions, removeDerivedClassifiers, removeRedefined
-
Methods inherited from class com.nomagic.uml2.ext.jmi.helpers.ValueSpecificationHelper
cloneValueSpecification, createValueSpecification, createValueSpecification, createValueSpecification, createValueSpecification, createValueSpecification, getValueSpecificationClass, getValueSpecificationClass, getValueSpecificationValue, getValueString, isValueSpecificationClassElementValue, setValueDisposeIfNeeded, setValueSpecificationValue, setValueSpecificationValue, setValueSpecificationValue
-
Methods inherited from class com.nomagic.uml2.ext.jmi.helpers.CoreHelper
areElementsEditable, canAddChild, canAssignName, canAssignName, canAssignName, canMoveChildInto, canMoveChildInto, collectRelationships, collectRelationships, collectRelationshipsByType, collectRelationshipsIncludeIndirect, dispose, findAcceptableParentFor, findAcceptableParentFor, findOwnerOfStrictType, findOwnerOfStrictTypeIncludingItself, findOwnerOfType, findOwnerOfTypeIncludingItself, findParent, findParent, getAdditionalElementsIterator, getClientElement, getComment, getCommentElement, getCommentElementOrCreate, getDependentClients, getDependentSuppliers, getFirstMemberEnd, getMultiplicity, getName, getOppositeEnd, getOwnedElementsIncludingAdditional, getSecondMemberEnd, getSupplierElement, getSupplierElement, getSupplierElements, hasParentIn, isChildOf, isDocumentationComment, isMultiplicityMany, isParentOf, isParentOf, isRelationship, isRelationshipAlwaysInClient, parseMultiplicityString, setClientElement, setComment, setCommentElement, setConstraintText, setConstraintText, setMultiplicity, setMultiplicity, setSupplierElement
-
-
-
-
Method Detail
-
getActivityParameterNodes
public static java.util.List<ActivityParameterNode> getActivityParameterNodes(Activity activity)
Gets activity parameter nodes from a given activity.- Parameters:
activity
- activity from which parameter nodes must be returned.- Returns:
- a list of activity parameter nodes of a given activity.
-
createImage
public static Image createImage(ElementsFactory factory, java.io.File file)
Creates image model element from a given image found in a file. The method does not start or check sessions.- Parameters:
file
- file in which to look for an image.- Returns:
- created image model element.
-
createImage
public static Image createImage(ElementsFactory factory, java.lang.String url)
Creates image model element from a given image found at url. The method does not start or check sessions.- Parameters:
url
- url- Returns:
- created image model element.
-
isPropertyEqual
public static boolean isPropertyEqual(Property p1, Property p2)
Compare the two given Property.- Parameters:
p1
- First propertyp2
- Second property- Returns:
- boolean
-
canChangeNavigability
public static boolean canChangeNavigability(Property property)
Checks if navigability of the association end property can be inverted - navigable to non-navigable and vice versa. Navigability can not be changed when association of association end (property) is not editable or when connected element is not editable, and it owns association end. We do not check connected element is can own an association end when it's non-navigable, because association end can be explicitly navigable without changing ownership.- Parameters:
property
- association end, can not be null- Returns:
- false if association is read-only or connected element owns association end, and it's read-only, otherwise returns true
-
setNavigable
public static void setNavigable(Property property, boolean navigable)
Sets navigability of the specified association end. It automatically changes ownership if possible.Example: Association assoc = ...; Property secondMemberEnd = ModelHelper.getSecondMemberEnd(assoc); ModelHelper.setNavigable(secondMemberEnd, secondMemberEnd.isNavigable());
- Parameters:
property
- association end. Can not be nullnavigable
- flag
-
setNavigable
public static void setNavigable(Property property, boolean navigable, boolean automaticOwnership)
Sets navigability of the specified association end. It may change ownership of the association end when: - association end changes to non-navigable, and it's owned by connected element. The association becomes an owner of the association end. - association end changes to navigable and automaticOwnership is set to true and connected element is editable and can own association end. The connected element becomes an owner of the association end. At least association has to be editable in order to change association end navigability.- Parameters:
property
- association end. Can not be nullnavigable
- flagautomaticOwnership
- indicates if it should change association end ownership to connected element when it's possible
-
canChangeOwnerTo
public static boolean canChangeOwnerTo(Property property, boolean toAssociation)
Checks if association end can be owned by association or connected element.- Parameters:
property
- association end. Can not be nulltoAssociation
- indicates what kind of ownership shall be checked - true for association and false for connected element- Returns:
- true according to toAssociation argument: if association can own the association end or connected element can own the association end. Returns false if preferred owner is null
-
changeOwnerTo
public static void changeOwnerTo(Property property, boolean toAssociation)
Changes ownership of the association end. It can change owner of the property to association or connected element.- Parameters:
property
- association end. Can not be nulltoAssociation
- preferred owner: true for association and false for connected element
-
findOwner
@CheckForNull public static NamedElement findOwner(Property property, boolean association)
Finds preferred owner element for the association end.- Parameters:
property
- association end. Can not be nullassociation
- preferred owner: true for association and false for connected element- Returns:
- model element or null if such element does not exist
-
findBehaviorFor
@CheckForNull public static Behavior findBehaviorFor(Element element)
Finds a defining behavior for a given element. Only BehaviorClassifier and BehaviorFeature are taken into account- Parameters:
element
- element- Returns:
- behavior
-
isAggregation
public static boolean isAggregation(Association association, AggregationKind aggregationKind)
Determines if association is of specified aggregation kind.- Parameters:
association
- association model element.aggregationKind
- AggregationKindEnum.SHARED - aggregation, AggregationKindEnum.COMPOSITE - composition.- Returns:
- true if one of association ends has set specified aggregation kind
-
isDirectedAssociation
public static boolean isDirectedAssociation(Association association)
Check if association is directed- Parameters:
association
- association- Returns:
- true if at least one end is navigable
-
isNonNavigableAssociation
public static boolean isNonNavigableAssociation(Association association)
Check if association is non-navigable- Parameters:
association
- association- Returns:
- true if both ends are not navigable
-
findDeployment
@CheckForNull public static Deployment findDeployment(DeploymentTarget deploymentTarget, DeployedArtifact artifact)
Find existing deployment among target and artifact- Parameters:
deploymentTarget
- targetartifact
- artifact- Returns:
- existing deployment or null
-
getContext
@CheckForNull public static BehavioredClassifier getContext(Behavior behavior)
The classifier that is the context for the execution of the behavior. A Behavior that is directly owned as a nestedClassifier does not have a context. Otherwise, to determine the context of a Behavior, find the first BehavioredClassifier reached by following the chain of owner relationships from the Behavior, if any. If there is such a BehavioredClassifier, then it is the context, unless it is itself a Behavior with a non-empty context, in which case that is also the context for the original Behavior. For example, following this algorithm, the context of an entry action in a state machine is the classifier that owns the state machine. The features of the context classifier as well as the elements visible to the context classifier are visible to the behavior. (Subsets RedefinableElement::redefinitionContext)- Parameters:
behavior
- behavior for which to get the context.
-
canAssignType
public static boolean canAssignType(TypedElement typedElement, @CheckForNull Type type)
Check if given Type can be assigned to a given TypedElement. For example Property owned by Stereotype (Tag definition) can be typed just by Stereotype, DataType or metaclass.- Parameters:
typedElement
- typed elementtype
- type- Returns:
- true if type can be changed
-
getFirstEnd
@CheckForNull public static ConnectorEnd getFirstEnd(Connector connector)
Return a first connector end- Parameters:
connector
- connector- Returns:
- end
-
getSecondEnd
@CheckForNull public static ConnectorEnd getSecondEnd(Connector connector)
Return a second connector end- Parameters:
connector
- connector- Returns:
- end
-
getOppositeEnd
@CheckForNull public static ConnectorEnd getOppositeEnd(ConnectorEnd end)
Gets opposite connector end for a given connector end.- Parameters:
end
- connector end for which to get opposite end- Returns:
- opposite connector end for a given connector end
-
-