Package com.nomagic.uml2.ext.jmi.helpers
Class InstanceSpecificationHelper
- java.lang.Object
-
- com.nomagic.uml2.ext.jmi.helpers.CoreHelper
-
- com.nomagic.uml2.ext.jmi.helpers.ValueSpecificationHelper
-
- com.nomagic.uml2.ext.jmi.helpers.ClassifierHelper
-
- com.nomagic.uml2.ext.jmi.helpers.InstanceSpecificationHelper
-
- Direct Known Subclasses:
ModelHelper
@OpenApiAll public class InstanceSpecificationHelper extends ClassifierHelper
An utility class with utility methods operating on InstanceSpecification domain elements
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.nomagic.uml2.ext.jmi.helpers.ClassifierHelper
ClassifierHelper.PropertyValueGetter, ClassifierHelper.PureAttributesGetter
-
-
Constructor Summary
Constructors Constructor Description InstanceSpecificationHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Collection<InstanceSpecification>
collectAllInstances(Classifier classifier, java.util.Collection<InstanceSpecification> result)
Collect all instances of given classifier.private static void
collectRealizedInterfaces(java.util.Collection<Classifier> res, BehavioredClassifier behavioredClassifier)
Given a behaviored classifier, collects realized interfaces by that classifier.static Slot
createSlot(InstanceSpecification instance, Property property, boolean createDefaultValue)
Creates slot for propertystatic void
createSlotsForDefaultValues(InstanceSpecification instance, boolean createAll)
Creates slots for properties of all assigned classifiers to instance.static void
createSlotsForDefaultValues(InstanceSpecification instance, Classifier classifier, boolean createAll)
Creates slots for properties of given classifier.static Slot
findSlot(InstanceSpecification instanceSpecification, Property property)
Looks for existing slot for a given property in given instance.static java.util.List<Association>
getAssignableAssociationsForLink(InstanceSpecification clientInstance, InstanceSpecification supplierInstance)
Gets available associations which are allowed to assign for a link.static java.util.Collection<Association>
getAssociationOfLink(InstanceSpecification instance)
Gets Association classifier from Link InstanceSpecification, if exists.private static java.util.Collection<Classifier>
getInstanceClassifiersWithHierarchyIncluded(InstanceSpecification instance)
Gets instance classifiers with generalization and interface realization relations included.static java.util.Collection<InstanceSpecification>
getLinksBetweenInstances(InstanceSpecification client, InstanceSpecification supplier)
Returns links found between client and supplier instancesstatic Slot
getNestedSlot(InstanceSpecification instanceSpecification, Property property, java.util.List<Property> path, int index)
static Slot
getSlot(InstanceSpecification instance, Property property, boolean createSlotIfNotExists)
Returns existing of creates a new Slot for the given property.static Slot
getSlot(InstanceSpecification instance, Property property, boolean createSlotIfNotExists, boolean createDefaultValue)
Returns existing of creates a new Slot for the given propertystatic java.lang.Object
getValueBySlot(Slot slot)
Retrieves values of slots as object, not as ValueSpecifications.static boolean
isInstanceSpecificationCompatibleWithType(Classifier type, InstanceSpecification instance)
Checks if given instance specification is compatible with given Type.static boolean
isInstanceSpecificationCompatibleWithType(Classifier type, InstanceSpecification instance, boolean checkInherited)
Checks if given instance specification is compatible with given Type.static boolean
isLink(InstanceSpecification instance)
Checks if InstanceSpecification is Link.static void
setClassifierForInstanceSpecification(Classifier classifier, InstanceSpecification instance, boolean createSlots)
Set classifier for instancestatic void
setClassifierForInstanceSpecification(java.util.Collection<? extends Classifier> classifiers, InstanceSpecification instance, boolean createSlots)
Set classifiers for instancestatic void
setSlotValue(Slot slot, java.lang.String value)
Set slot value from a given string.-
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
-
findSlot
@CheckForNull public static Slot findSlot(InstanceSpecification instanceSpecification, Property property)
Looks for existing slot for a given property in given instance.- Parameters:
instanceSpecification
- instanceproperty
- definingFeature of slot- Returns:
- found slot or null
-
getSlot
@CheckForNull public static Slot getSlot(InstanceSpecification instance, Property property, boolean createSlotIfNotExists)
Returns existing of creates a new Slot for the given property. If new Slot is created, it will be filled with value from the property default values.- Parameters:
instance
- instance specificationproperty
- featurecreateSlotIfNotExists
- create a new slot if needed- Returns:
- slot
-
getSlot
@CheckForNull public static Slot getSlot(InstanceSpecification instance, Property property, boolean createSlotIfNotExists, boolean createDefaultValue)
Returns existing of creates a new Slot for the given property- Parameters:
instance
- instance specificationproperty
- featurecreateSlotIfNotExists
- create a new slot if neededcreateDefaultValue
- fill slot value from property default value- Returns:
- slot
-
createSlotsForDefaultValues
public static void createSlotsForDefaultValues(InstanceSpecification instance, boolean createAll)
Creates slots for properties of all assigned classifiers to instance.- Parameters:
instance
- instancecreateAll
- true, if creates slots for all properties (do not check multiplicity). false, to create slots for properties with mandatory value, i.e. with lower multiplicity >= 1.
-
createSlotsForDefaultValues
public static void createSlotsForDefaultValues(InstanceSpecification instance, Classifier classifier, boolean createAll)
Creates slots for properties of given classifier.- Parameters:
instance
- instanceclassifier
- classifiercreateAll
- true, if creates slots for all properties (do not check multiplicity). false, to create slots for properties with mandatory value, i.e. with lower multiplicity >= 1.
-
createSlot
@CheckForNull public static Slot createSlot(InstanceSpecification instance, Property property, boolean createDefaultValue)
Creates slot for property- Parameters:
instance
- instanceproperty
- propertycreateDefaultValue
- fill slot value from property default value- Returns:
- slot for property
-
setSlotValue
public static void setSlotValue(Slot slot, @CheckForNull java.lang.String value)
Set slot value from a given string. Given string will by parsed by the slot type. For example if slot values are booleans, string should be "true".- Parameters:
slot
- slotvalue
- value string representation.
-
getValueBySlot
@CheckForNull public static java.lang.Object getValueBySlot(@CheckForNull Slot slot)
Retrieves values of slots as object, not as ValueSpecifications. Takes into account multiplicity of slot's defining feature. Collection is returned if slot multiplicity is many.- Parameters:
slot
- slot- Returns:
- value of slot
-
setClassifierForInstanceSpecification
public static void setClassifierForInstanceSpecification(Classifier classifier, InstanceSpecification instance, boolean createSlots)
Set classifier for instance- Parameters:
classifier
- classifierinstance
- instancecreateSlots
- true if slots needs to be created
-
setClassifierForInstanceSpecification
public static void setClassifierForInstanceSpecification(@CheckForNull java.util.Collection<? extends Classifier> classifiers, InstanceSpecification instance, boolean createSlots)
Set classifiers for instance- Parameters:
classifiers
- classifiersinstance
- instancecreateSlots
- true if slots needs to be created- See Also:
createSlotsForDefaultValues(InstanceSpecification, boolean)
-
getAssignableAssociationsForLink
public static java.util.List<Association> getAssignableAssociationsForLink(InstanceSpecification clientInstance, InstanceSpecification supplierInstance)
Gets available associations which are allowed to assign for a link.- Parameters:
clientInstance
- client instance specificationsupplierInstance
- supplier instance specification- Returns:
- a list of assignable associations for a link
-
getInstanceClassifiersWithHierarchyIncluded
private static java.util.Collection<Classifier> getInstanceClassifiersWithHierarchyIncluded(InstanceSpecification instance)
Gets instance classifiers with generalization and interface realization relations included.- Parameters:
instance
- - instance for which classifiers in hierarchy should be collected.- Returns:
- a list of instance classifiers in hierarchy.
-
collectRealizedInterfaces
private static void collectRealizedInterfaces(java.util.Collection<Classifier> res, BehavioredClassifier behavioredClassifier)
Given a behaviored classifier, collects realized interfaces by that classifier.- Parameters:
res
- a set in which results are collected.behavioredClassifier
- behaviored classifier for which realized interfaces should be collected.
-
isLink
public static boolean isLink(@CheckForNull InstanceSpecification instance)
Checks if InstanceSpecification is Link.- Parameters:
instance
- instance to check- Returns:
- true if it is Link element - it has Association as classifier or has a Link symbol in diagram
-
collectAllInstances
public static java.util.Collection<InstanceSpecification> collectAllInstances(Classifier classifier, java.util.Collection<InstanceSpecification> result)
Collect all instances of given classifier. Instances of derived classifiers are also collected.- Parameters:
classifier
- classifierresult
- result collection- Returns:
- result collection
-
isInstanceSpecificationCompatibleWithType
public static boolean isInstanceSpecificationCompatibleWithType(Classifier type, InstanceSpecification instance)
Checks if given instance specification is compatible with given Type. Instance is compatible if its classifiers are compatible with given type.- Parameters:
type
- instance compatibility will be checked against this typeinstance
- instance to check- Returns:
- true if instance is compatible with given type
-
isInstanceSpecificationCompatibleWithType
public static boolean isInstanceSpecificationCompatibleWithType(Classifier type, InstanceSpecification instance, boolean checkInherited)
Checks if given instance specification is compatible with given Type. Instance is compatible if its classifiers are compatible with given type.- Parameters:
type
- instance compatibility will be checked against this typeinstance
- instance to checkcheckInherited
- if set to true, parent type will be treated as compatible.- Returns:
- true if instance is compatible with given type
-
getAssociationOfLink
public static java.util.Collection<Association> getAssociationOfLink(InstanceSpecification instance)
Gets Association classifier from Link InstanceSpecification, if exists.- Parameters:
instance
- Link instance- Returns:
- Associations or empty collection
-
getLinksBetweenInstances
public static java.util.Collection<InstanceSpecification> getLinksBetweenInstances(InstanceSpecification client, InstanceSpecification supplier)
Returns links found between client and supplier instances- Parameters:
client
- instancesupplier
- instance- Returns:
- links
-
getNestedSlot
@CheckForNull public static Slot getNestedSlot(InstanceSpecification instanceSpecification, Property property, java.util.List<Property> path, int index)
-
-