Class UML2ModelUtil

java.lang.Object
com.nomagic.magicdraw.uml2.util.UML2ModelUtil

public class UML2ModelUtil extends Object
Contains various UML2 model related utility methods.
Version:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    checkCompatibility(org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature structuralFeature, Object value)
    Checks whether the specified object and specified feature value is valid.
    static void
    collectAllEClassifiers(org.eclipse.emf.ecore.EPackage ePackage, Collection<org.eclipse.emf.ecore.EClassifier> result)
    Collects all classifiers from the specified package recursively.
    static void
    collectEAllClasses(org.eclipse.emf.ecore.EPackage root, Collection<org.eclipse.emf.ecore.EClass> result)
    Collect all classifiers recursively into specified result collection.
    static Collection<org.eclipse.emf.ecore.EClassifier>
    getAllEClassifiers(org.eclipse.emf.ecore.EPackage aPackage)
    Returns all classifiers from the specified package recursively.
    static String
    getChangePropertyName(org.eclipse.emf.ecore.EObject target, org.eclipse.emf.ecore.EStructuralFeature structuralFeature, Object value)
    Returns change property name.
    static Collection<org.eclipse.emf.ecore.EClassifier>
    getCompatibleTypes(org.eclipse.emf.ecore.EClass eClass, org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns Collection of EClassifiers which instances can be set as values to the specified feature to an instance of the type eClass.
    static String
    getDefault(Property property)
    Returns string representation of the default value of the property.
    static org.eclipse.emf.common.util.EList<org.eclipse.emf.ecore.EClass>
    getEAllSubClasses(org.eclipse.emf.ecore.EClass eClass)
    Returns all subclasses of the specified class.
    static org.eclipse.emf.ecore.EStructuralFeature
    getEStructuralFeature(org.eclipse.emf.ecore.EClass eClass, String publicFeatureName)
    Returns structural feature from the specified class by public feature name.
    static String
    getMOFPackageName(org.eclipse.emf.ecore.EClassifier classifier)
    Returns qualified MOF package name of the EClassifier that represents UML model element metaclass.
    static org.eclipse.emf.ecore.EStructuralFeature
    getOppositeRedefinition(org.eclipse.emf.ecore.EClass eClass, org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns structural feature that redefines the specified feature.
    static String
    getPrivateFeatureName(org.eclipse.emf.ecore.EClass containingClass, String publicFeatureName)
    Returns private name of the specified feature.
    static String
    getPublicFeatureName(org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns public name of the structural feature.
    static List<String>
    getQualifiedMOFPackageName(org.eclipse.emf.ecore.EClassifier classifier)
    Returns qualified MOF package name of the EClassifier that represents UML model element metaclass.
    static List<org.eclipse.emf.ecore.EStructuralFeature>
    getRedefinedFeatures(org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns redefined features of the specified feature.
    static org.eclipse.emf.ecore.EStructuralFeature
    getRedefinition(org.eclipse.emf.ecore.EClass eContainingClass, org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns structural feature that redefines the specified feature.
    static List<org.eclipse.emf.ecore.EStructuralFeature>
    getSortedFeatures(org.eclipse.emf.ecore.EClass eClass)
    Returns sorted features.
    static List<org.eclipse.emf.ecore.EReference>
    getSortedReferences(org.eclipse.emf.ecore.EClass eClass)
    Returns sorted reference.
    static List<org.eclipse.emf.ecore.EStructuralFeature>
    getSubsetFeatures(org.eclipse.emf.ecore.EClass eClass, org.eclipse.emf.ecore.EStructuralFeature supersetFeature, boolean includeDerived, boolean includeMany)
    Returns subset features of the specified superset feature.
    static List<org.eclipse.emf.ecore.EStructuralFeature>
    getSubsettedFeatures(org.eclipse.emf.ecore.EStructuralFeature eStructuralFeature)
    Returns subsetted feature list of the specified feature.
    static List<org.eclipse.emf.ecore.EStructuralFeature>
    getSubsettedFeatures(org.eclipse.emf.ecore.EStructuralFeature eStructuralFeature, boolean recursive)
    Returns subsetted feature list of the specified feature.
    static boolean
    isAssignableFrom(org.eclipse.emf.ecore.EClassifier a, org.eclipse.emf.ecore.EClassifier b)
    Determines if the instance class represented by the first EClassifier object is either the same as, or is a superclass of the instance class represented by the specified second EClassifier parameter.
    static boolean
     
    static boolean
    isCompatible(org.eclipse.emf.ecore.EObject obj, org.eclipse.emf.ecore.EStructuralFeature feature, Object value)
    Checks whether the specified object and specified feature value is valid.
    static boolean
    isContainer(org.eclipse.emf.ecore.EReference reference)
    Returns true if the reference should be treated as container reference.
    static boolean
    isContainment(org.eclipse.emf.ecore.EReference reference)
    Returns true if the reference should be treated as containment reference.
    static boolean
    isDerivedButNotUnion(org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns true if the specified feature is derived but not derived union.
    static boolean
    isDerivedUnion(org.eclipse.emf.ecore.EStructuralFeature feature)
    Checks whether the specified feature is derived union.
    static boolean
    isFullyCompatible(org.eclipse.emf.ecore.EObject obj, org.eclipse.emf.ecore.EStructuralFeature feature, Object value)
    Returns whether the specified object feature can be set to/value added to collection representing value of the feature or can not.
    static boolean
    isMDMultiplicityMany(org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns true if the multiplicity of the property should be treated as many.
    static boolean
    isMDTransient(org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns true if the feature is marked transient in MD.
    static boolean
    isOppositeRedefined(org.eclipse.emf.ecore.EClass eClass, org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns whether the specified feature is redefined.
    static boolean
    isRedefined(org.eclipse.emf.ecore.EClass eContainingClass, org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns whether the specified feature is redefined.
    static boolean
    isRedefinition(org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns true if the specified feature is redefinition of another feature.
    static boolean
    isRenamed(org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns true if the specified feature is renamed.
    static boolean
    isSubsets(org.eclipse.emf.ecore.EReference reference)
     
    static boolean
    isSuperset(org.eclipse.emf.ecore.EClass eClass, org.eclipse.emf.ecore.EStructuralFeature eStructuralFeature)
    Returns true if the specified structural feature in the specified EClass is superset.
    static boolean
    isTransient(org.eclipse.emf.ecore.EStructuralFeature feature)
    Returns true if the feature is transient or marked transient in MD.
    static void
    setCheckCompatibility(boolean checkCompatibility)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • isCheckCompatibility

      public static boolean isCheckCompatibility()
    • setCheckCompatibility

      public static void setCheckCompatibility(boolean checkCompatibility)
    • isDerivedUnion

      public static boolean isDerivedUnion(org.eclipse.emf.ecore.EStructuralFeature feature)
      Checks whether the specified feature is derived union.
      Parameters:
      feature - a feature.
      Returns:
      true if it is derived union.
    • isSubsets

      public static boolean isSubsets(org.eclipse.emf.ecore.EReference reference)
    • getSubsettedFeatures

      public static List<org.eclipse.emf.ecore.EStructuralFeature> getSubsettedFeatures(org.eclipse.emf.ecore.EStructuralFeature eStructuralFeature)
      Returns subsetted feature list of the specified feature. Returns empty list if the features has no subsetted features.
      Parameters:
      eStructuralFeature - feature which subsetted features should be returned.
      Returns:
      list of subsetted features.
    • getSubsettedFeatures

      public static List<org.eclipse.emf.ecore.EStructuralFeature> getSubsettedFeatures(org.eclipse.emf.ecore.EStructuralFeature eStructuralFeature, boolean recursive)
      Returns subsetted feature list of the specified feature. Returns empty list if the features has no subsetted features.
      Parameters:
      eStructuralFeature - feature which subsetted features should be returned.
      recursive - if true then search for subsetted features recursively.
      Returns:
      list of subsetted features.
    • getSubsetFeatures

      public static List<org.eclipse.emf.ecore.EStructuralFeature> getSubsetFeatures(org.eclipse.emf.ecore.EClass eClass, org.eclipse.emf.ecore.EStructuralFeature supersetFeature, boolean includeDerived, boolean includeMany)
      Returns subset features of the specified superset feature.
      Parameters:
      eClass - EClass that is a context of search.
      supersetFeature - superset feature.
      includeDerived - if value is true then derived properties should be included into result.
      includeMany - if true then multivalue features should be included into result.
      Returns:
      list of subset features.
    • isSuperset

      public static boolean isSuperset(org.eclipse.emf.ecore.EClass eClass, org.eclipse.emf.ecore.EStructuralFeature eStructuralFeature)
      Returns true if the specified structural feature in the specified EClass is superset.
      Parameters:
      eClass - EClass object which features will be analysed.
      eStructuralFeature - structural feature.
      Returns:
      true if it is superset.
    • isRedefinition

      public static boolean isRedefinition(org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns true if the specified feature is redefinition of another feature.
      Parameters:
      feature - a feature.
      Returns:
      true if redefinition.
    • isMDTransient

      public static boolean isMDTransient(org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns true if the feature is marked transient in MD. This method does not fully replace isPrivatePropertyName, use isTransient(EStructuralFeature) for this.
      Parameters:
      feature - structural feature.
      Returns:
      true if md transient.
    • isTransient

      public static boolean isTransient(org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns true if the feature is transient or marked transient in MD.
      Parameters:
      feature - structural feature.
      Returns:
      true if transient or md transient.
    • getMOFPackageName

      @CheckForNull public static String getMOFPackageName(org.eclipse.emf.ecore.EClassifier classifier)
      Returns qualified MOF package name of the EClassifier that represents UML model element metaclass. Separator used in the qualified name is '.'
      Parameters:
      classifier - classifier from UML metamodel.
      Returns:
      package name or null if the classifier is not from UML metamodel.
      Throws:
      IllegalArgumentException - if the classifier parameter is null.
    • getQualifiedMOFPackageName

      @CheckForNull public static List<String> getQualifiedMOFPackageName(org.eclipse.emf.ecore.EClassifier classifier)
      Returns qualified MOF package name of the EClassifier that represents UML model element metaclass.
      Parameters:
      classifier - classifier from UML metamodel.
      Returns:
      list of MOF package names null if the classifier is not from UML metamodel.
      Throws:
      IllegalArgumentException - if the classifier parameter is null.
    • collectEAllClasses

      public static void collectEAllClasses(org.eclipse.emf.ecore.EPackage root, Collection<org.eclipse.emf.ecore.EClass> result)
      Collect all classifiers recursively into specified result collection.
      Parameters:
      root - root EPackage.
      result - result collection.
    • getRedefinedFeatures

      public static List<org.eclipse.emf.ecore.EStructuralFeature> getRedefinedFeatures(org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns redefined features of the specified feature.
      Parameters:
      feature - a structural feature.
      Returns:
      redefined features.
    • getRedefinition

      @CheckForNull public static org.eclipse.emf.ecore.EStructuralFeature getRedefinition(org.eclipse.emf.ecore.EClass eContainingClass, org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns structural feature that redefines the specified feature. Uses map for fast search.
      Parameters:
      eContainingClass - containing EClass.
      feature - structural feature that mey be redefined.
      Returns:
      redefinition feature or null if the specified feature is not redefined.
    • getOppositeRedefinition

      @CheckForNull public static org.eclipse.emf.ecore.EStructuralFeature getOppositeRedefinition(org.eclipse.emf.ecore.EClass eClass, org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns structural feature that redefines the specified feature.
      Parameters:
      eClass - containing EClass.
      feature - structural feature that mey be redefined.
      Returns:
      redefinition feature or null if the specified feature is not redefined.
    • isRedefined

      public static boolean isRedefined(org.eclipse.emf.ecore.EClass eContainingClass, org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns whether the specified feature is redefined.
      Parameters:
      eContainingClass - containing EClass.
      feature - structural feature that mey be redefined.
      Returns:
      true if redefined.
    • isOppositeRedefined

      public static boolean isOppositeRedefined(org.eclipse.emf.ecore.EClass eClass, org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns whether the specified feature is redefined.
      Parameters:
      eClass - containing EClass.
      feature - structural feature that mey be redefined.
      Returns:
      true if redefined.
    • isFullyCompatible

      public static boolean isFullyCompatible(org.eclipse.emf.ecore.EObject obj, org.eclipse.emf.ecore.EStructuralFeature feature, Object value)
      Returns whether the specified object feature can be set to/value added to collection representing value of the feature or can not.
      Parameters:
      obj - an object which feature should be analysed.
      feature - a feature that should be analysed.
      value - a value of the feature.
      Returns:
      true if value can be set.
    • isCompatible

      public static boolean isCompatible(org.eclipse.emf.ecore.EObject obj, org.eclipse.emf.ecore.EStructuralFeature feature, Object value)
      Checks whether the specified object and specified feature value is valid.
      Parameters:
      obj - an object.
      feature - a feature that should be checked.
      value - value that should be checked.
      Returns:
      true if compatible.
    • checkCompatibility

      public static void checkCompatibility(org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature structuralFeature, Object value)
      Checks whether the specified object and specified feature value is valid.
      Parameters:
      object - an object.
      structuralFeature - a structural feature.
      value - a value.
      Throws:
      IllegalArgumentException - if the specified value is not compatible.
    • isRenamed

      public static boolean isRenamed(org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns true if the specified feature is renamed.
      Parameters:
      feature - a feature.
      Returns:
      renamed.
    • getPublicFeatureName

      public static String getPublicFeatureName(org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns public name of the structural feature.
      Parameters:
      feature - a structural feature.
      Returns:
      public name.
    • getPrivateFeatureName

      public static String getPrivateFeatureName(org.eclipse.emf.ecore.EClass containingClass, String publicFeatureName)
      Returns private name of the specified feature.
      Parameters:
      containingClass - a class that private feature name should be returned.
      publicFeatureName - public name of the feature.
      Returns:
      private name of the feature.
    • getChangePropertyName

      public static String getChangePropertyName(org.eclipse.emf.ecore.EObject target, org.eclipse.emf.ecore.EStructuralFeature structuralFeature, @CheckForNull Object value)
      Returns change property name.
      Parameters:
      target - owner of the property.
      structuralFeature - feature changed.
      value - value of the property.
      Returns:
      name of the property change.
    • getEStructuralFeature

      public static org.eclipse.emf.ecore.EStructuralFeature getEStructuralFeature(org.eclipse.emf.ecore.EClass eClass, String publicFeatureName)
      Returns structural feature from the specified class by public feature name.
      Parameters:
      eClass - EClass.
      publicFeatureName - public feature name.
      Returns:
      structural feature or null if no such exist.
    • isContainment

      public static boolean isContainment(org.eclipse.emf.ecore.EReference reference)
      Returns true if the reference should be treated as containment reference.
      Parameters:
      reference - a reference.
      Returns:
      true if it is containment reference.
    • isContainer

      public static boolean isContainer(org.eclipse.emf.ecore.EReference reference)
      Returns true if the reference should be treated as container reference.
      Parameters:
      reference - a reference.
      Returns:
      true if it is container reference.
    • getSortedReferences

      public static List<org.eclipse.emf.ecore.EReference> getSortedReferences(org.eclipse.emf.ecore.EClass eClass)
      Returns sorted reference. References are sorted in the order that allows correct sequential modification of reference values.
      Parameters:
      eClass - EClass object.
      Returns:
      references where supersets are in the latest positions.
    • getSortedFeatures

      public static List<org.eclipse.emf.ecore.EStructuralFeature> getSortedFeatures(org.eclipse.emf.ecore.EClass eClass)
      Returns sorted features. Features are sorted in the order that allows correct sequential modification of feature values.
      Parameters:
      eClass - EClass instance.
      Returns:
      sorted features.
    • isDerivedButNotUnion

      public static boolean isDerivedButNotUnion(org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns true if the specified feature is derived but not derived union.
      Parameters:
      feature - a structural feature.
      Returns:
      true if the feature is derived but not derived union.
    • getEAllSubClasses

      public static org.eclipse.emf.common.util.EList<org.eclipse.emf.ecore.EClass> getEAllSubClasses(org.eclipse.emf.ecore.EClass eClass)
      Returns all subclasses of the specified class. The method returns subclasses from the package to which belongs the specified class. If there are other packages that contains classes that extends the specified class then these classes will not be returned. The method return only not abstract classes.
      Parameters:
      eClass - a class which subclasses must be returned.
      Returns:
      list of subclasses.
    • collectAllEClassifiers

      public static void collectAllEClassifiers(org.eclipse.emf.ecore.EPackage ePackage, Collection<org.eclipse.emf.ecore.EClassifier> result)
      Collects all classifiers from the specified package recursively.
      Parameters:
      ePackage - a package from which to collect classifiers.
      result - result collection.
    • getAllEClassifiers

      public static Collection<org.eclipse.emf.ecore.EClassifier> getAllEClassifiers(org.eclipse.emf.ecore.EPackage aPackage)
      Returns all classifiers from the specified package recursively.
      Parameters:
      aPackage - a package.
      Returns:
      result collection.
    • isAssignableFrom

      public static boolean isAssignableFrom(org.eclipse.emf.ecore.EClassifier a, org.eclipse.emf.ecore.EClassifier b)
      Determines if the instance class represented by the first EClassifier object is either the same as, or is a superclass of the instance class represented by the specified second EClassifier parameter.
      Parameters:
      a - first classifier.
      b - second classifier.
      Returns:
      true if assignable.
    • getCompatibleTypes

      public static Collection<org.eclipse.emf.ecore.EClassifier> getCompatibleTypes(org.eclipse.emf.ecore.EClass eClass, org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns Collection of EClassifiers which instances can be set as values to the specified feature to an instance of the type eClass.
      Parameters:
      eClass - EClass object which reference should be analyzed.
      feature - a structural feature which should be analyzed.
      Returns:
      compatible type.
      Throws:
      IllegalArgumentException - if the specified EClass is not from UML package or if the specified feature is not contained by the class.
    • getDefault

      public static String getDefault(Property property)
      Returns string representation of the default value of the property.
      Parameters:
      property - a property.
      Returns:
      default value as string.
    • isMDMultiplicityMany

      public static boolean isMDMultiplicityMany(org.eclipse.emf.ecore.EStructuralFeature feature)
      Returns true if the multiplicity of the property should be treated as many. Otherwise - false.
      Parameters:
      feature - a structural feature.
      Returns:
      true if many otherwise - false.