Class fUMLHelper

java.lang.Object
com.nomagic.magicdraw.simulation.fuml.fUMLHelper

@OpenApiAll public class fUMLHelper extends Object
The class contains helper methods for create, access, and modify the fUML object.
  • Constructor Details

    • fUMLHelper

      public fUMLHelper()
  • Method Details

    • getFeatureValueByName

      @CheckForNull public static FeatureValue getFeatureValueByName(@CheckForNull StructuredValue object, String name)
      Returns the FeatureValue from the specified StructuredValue with the specified name. Find the StructuralFeature by getFeatureByName(com.nomagic.magicdraw.simulation.fuml.classes.StructuredValue, java.lang.String)
      Parameters:
      object - the specified StructuredValue
      name - feature value name
      Returns:
      The matched FeatureValue from the specified CompoundValue or null if not found
    • getParameterValueByName

      @CheckForNull public static ParameterValue getParameterValueByName(Execution object, String name)
      Returns the parameter value of the Execution.
      Parameters:
      object - the specified Execution
      name - the parameter value name
      Returns:
      the parameter value of the object
    • getParameterByName

      @CheckForNull public static Parameter getParameterByName(Execution object, String name)
      Returns the instance of Parameter from the specified Execution and parameter's name.
      Parameters:
      object - the specified Execution
      name - the parameter name
      Returns:
      the instance of matched Parameter
    • createValue

      @CheckForNull public static Value createValue(Object o, Object owner, @CheckForNull Locus locus)
      Create the fUML value object with the specified object.
      Parameters:
      o - the specified object
      owner - the specified owner
      locus - locus
      Returns:
      the fUML value object
    • createValueList

      public static ValueList createValueList(@CheckForNull Object value, @CheckForNull Object owner)
      A convenience method for creating the instance of ValueList with assigned values, and return it. If value is instance of ValueList, just return value
      Parameters:
      value - the specified value, It can be collections, arrays, or even the single value.
      owner - of the created value
      Returns:
      ValueList with assigned values.
    • createValueList

      public static ValueList createValueList(Object value, Object owner, Type type)
      A convenience method for creating the instance of ValueList with assigned values, and return it. If value is instance of ValueList, just return value
      Parameters:
      value - the specified value, It can be collections, arrays, or even the single value.
      owner - of the created value
      type - Type of value
      Returns:
      ValueList with assigned values.
    • getObjectFromValueList

      @CheckForNull public static Object getObjectFromValueList(ValueList valueList, int upperMultiplicity)
      Return the value or value list from the fUML value list.
      Parameters:
      valueList - the specified fUML value list
      upperMultiplicity - upper multiplicity
      Returns:
      the value if the size of the value list is 1, otherwise returns the value list
    • getObjectFromValueList

      @CheckForNull public static Object getObjectFromValueList(ValueList valueList, int upperMultiplicity, @CheckForNull TypedElement convertToTypeOf)
      Return the value or value list from the fUML value list.
      Parameters:
      valueList - the specified fUML value list
      upperMultiplicity - upper multiplicity
      convertToTypeOf - in case of the PrimitiveValue, converts the value to the type of this TypedElement. Providing null will return actual value from the list.
      Returns:
      the value if the size of the value list is 1, otherwise returns the value list
    • getObjectFromFeatureValue

      @CheckForNull public static Object getObjectFromFeatureValue(FeatureValue featureValue)
      Return the value or value list from the feature value.
      Parameters:
      featureValue - the specified feature value
      Returns:
      the value if the size of the value list of the feature value is 1, otherwise returns the value list
    • getObjectFromParameterValue

      @CheckForNull public static Object getObjectFromParameterValue(ParameterValue parameterValue)
      Return the value or value list from the parameter value.
      Parameters:
      parameterValue - the specified parameter value
      Returns:
      the value if the size of the value list of the parameter value is 1, otherwise returns the value list
    • getObjectFromValue

      @CheckForNull public static Object getObjectFromValue(@CheckForNull Value value)
      Return the value of the specified fUML value object.
      Parameters:
      value - the fUML object value
      Returns:
      the value of the specified fUML value object
    • getFirstObjectFromValueList

      @CheckForNull public static Object getFirstObjectFromValueList(ValueList valueList)
      Returns the first object in the given valueList if existed.
      Parameters:
      valueList - ValueList
      Returns:
      the first object in the given valueList if existed
    • getFirstObjectFromValueList

      @CheckForNull public static Object getFirstObjectFromValueList(ValueList valueList, boolean returnReference)
      Returns the first object in the given valueList if existed.
      Parameters:
      valueList - ValueList
      returnReference - if this flag is true, if the value is Object_, it will return Reference of that Object_ instead
      Returns:
      the first object in the given valueList if existed
    • getSignalsFromObject

      public static List<Signal> getSignalsFromObject(Object_ object)
      Return the list of signal with the specified object.
      Parameters:
      object - the specified object
      Returns:
      the list of signal
    • getSignalsFromExecution

      public static List<Signal> getSignalsFromExecution(Execution execution)
      Collect the list of signals from the execution. It will find a behavior from the execution and collect signals from that behavior.
      Parameters:
      execution - the specified execution
      Returns:
      the list of signals
    • getFeatureByName

      @CheckForNull public static StructuralFeature getFeatureByName(@CheckForNull StructuredValue object, String featureName)
      Returns the StructuralFeature of the specified CompoundValue with the specified structural feature name.
      Parameters:
      object - the specified CompoundValue(or subclasses) to be used
      featureName - the structural feature name
      Returns:
      the StructuralFeature of the specified CompoundValue
    • setFeatureValue

      public static void setFeatureValue(StructuredValue object, StructuralFeature feature, Object value)
      Find the FeatureValue, and set its value with the value. If value is instance of ValueList, set value to the found FeatureValue, otherwise create the new ValueList and its value and set to the found FeatureValue.

      If want to find FeatureValue from Association(Link), use addFeatureValues(Locus locus, Value valueOwner, StructuralFeature feature, ValueList inputValues, int insertAt, boolean replaceAll)

      Parameters:
      object - the specified object
      feature - the structural feature
      value - the specified value
      See Also:
    • setFeatureValue

      public static void setFeatureValue(@CheckForNull StructuredValue object, StructuralFeature feature, Object value, Locus locus)
      Find the FeatureValue, and set its value with the value. If value is instance of ValueList, set value to the found FeatureValue, otherwise create the new ValueList and its value and set to the found FeatureValue.
      Parameters:
      object - the specified object
      feature - the structural feature
      value - the specified value
      locus - execution locus
    • setFeatureValue

      public static void setFeatureValue(StructuredValue object, String featureName, Object value)
      Find the StructuralFeature from the specified object with the specified structural feature name, and delegates to setFeatureValue(StructuredValue, StructuralFeature, Object).
      Parameters:
      object - the specified object
      featureName - the structural feature name
      value - the specified value
      See Also:
    • setValue

      public static boolean setValue(Value value, @CheckForNull Object o)
      Set the specified value to the fUML value object.
      Parameters:
      value - the fUML value object
      o - the specified value
      Returns:
      true if value was actually set, false if value was not compatible
    • callBehavior

      public static Object callBehavior(StructuredValue object, Behavior behavior, List<?> arguments, SimulationSession session, Boolean synchronous)
      Create the Execution based on the specified Behavior, and execute. The arguments are passed to create the parameter value of the created Execution.
      Parameters:
      object - a context
      behavior - an instance of subclasses of Behavior
      arguments - argument lists
      session - the specified session
      synchronous - true if call synchronously.
      Returns:
      the return value of this execution
    • callOperation

      public static Object callOperation(StructuredValue object, Operation operation, List<?> arguments, SimulationSession session, Boolean synchronous)
      Call the specified Operation.
      Parameters:
      object - the specified object
      operation - the specified Operation
      arguments - argument lists
      session - the running session
      synchronous - is synchronous or not
      Returns:
      the return value of this execution
    • callOperation

      public static Object callOperation(StructuredValue object, Operation operation, List<?> arguments, SimulationSession session, Boolean synchronous, StructuredValue caller)
      Call the specified Operation.
      Parameters:
      object - the specified object
      operation - the specified Operation
      arguments - argument lists
      session - the running session
      synchronous - is synchronous or not
      caller - the specified calling Object_
      Returns:
      the return value of this execution
    • createObject

      @CheckForNull public static Object_ createObject(Class classifier, Object_ context)
      Create the runtime object from the specified classifier.
      Parameters:
      classifier - the specified classifier
      context - the creating object
      Returns:
      the created runtime object
    • setParameterValue

      public static void setParameterValue(Execution execution, String name, Object value)
      Find the Parameter by name from the specified Execution, and delegate to setParameterValue(Execution, Parameter, Object).
      Parameters:
      execution - the specified Execution
      name - name
      value - value
      See Also:
    • setParameterValue

      public static void setParameterValue(Execution execution, Parameter parameter, Object value)
      Find the ParameterValue. The new ValueList is created from value and set to the found Parameter.
      Parameters:
      execution - the specified execution
      parameter - the specified parameter
      value - the value to be set to ParameterValue
    • setParameterValue

      public static void setParameterValue(ParameterValue parameterValue, Object object, boolean isReplaceAll)
      Set the value to the specified ParameterValue. Now it supports only isReplaceAll == true.
      Parameters:
      parameterValue - the specified ParameterValue.
      object - the specified value
      isReplaceAll - if true, replace all existing value
    • getObjectFromTokenList

      @CheckForNull public static Object getObjectFromTokenList(List<Token> tokenList)
      Return the value or value list from the TokenList.
      Parameters:
      tokenList - the specified fUML token list
      Returns:
      the value if the size of the value list is 1, otherwise returns the value list
    • getObjectFromToken

      @CheckForNull public static Object getObjectFromToken(Token token)
      The Object value from the specified Token.
      Parameters:
      token - the specified Token
      Returns:
      the Object value
    • addObjectToValueList

      public static boolean addObjectToValueList(ValueList vList, Object object, Object owner)
      Create the new Value from the object, and add to the last position of the specified ValueList.
      Parameters:
      vList - the specified ValueList
      object - the object being used to create Value
      owner - the specified owner
      Returns:
      true (as specified by Collection.add(E))
    • addFeatureValues

      public static void addFeatureValues(Locus locus, Value valueOwner, StructuralFeature feature, ValueList inputValues, int insertAt, boolean replaceAll)
      Add the specified ValueList to the FeatureValue(matched with the specified StructuralFeature). This method supports insertAt, and replaceAll.
      Parameters:
      locus - the specified locus
      valueOwner - Value
      feature - StructuralFeature
      inputValues - ValueList
      insertAt - the added position
      replaceAll - if true, remove all existing values.
    • getNormativeValues

      public static Collection<String> getNormativeValues(Collection<?> values)
      Get fUML normative values.
      Parameters:
      values - the specified values
      Returns:
      the collection of String representing the specified values
    • buildStringFor

      public static String buildStringFor(Object object)
      Builds String representation for the given object.
      Parameters:
      object - Object
      Returns:
      String representation of the given object
    • buildStringFor

      public static String buildStringFor(Object object, com.nomagic.magicdraw.simulation.utils.ValueRepresentationParams params)
      Builds String representation for the given object.
      Parameters:
      object - Object
      params - representation parameters
      Returns:
      String representation of the given object
    • buildStringFor

      public static String buildStringFor(Collection<?> collection, com.nomagic.magicdraw.simulation.utils.ValueRepresentationParams params, @CheckForNull Map<Integer,Color> colors)
      Builds String representation for the given collection.
      Parameters:
      collection - Collectioninvalid input: '<'?>
      params - representation parameters
      Returns:
      String representation of the given collection
    • getConnectedObjectsViaPort

      public static List<Object_> getConnectedObjectsViaPort(Value value, Port port, SimulationSession session)
      Collect all connected objects via the specified port from the specified value.
      Parameters:
      value - the specified value
      port - the specified port
      session - the specified session
      Returns:
      all connected objects
    • getNormativeValue

      public static void getNormativeValue(Object object, Collection<String> normative)
      Gets the normative value.
      Parameters:
      object - the object
      normative - the normative
    • removeFeatureValue

      public static void removeFeatureValue(Locus locus, Value valueOwner, StructuralFeature feature, @CheckForNull Value value, int removeAt, boolean isRemoveDuplicates)
      Removes the specified value from the FeatureValue that is matched with the specified feature.
      Parameters:
      locus - Locus
      valueOwner - Value
      feature - StructuralFeature
      value - Value
      removeAt - int
      isRemoveDuplicates - boolean
    • getValue

      public static List<FeatureValue> getValue(StructuredValue object, String featureName)
      Returns the list FeatureValue from the specified StructuredValue with the specified feature name. FeatureValue from multiple Link can be collected.
      Parameters:
      object - the specified StructuredValue
      featureName - feature name
      Returns:
      The list of matched FeatureValue from the specified StructuredValue or null if not found
    • getValue

      public static List<FeatureValue> getValue(StructuredValue object, StructuralFeature structuralFeature)
      Returns the list FeatureValue from the specified StructuredValue with the specified structural feature. FeatureValue from multiple Link can be collected.
      Parameters:
      object - the specified StructuredValue
      structuralFeature - structuralFeature
      Returns:
      The list of matched FeatureValue from the specified StructuredValue or null if not found
    • saveValueToInstance

      public static boolean saveValueToInstance(StructuredValue object, InstanceSpecification instance)
      Save the runtime values of the given object to the slots of the given InstanceSpecification.
      Parameters:
      object - is the given runtime object, whose values will be saved to the InstanceSpecification.
      instance - is the given InstanceSpecification for storing the runtime values to its slots.
      Returns:
      true if the runtime values are saved to the given InstanceSpecification successfully. Otherwise, false is returned.
    • sendSignal

      public static void sendSignal(String signalName, Object_ target)
      Create SignalInstance instance of the specified Signal name, and send it to the target Object_.

      If signalName contains "::", it will find the signal from the qualified name, the signal is found if its qualified name is ended with signalName.

      Parameters:
      signalName - the specified Signal name
      target - the specified target Object_
    • sendSignal

      public static void sendSignal(Signal signal, Object_ target)
      Create SignalInstance instance of the specified Signal , and send it to the target Object_.

      Parameters:
      signal - the specified Signal element
      target - the specified target Object_
    • sendSignal

      public static void sendSignal(String signalName, Object_ target, String targetPortName)
      Create SignalInstance instance of the specified Signal name, and send it to the specified target and targetPortName.

      If signalName contains "::", it will find the signal from the qualified name, the signal is found if its qualified name is ended with signalName.

      Parameters:
      signalName - the specified Signal name
      target - the specified target
      targetPortName - the specified target port name
    • sendSignal

      public static void sendSignal(SignalInstance signal, Object_ target)
      Send the specified SignalInstance to the specified target Object_.
      Parameters:
      signal - the specified SignalInstance
      target - the specified target Object_
    • sendSignal

      public static void sendSignal(SignalInstance signal, String targetName)
      Send the specified SignalInstance to the specified targetName.

      If targetName is defined, there are two possible cases.

      • It will find target objects from all waiting objects that have their parts name matched with targetName
      • It will find target objects via connected port, which port name is matched with the specified targetName
      Parameters:
      signal - the specified SignalInstance
      targetName - the specified target object name
    • sendSignal

      public static void sendSignal(SignalInstance signal, Object_ target, String targetPortName)
      Send the specified SignalInstance to the specified target and targetPortName.
      Parameters:
      signal - the specified SignalInstance
      target - the specified target
      targetPortName - the specified target port name
    • findFeatureValue

      public static List<FeatureValue> findFeatureValue(CompoundValue runtimeContext, List<Property> propertyPath, Property target)
      Collect all featureValue objects which are matching with the given nested property path in the given runtime object.
      Parameters:
      runtimeContext - is the runtime object which is the owner of the returned runtime values, specified by propertyPath.
      propertyPath - is the property path to the required runtime values. The first property in the propertyPath must be owned by the classifier that type the owner. to be found.
      target - target Property
      Returns:
      list of runtime values which are reside in the given 'owner' and matching to the given nested propertyPath.