Package com.nomagic.uml2.ext.jmi.helpers
Class CoreHelper
java.lang.Object
com.nomagic.uml2.ext.jmi.helpers.CoreHelper
- Direct Known Subclasses:
ValueSpecificationHelper
Utility class for working with core UML elements
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areElementsEditable
(Collection<? extends Element> elements) Indicates if all elements in a collection are editable.static boolean
canAddChild
(BaseElement parent, BaseElement child) Checks if current element can add given element.static boolean
canAssignName
(String name, NamedElement data, boolean symbol) Checks if given name can be assigned to the given ModelElement.static boolean
canAssignName
(String name, NamedElement data, boolean symbol, boolean showError) Checks if given name can be assigned to the given Element.static boolean
canAssignName
(String name, NamedElement data, boolean symbol, boolean showError, boolean doNotCheckBehavioralFeature) Checks if given name can be assigned to the given ModelElement.static boolean
canMoveChildInto
(Element parent, Element child) Returns true, if child can be moved to the parent.static boolean
canMoveChildInto
(Element parent, Element child, boolean checkPermissions) Returns true, if child can be moved to the parent.static Collection<Element>
collectRelationships
(Element element) Collects connected relations of specified element.static Collection<Element>
collectRelationships
(Element element, Predicate<Element> predicate, boolean includeIndirect) Collects connected relations of specified element.static <T> Collection<T>
collectRelationshipsByType
(Element element, Class<T> relationType, boolean includeIndirect) Collects relations connected to specified element by relation class type.static Collection<Element>
Collects relations connected to specified element and some elements that are owned by that element.static void
dispose
(Collection<? extends Element> elements) Dispose all elements in the given collection.static Element
findAcceptableParentFor
(Element element, Element owner) Goes up in the hierarchy of ownership until owner is found for a given element.static Element
findAcceptableParentFor
(Element element, Element owner, boolean checkPermissions) Goes up in the hierarchy of ownership until owner is found for a given element.static <T extends Element>
TfindOwnerOfStrictType
(Element element, Class<T> ownerType) Finds owner of an element of a specific class type.static <T extends Element>
TfindOwnerOfStrictTypeIncludingItself
(Element element, Class<T> ownerType) Finds owner of an element of a specific class type.static <T extends Element>
TfindOwnerOfType
(Element element, Class<? extends T> ownerType) Searches for first direct or indirect owner of the given type among owners of the given element.static <T extends Element>
TfindOwnerOfTypeIncludingItself
(Element element, Class<? extends T> ownerType) Searches for first direct or indirect owner of the given type among owners of the given element.static Element
findParent
(Element relationship, Element clientME, Element supplierME, Element diagramParent) Looks for a possible parent for given relationship.static Element
findParent
(Element relationship, Element clientME, Element supplierME, Element diagramParent, boolean checkPermissions) Looks for a possible parent for given relationship.getAdditionalElementsIterator
(Element element) Returns iterator of additional contained elements defined in DSL specification by additionalContentProperty.static Element
getClientElement
(Element relationship) Get client of the relationship.static String
getComment
(Element element) Returns documentation of given element.static Comment
getCommentElement
(Element element) Returns documentation Comment for this Element.static Comment
getCommentElementOrCreate
(Element element) Returns documentation Comment for this element.static List<NamedElement>
getDependentClients
(NamedElement element, Class<? extends Dependency> dependencyClass) Collects elements those are connected with Dependencies as clients with a given elementstatic List<NamedElement>
getDependentSuppliers
(NamedElement element, Class<? extends Dependency> dependencyClass) Collects elements those are connected with Dependencies as suppliers with a given elementstatic Property
getFirstMemberEnd
(Association assoc) Get first property member end of association.static String
getMultiplicity
(MultiplicityElement element) Returns multiplicity string for specified multiplicity element.static String
getName
(BaseElement element) Return a name of given elementstatic Element
getOppositeEnd
(Element relationship, Element end) Return opposite relationship endgetOwnedElementsIncludingAdditional
(Element element, boolean includePureOwned) Return owned elements of the given Element including additional owned elements defined in DSL specification by additionalContentProperty.static Property
getSecondMemberEnd
(Association assoc) Get second property member end of association.static Element
getSupplierElement
(Element relationship) Get supplier of the relationship.static Element
getSupplierElement
(Element relationship, boolean takeUserFriendly) Get supplier of the relationship.static Collection<Element>
getSupplierElements
(Collection<? extends Element> relationships) Collect suppliers of the given relationshipsstatic boolean
hasParentIn
(Collection<? extends BaseElement> possibleParents, BaseElement possibleChild) Checks if given object is child of any of the given parent objects.static boolean
isChildOf
(Collection<? extends Element> owners, Element element) Is given element is child of some given owner.static boolean
isDocumentationComment
(Comment comment) Checks if given comment used for storing element documentation.static boolean
isMultiplicityMany
(int value) Check if given value is 'many' -it is more than 1 or is unlimited (-1).static boolean
isParentOf
(BaseElement possibleParent, BaseElement possibleChild) Checks if given object is child of given parent object.static boolean
isParentOf
(Element possibleParent, Element possibleChild) Checks if given object is child of given parent object.static boolean
isRelationship
(Element element) Check if given element is a relationship.static boolean
isRelationshipAlwaysInClient
(Class relationshipClass) Check if relationship if given class type is always owned by a client elementstatic String[]
parseMultiplicityString
(String expression) Parses multiplicity of form 1..* and return array of 2 string [lower, upper] representing boundsstatic void
setClientElement
(Element relationship, Element client) Set client of the relationship.static void
setComment
(Element element, String documentation) Set comment (documentation) for element.static void
setCommentElement
(Element element, Comment comment) Set given Comment as documentation of given Element.static void
setConstraintText
(Constraint constraint, String text, boolean useName, boolean useExpression) Set text for constraint as name or as expressionstatic void
setConstraintText
(Constraint constraint, String text, boolean useName, boolean useExpression, boolean showWarnings) Set text for constraint as name or as expressionstatic void
setMultiplicity
(int lower, int upper, MultiplicityElement element) Set multiplicity to elementstatic void
setMultiplicity
(String expression, MultiplicityElement element) Sets multiplicity for specified multiplicity element.static void
setSupplierElement
(Element relationship, Element supplier) Set supplier of the relationship.
-
Constructor Details
-
CoreHelper
public CoreHelper()
-
-
Method Details
-
hasParentIn
public static boolean hasParentIn(Collection<? extends BaseElement> possibleParents, BaseElement possibleChild) Checks if given object is child of any of the given parent objects.- Parameters:
possibleChild
- possible childpossibleParents
- possible parents- Returns:
- true if the given possibleChild is a child of any of given possibleParents
-
isParentOf
Checks if given object is child of given parent object.- Parameters:
possibleChild
- possible childpossibleParent
- possible parent- Returns:
- true if possibleChild is child of possibleParent.
-
isParentOf
Checks if given object is child of given parent object.- Parameters:
possibleChild
- possible childpossibleParent
- possible parent- Returns:
- true if possibleChild is child of possibleParent
-
setComment
Set comment (documentation) for element. Comment is set on the first element in owned comments collection. If documentation is null or empty string, removed the comment.- Parameters:
element
- element to set documentation.documentation
- documentation text.
-
getComment
Returns documentation of given element.- Parameters:
element
- element to get documentation.- Returns:
- element documentation.
-
getCommentElementOrCreate
Returns documentation Comment for this element. If Comment is not set yet, new Comment is created.- Parameters:
element
- element- Returns:
- comment
-
getCommentElement
Returns documentation Comment for this Element. If Comment is not set, returns null.- Parameters:
element
- element- Returns:
- comment
-
setCommentElement
Set given Comment as documentation of given Element.- Parameters:
element
- elementcomment
- comment
-
isDocumentationComment
Checks if given comment used for storing element documentation.- Parameters:
comment
- comment- Returns:
- true if comment is used as documentation
-
findOwnerOfTypeIncludingItself
@CheckForNull public static <T extends Element> T findOwnerOfTypeIncludingItself(@CheckForNull Element element, Class<? extends T> ownerType) Searches for first direct or indirect owner of the given type among owners of the given element. Checks if the element itself is an instance of given ownerType. If yes, returns it, if no, looks for owner of given instance in all element's ownership hierarchy. If such owner does not exist, returns null.- Parameters:
element
- elementownerType
- the meta class of owner to find. Found owner must be instance of this class- Returns:
- found owner or null
-
findOwnerOfType
@CheckForNull public static <T extends Element> T findOwnerOfType(@CheckForNull Element element, Class<? extends T> ownerType) Searches for first direct or indirect owner of the given type among owners of the given element. Look for owner of given instance in all element's ownership hierarchy. If such owner does not exist, returns null.- Parameters:
element
- element.ownerType
- the meta class of owner to find. Found owner must be instance of this class.- Returns:
- found owner or null.
-
findOwnerOfStrictTypeIncludingItself
@CheckForNull public static <T extends Element> T findOwnerOfStrictTypeIncludingItself(@CheckForNull Element element, Class<T> ownerType) Finds owner of an element of a specific class type.- Parameters:
element
- element for which owner of a specific type should be foundownerType
- class type of the owner- Returns:
- found owner or null if owner of a specific type was not found
-
findOwnerOfStrictType
@CheckForNull public static <T extends Element> T findOwnerOfStrictType(Element element, Class<T> ownerType) Finds owner of an element of a specific class type.- Parameters:
element
- element for which parent of a specific type should be foundownerType
- class type of the owner- Returns:
- found owner or null if owner of a specific type was not found
-
dispose
Dispose all elements in the given collection.- Parameters:
elements
- elements to dispose
-
setMultiplicity
Sets multiplicity for specified multiplicity element.- Parameters:
expression
- values that make sense: "0", "1", "*", "0..*", "1..*", "0..1". If null, multiplicity will become unspecifiedelement
- multiplicity element.
-
parseMultiplicityString
Parses multiplicity of form 1..* and return array of 2 string [lower, upper] representing bounds- Parameters:
expression
- expression
-
getMultiplicity
Returns multiplicity string for specified multiplicity element.- Parameters:
element
- multiplicity element.- Returns:
- multiplicity expression : "0", "1", "*", "0..*", "1..*", "0..1". "" is returned if no multiplicity is set.
-
isMultiplicityMany
public static boolean isMultiplicityMany(int value) Check if given value is 'many' -it is more than 1 or is unlimited (-1).- Parameters:
value
- value- Returns:
- true if value is many
-
setMultiplicity
Set multiplicity to element- Parameters:
lower
- loverupper
- upperelement
- element
-
getSupplierElements
Collect suppliers of the given relationships- Parameters:
relationships
- relationships- Returns:
- suppliers of relationships
-
getSupplierElement
Get supplier of the relationship.- Parameters:
relationship
- relationship model element.
-
getSupplierElement
@CheckForNull public static Element getSupplierElement(Element relationship, boolean takeUserFriendly) Get supplier of the relationship.- Parameters:
relationship
- relationship model element.takeUserFriendly
- take user friendly element in some cases (for example owning classifier instead of template signature)
-
setSupplierElement
Set supplier of the relationship.- Parameters:
relationship
- relationship model element.supplier
- supplier element that will be set to specified relationship model element.
-
getClientElement
Get client of the relationship.- Parameters:
relationship
- relationship model element.- Returns:
- client of given relationship
-
collectRelationships
public static Collection<Element> collectRelationships(Element element, @CheckForNull Predicate<Element> predicate, boolean includeIndirect) Collects connected relations of specified element.- Parameters:
element
- elementpredicate
- filters collected relationsincludeIndirect
- include indirect relations.- Returns:
- relations that are connected to specified element.
-
collectRelationships
Collects connected relations of specified element.- Parameters:
element
- element- Returns:
- relations that are connected to specified element.
-
collectRelationshipsIncludeIndirect
Collects relations connected to specified element and some elements that are owned by that element. For example if element is action collects relations attached to it and it's input or output pins.- Parameters:
element
- element- Returns:
- relations that are connected to specified element and some elements that are owned by that element.
-
collectRelationshipsByType
public static <T> Collection<T> collectRelationshipsByType(Element element, Class<T> relationType, boolean includeIndirect) Collects relations connected to specified element by relation class type.- Parameters:
element
- elementrelationType
- relation class typeincludeIndirect
- should include indirect- Returns:
- relations that are connected to specified element and some elements that are owned by that element.
-
setClientElement
Set client of the relationship.- Parameters:
relationship
- relationship model element.client
- client element that will be set to specified relationship model element.
-
getFirstMemberEnd
Get first property member end of association.- Parameters:
assoc
- association model element.- Returns:
- first property member end of association.
-
getSecondMemberEnd
Get second property member end of association.- Parameters:
assoc
- association model element.- Returns:
- second property member end of association.
-
areElementsEditable
Indicates if all elements in a collection are editable.- Parameters:
elements
- a collection of elements to check- Returns:
- true if all elements in a collection are editable, false otherwise
-
findAcceptableParentFor
@CheckForNull public static Element findAcceptableParentFor(Element element, @CheckForNull Element owner, boolean checkPermissions) Goes up in the hierarchy of ownership until owner is found for a given element.- Parameters:
element
- elementowner
- candidate for ownercheckPermissions
- check editing permissions- Returns:
- found owner or null
-
findAcceptableParentFor
@CheckForNull public static Element findAcceptableParentFor(Element element, @CheckForNull Element owner) Goes up in the hierarchy of ownership until owner is found for a given element. Checks owner editing permissions.- Parameters:
element
- elementowner
- candidate for owner- Returns:
- found owner or null
-
canMoveChildInto
Returns true, if child can be moved to the parent. This can be done if parent can add such child and parent does not have other child with the same name for example. -
canMoveChildInto
Returns true, if child can be moved to the parent. This can be done if parent can add such child and parent does not have other child with the same name. -
canAssignName
public static boolean canAssignName(String name, NamedElement data, boolean symbol, boolean showError) Checks if given name can be assigned to the given Element.- Parameters:
name
- a new name for Elementdata
- a given Elementsymbol
- true if changing symbol nameshowError
- show error in UI in case of name conflict- Returns:
- true if name can be changed
-
canAssignName
Checks if given name can be assigned to the given ModelElement.- Parameters:
name
- a new name for ModelElement.data
- a given ModelElement.symbol
- true if changing symbol name- Returns:
- new name for ModelElement or null if given name can not be assigned to the ModelElement.
-
canAssignName
public static boolean canAssignName(String name, NamedElement data, boolean symbol, boolean showError, boolean doNotCheckBehavioralFeature) Checks if given name can be assigned to the given ModelElement.- Parameters:
name
- a new name for ModelElement.data
- a given ModelElement.symbol
- true if changing symbol nameshowError
- show error in UI in case of name conflict- Returns:
- new name for ModelElement or null if given name can not be assigned to the ModelElement.
-
isRelationship
Check if given element is a relationship. MD treats Transition, ActivityEdge and InstanceSpecifications used as Links as relationships.- Parameters:
element
- element- Returns:
- true if element is relationship
-
getOppositeEnd
Return opposite relationship end- Parameters:
relationship
- relationshipend
- end- Returns:
- opposite end
-
findParent
@CheckForNull public static Element findParent(Element relationship, Element clientME, Element supplierME, @CheckForNull Element diagramParent) Looks for a possible parent for given relationship. Possible parent is calculated according client/supplier and relationship type.- Parameters:
relationship
- relation for which possible parent should be found.clientME
- relationship client elementsupplierME
- relationship supplier elementdiagramParent
- can be null if diagram is not important in context- Returns:
- possible parent for a given relation if found, null otherwise.
-
findParent
@CheckForNull public static Element findParent(Element relationship, Element clientME, Element supplierME, @CheckForNull Element diagramParent, boolean checkPermissions) Looks for a possible parent for given relationship. Possible parent is calculated according client/supplier and relationship type.- Parameters:
relationship
- relation for which possible parent should be found.clientME
- relationship client elementsupplierME
- relationship supplier elementdiagramParent
- can be null if diagram is not important in contextcheckPermissions
- indicates if permissions should be checked.- Returns:
- possible parent for a given relation if found, null otherwise.
-
isRelationshipAlwaysInClient
Check if relationship if given class type is always owned by a client element- Parameters:
relationshipClass
- relationship class type- Returns:
- return true if given relationship is always owned by client element
-
isChildOf
Is given element is child of some given owner.- Parameters:
owners
- the given owners.element
- the given element- Returns:
- true if given element is child of some given owner.
-
getOwnedElementsIncludingAdditional
public static List<Element> getOwnedElementsIncludingAdditional(Element element, boolean includePureOwned) Return owned elements of the given Element including additional owned elements defined in DSL specification by additionalContentProperty.- Parameters:
includePureOwned
- include element owned directly in ownedElement UML meta property- Returns:
- owned elements of the given Element
-
getAdditionalElementsIterator
Returns iterator of additional contained elements defined in DSL specification by additionalContentProperty.- Returns:
- iterator of additional elements
-
getName
Return a name of given element- Parameters:
element
- name- Returns:
- name of give element
-
canAddChild
Checks if current element can add given element.
Uses such rules: 1. current object is not the same as given object. 2. current object is not a child of given object. Current implementation returns false.- Returns:
- true, if checking rules are true.
-
setConstraintText
public static void setConstraintText(Constraint constraint, String text, boolean useName, boolean useExpression) Set text for constraint as name or as expression- Parameters:
constraint
- constrainttext
- textuseName
- set text as nameuseExpression
- set text as expression
-
setConstraintText
public static void setConstraintText(Constraint constraint, String text, boolean useName, boolean useExpression, boolean showWarnings) Set text for constraint as name or as expression- Parameters:
constraint
- constrainttext
- textuseName
- set text as nameuseExpression
- set text as expressionshowWarnings
- shows parsing warnings in UI if there were any
-
getDependentClients
public static List<NamedElement> getDependentClients(NamedElement element, Class<? extends Dependency> dependencyClass) Collects elements those are connected with Dependencies as clients with a given element- Parameters:
element
- the given elementdependencyClass
- dependency class to filter- Returns:
- list of dependent client elements
-
getDependentSuppliers
public static List<NamedElement> getDependentSuppliers(NamedElement element, Class<? extends Dependency> dependencyClass) Collects elements those are connected with Dependencies as suppliers with a given element- Parameters:
element
- the given elementdependencyClass
- dependency class to filter- Returns:
- list of dependent supplier elements
-