Package com.nomagic.magicdraw.uml
Class ClassifierFinder
java.lang.Object
com.nomagic.magicdraw.uml.ClassifierFinder
Utility class for finding and creating classifiers by simple or qualified name.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A resolver of simple classifier name. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Classifier
createClassifier
(String qualifiedName, Class<? extends Classifier> type, Namespace root) Creates a classifier and packages for classifier according qualified classifier name.static Classifier
createClassifier
(String elementName, Class<? extends Classifier> type, List suggestedByDSL, Namespace root) static Classifier
findClassifier
(Project project, String name, Class[] types, Collection restricted, Namespace root) Looks for a classifier by a given name (simple or qualified).static Classifier
findClassifier
(String name, Class<? extends Classifier>[] types, Collection restricted, Collection<Namespace> root) Looks for a classifier of type by a given name (simple or qualified)static Classifier
findClassifierOrDataType
(Project project, String name, Class<? extends Classifier>[] types, Collection restricted, Namespace root) Looks for a classifier of type or standard data type by a given name (simple or qualified).static Classifier
findClassifierOrDataType
(Project project, String name, Collection restricted, Namespace root) Looks for a classifier or standard data type by the given name (simple or qualified).static Classifier
findOrCreateClassifier
(Project project, Element context, String name, ClassifierFinder.SimpleNameResolver simpleNameResolver) Searches for a classifier or standard data type with a given name (qualified or simple).static Classifier
findOrCreateClassifier
(Project project, Element context, String name, ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound) Searches for a classifier or standard data type with a given name (qualified or simple).static Classifier
findOrCreateClassifier
(Project project, Element context, String name, Class<? extends Classifier> createType) Searches for a classifier or standard data type with a given name (qualified or simple).static Classifier
findOrCreateClassifier
(Project project, Element context, String name, Class<? extends Classifier> createType, Collection<Class<? extends Classifier>> searchType, ClassifierFinder.SimpleNameResolver simpleNameResolver) Searches for a classifier or standard data type with a given name (qualified or simple)static Classifier
findOrCreateClassifier
(Project project, Element context, String name, Class<? extends Classifier> createType, Collection<Class<? extends Classifier>> searchType, ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound) Searches for a classifier or standard data type with a given name (qualified or simple)static Classifier
findOrCreateClassifier
(Project project, Element context, String name, Class<? extends Classifier> createType, Collection<Class<? extends Classifier>> searchType, ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound, PresentationElement contextView) Searches for a classifier with given name (simple or qualified).static Namespace
findOrCreateNamespaceForElement
(String qualifiedElementName, Class<? extends Namespace> searchType, Class<? extends Namespace> createType, Namespace root) Returns namespace according given qualified element name.static Namespace
findOrCreatePackageForElement
(String qualifiedElementName, Namespace root) Creates or finds packages using a qualified name of element in the given root.static Classifier
findStandardDataType
(Project project, String name, Collection restricted) Searches for a standard DataType from UMLStandardProfile or MagicDrawProfile modules.static boolean
isQualifiedName
(String elementName) Check if given element name is a qualified name
-
Constructor Details
-
ClassifierFinder
public ClassifierFinder()
-
-
Method Details
-
findClassifier
@CheckForNull public static Classifier findClassifier(Project project, String name, @CheckForNull Class[] types, @CheckForNull Collection restricted, @CheckForNull Namespace root) Looks for a classifier by a given name (simple or qualified).- Parameters:
project
- projectname
- classifier name (simple or qualified)types
- classifier typesrestricted
- allowed DSL elements. Collection should contain stereotypes and/or metaclass classes (java.lang.Class)root
- root element. Null means whole project- Returns:
- found classifier
-
findClassifier
@CheckForNull public static Classifier findClassifier(String name, @CheckForNull Class<? extends Classifier>[] types, @CheckForNull Collection restricted, Collection<Namespace> root) Looks for a classifier of type by a given name (simple or qualified)- Parameters:
name
- classifier name (simple or qualified)types
- classifier typesrestricted
- allowed DSL elements. Collection should contain stereotypes and/or metaclass classes (java.lang.Class)root
- root elements. Empty means whole project- Returns:
- found classifier
-
findStandardDataType
@CheckForNull public static Classifier findStandardDataType(Project project, String name, @CheckForNull Collection restricted) Searches for a standard DataType from UMLStandardProfile or MagicDrawProfile modules.- Parameters:
project
- projectname
- data type namerestricted
- allowed DSL elements. Collection should contain stereotypes and/or metaclass classes (java.lang.Class)- Returns:
- found data type or null
-
findClassifierOrDataType
@CheckForNull public static Classifier findClassifierOrDataType(Project project, String name, @CheckForNull Collection restricted, @CheckForNull Namespace root) Looks for a classifier or standard data type by the given name (simple or qualified).- Parameters:
project
- projectname
- classifier name simple or qualified)restricted
- allowed DSL elements. Collection should contain stereotypes and/or metaclass classes (java.lang.Class)root
- root element. Null means whole project- Returns:
- found classifier
- See Also:
-
findClassifierOrDataType
@CheckForNull public static Classifier findClassifierOrDataType(Project project, String name, @CheckForNull Class<? extends Classifier>[] types, @CheckForNull Collection restricted, @CheckForNull Namespace root) Looks for a classifier of type or standard data type by a given name (simple or qualified).- Parameters:
project
- projectname
- classifier nametypes
- classifier typesrestricted
- Allowed DSL elements. Collection should contain stereotypes and/or metaclass classes (java.lang.Class)root
- root element. Null means whole project- Returns:
- found classifier
- See Also:
-
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(Project project, @CheckForNull Element context, String name, ClassifierFinder.SimpleNameResolver simpleNameResolver) Searches for a classifier or standard data type with a given name (qualified or simple). Creates UML Class if not found. -
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(Project project, @CheckForNull Element context, String name, ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound) Searches for a classifier or standard data type with a given name (qualified or simple). Creates UML Class if not found. -
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(Project project, @CheckForNull Element context, String name, Class<? extends Classifier> createType) Searches for a classifier or standard data type with a given name (qualified or simple). Creates classifier of given type. -
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(Project project, @CheckForNull Element context, String name, Class<? extends Classifier> createType, Collection<Class<? extends Classifier>> searchType, @CheckForNull ClassifierFinder.SimpleNameResolver simpleNameResolver) Searches for a classifier or standard data type with a given name (qualified or simple) -
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(@CheckForNull Project project, @CheckForNull Element context, String name, Class<? extends Classifier> createType, Collection<Class<? extends Classifier>> searchType, @CheckForNull ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound) Searches for a classifier or standard data type with a given name (qualified or simple) -
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(@CheckForNull Project project, @CheckForNull Element context, String name, Class<? extends Classifier> createType, Collection<Class<? extends Classifier>> searchType, @CheckForNull ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound, @CheckForNull PresentationElement contextView) Searches for a classifier with given name (simple or qualified). If such does not exist, creates a classifier with given name. Priorities:- 1. if qualified name is specified, searching by qualified name
- 2. if context is not null, using context to find nearest Package and searching in it
- 3. Searching in all packages
- 4. Searching for standard data type
- getClassifierFor(root, "java::lang::String", Class.class)
- getClassifierFor(javaLangPackage, "String", Class.class)
- getClassifierFor(ioPackage, "Serializable", Interface.class)
- Parameters:
context
- element used to find nearest Package and use it as rootname
- name of classifier. If classifier contains "::" then assuming that name is qualifiedcreateType
- a classifier type to create if not found (for example Class.class or Interface.class)searchType
- a collection of classifier types to search for (for example Class.class or Interface.class)simpleNameResolver
- simple name resolvercontextView
- context viewcreateIfNotFound
- should new classifier be created if existing is not found
-
createClassifier
@CheckForNull public static Classifier createClassifier(String elementName, Class<? extends Classifier> type, @CheckForNull List suggestedByDSL, Namespace root) -
createClassifier
@CheckForNull public static Classifier createClassifier(String qualifiedName, Class<? extends Classifier> type, Namespace root) Creates a classifier and packages for classifier according qualified classifier name.- Parameters:
qualifiedName
- qualifiedNametype
- classifier typeroot
- root namespace- Returns:
- create classifier ir null
-
findOrCreatePackageForElement
@CheckForNull public static Namespace findOrCreatePackageForElement(String qualifiedElementName, Namespace root) Creates or finds packages using a qualified name of element in the given root.- Parameters:
qualifiedElementName
- qualified name of element (not the package!) from a given root elementroot
- parent package where packages will be created- Returns:
- leaf package
-
findOrCreateNamespaceForElement
@CheckForNull public static Namespace findOrCreateNamespaceForElement(String qualifiedElementName, Class<? extends Namespace> searchType, @CheckForNull Class<? extends Namespace> createType, @Nonnull Namespace root) Returns namespace according given qualified element name.- Parameters:
qualifiedElementName
- qualified name of element inside a namespace (not namespace itself!!!)searchType
- class type of namespace to findcreateType
- class type of namespace to create. Null if do not want to create a namespaceroot
- root- Returns:
- found or created namespace element
-
isQualifiedName
Check if given element name is a qualified name- Parameters:
elementName
- name- Returns:
- true if name is a qualified
-