Class ModelHelper

    • Constructor Detail

      • ModelHelper

        public ModelHelper()
    • 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 property
        p2 - 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, other wise 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 null
        navigable - 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 null
        navigable - flag
        automaticOwnership - indicates if it should change association end ownership to connected element when its 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 null
        toAssociation - 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 null
        toAssociation - preferred owner: true for association and false for connected element
      • findOwner

        public static NamedElement findOwner​(Property property,
                                             boolean association)
        Finds preferred owner element for the association end.
        Parameters:
        property - association end. Can not be null
        association - 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 - target
        artifact - 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 element
        type - 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
      • findElementWithPath

        @Deprecated
        public static <T extends Element> T findElementWithPath​(java.lang.String path)
        Deprecated.
        use com.nomagic.magicdraw.uml.Finder#byQualifiedName()