java.lang.Object
com.nomagic.magicdraw.simulation.utils.ALH

@OpenApiAll public final class ALH extends Object
An Action Language Helper for using in scripts to access values of the runtime object.
Since:
SIM 1.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    ALH()
    Constructor.
    Constructor.
    Constructor.
    ALH(SimulationSession session, List<NamedElement> trace, fUML.Semantics.Classes.Kernel.Object_ context)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addValue(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName, Object value)
    Find the matched FeatureValue from the specified object, and set the value at the last position of the value list.
    void
    addValueAt(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName, Object value, Integer insertAt)
    Find the matched FeatureValue from the specified object, and set the value at the insertAt position.
    Execute the Behavior element that matches the specified name.
    callBehavior(String name, List<?> arguments)
    Execute the CallBehaviorAction element that matches the specified name.
    callBehavior(String name, List<?> arguments, boolean isSynchonous)
    Execute the CallBehaviorAction element that matches the specified name.
    callOperation(fUML.Semantics.Classes.Kernel.Object_ object, String name)
    Execute the method of the Operation element that matches the specified name.
    callOperation(fUML.Semantics.Classes.Kernel.Object_ object, String name, List<?> arguments)
    Execute the method of the Operation element that matches the specified name.
    callOperation(fUML.Semantics.Classes.Kernel.Object_ object, String name, List<?> arguments, boolean isSynchonous)
    Execute the method of the Operation element that matches the specified name.
    Execute the method of the Operation element that matches the specified name.
    callOperation(String name, List<?> arguments)
    Execute the method of the Operation element that matches the specified name.
    A convenience method for creating the list.
    A convenience method for creating the list with one added item in the list.
    fUML.Semantics.Classes.Kernel.Object_
    createObject(Class classifier)
    Create an Object_ with the given type (which must be a Class) in the Locus of the active SimulationSession.
    fUML.Semantics.Classes.Kernel.Object_
    Create an Object_ with the given name (which must be name of Class) as its type.
    fUML.Semantics.CommonBehaviors.Communications.SignalInstance
    Create the instance of SignalInstance.
    fUML.Semantics.CommonBehaviors.Communications.SignalInstance
    Create the instance of SignalInstance.
    evaluate(String expression)
    Evaluate the string expression.
    evaluate(String language, String expression)
    Evaluate the string expression based on the specified scripting language.
    Get the calling element of the script evaluation.
    fUML.Semantics.Classes.Kernel.Object_
    Get the context of ALH.
    double
    Gets current time.
    double
    Gets current time in forms of the specified timeUnit.
    getGlobalVariable(String variableName)
    Gets global variable from the execution.
    fUML.Semantics.CommonBehaviors.Communications.SignalInstance
    getLastSignal(fUML.Semantics.Classes.Kernel.Object_ o)
    Get the last signal instance from the event pool.
    getState(fUML.Semantics.Classes.Kernel.Object_ object)
    Get the current State from the specified object.
    getTagValue(fUML.Semantics.Classes.Kernel.Object_ object, String tagName)
    Get tag value from classifier of Object, and structural feature that Object represented
    Get tag value from classifier of context.
    Gets time unit of the running execution.
    Get Tokens values from the current context.
    getValue(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName)
    Get the value of FeatureValue from the object that match the specified StructureFeature name.
    boolean
    inState(fUML.Semantics.Classes.Kernel.Object_ object, String stateName)
    Check whether the specified object is in the specified state name or not.
    boolean
    inState(String stateName)
    Check whether the current runtime object is in the specified state name or not.
    isGlobalVariable(String variableName)
    Checks whether or not the given variableName is global variable.
    void
    Removes global variable from the execution.
    void
    removeValue(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName, fUML.Semantics.Classes.Kernel.Value value)
    Find the matched FeatureValue from the specified object, remove the defined value or the value at removeAt position.
    void
    removeValueAt(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName, Integer removeAt)
    Find the matched FeatureValue from the specified object, remove the defined value or the value at removeAt position.
    void
    sendSignal(fUML.Semantics.CommonBehaviors.Communications.SignalInstance signal, fUML.Semantics.Classes.Kernel.Object_ target)
    Send the specified SignalInstance to the specified target Object_.
    void
    sendSignal(fUML.Semantics.CommonBehaviors.Communications.SignalInstance signal, fUML.Semantics.Classes.Kernel.Object_ target, String portName)
    Send the specified SignalInstance to the specified target Object_ via the specified port name.
    void
    sendSignal(fUML.Semantics.CommonBehaviors.Communications.SignalInstance signal, String targetName)
    Send the specified SignalInstance to the specified targetName.
    void
    sendSignal(String signalName, fUML.Semantics.Classes.Kernel.Object_ target)
    Create SignalInstance instance of the specified Signal name, and send it to the target Object_.
    void
    sendSignal(String signalName, fUML.Semantics.Classes.Kernel.Object_ target, String portName)
    Create SignalInstance instance of the specified Signal name, and send it to the target Object_ via the specified port name.
    void
    sendSignal(String signalName, String targetName)
    Create SignalInstance instance of the specified Signal name, and send it to the specified targetName.
    void
    setGlobalVariable(String variableName, Object value)
    Sets global variable for the execution.
    void
    setValue(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName, Object value)
    Find the matched FeatureValue from the specified object, and set the value.
    void
    setValue(String featureName, Object value)
    Find the matched FeatureValue from the context, and set the value.
    boolean
    wasInState(fUML.Semantics.Classes.Kernel.Object_ object, String stateName)
    Check that the state matching with the name was already visited or not.
    boolean
    wasInState(String stateName)
    Check that the state matching with the name was already visited or not.

    Methods inherited from class java.lang.Object

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

    • ALH

      public ALH()
      Constructor.
    • ALH

      public ALH(SimulationSession session)
      Constructor.
      Parameters:
      session - the running session
    • ALH

      public ALH(SimulationSession session, List<NamedElement> trace)
      Constructor.
      Parameters:
      session - the running session
      trace - trace
    • ALH

      public ALH(@CheckForNull SimulationSession session, List<NamedElement> trace, fUML.Semantics.Classes.Kernel.Object_ context)
      Constructor.
      Parameters:
      session - the running session
      trace - trace
      context - the context
  • Method Details

    • getContext

      @CheckForNull public fUML.Semantics.Classes.Kernel.Object_ getContext()
      Get the context of ALH.
      Returns:
      context of ALH.
    • getValue

      @CheckForNull public Object getValue(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName)
      Get the value of FeatureValue from the object that match the specified StructureFeature name. It supports nested structural features.
      Parameters:
      object - the specified instance of StructuredValue(or its subclasses)
      featureName - the specified name, it will check with StructuralFeature name, nested structural features such as "part1.part2" are allowed.
      Returns:
      the value of FeatureValue
      Throws:
      IllegalArgumentException - if object or featureName is null.
      See Also:
    • setValue

      public void setValue(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName, Object value)
      Find the matched FeatureValue from the specified object, and set the value. If not found, create the new FeatureValue and add to the specified object. It supports nested structural features.

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

      Parameters:
      object - the fUML runtime Object_ or SignalInstance
      featureName - the name of structural feature, nested structural features such as "part1.part2" are allowed.
      value - the value to be set. Can be Java value or fUML Value.
      Throws:
      IllegalArgumentException - if object or featureName is null.
      See Also:
    • setValue

      public void setValue(String featureName, Object value)
      Find the matched FeatureValue from the context, and set the value. If not found, create the new FeatureValue and add to the context. It supports nested structural features.

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

      Parameters:
      featureName - the name of structural feature, nested structural features such as "part1.part2" are allowed.
      value - the value to be set. Can be Java value or fUML Value.
      Throws:
      IllegalArgumentException - if object or featureName is null.
      See Also:
    • addValue

      public void addValue(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName, Object value)
      Find the matched FeatureValue from the specified object, and set the value at the last position of the value list.
      Parameters:
      object - the fUML runtime Object_ or SignalInstance
      featureName - the name of structural feature, nested structural features such as "part1.part2" are allowed.
      value - the value to be set. Can be Java value or fUML Value.
    • addValueAt

      public void addValueAt(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName, Object value, Integer insertAt)
      Find the matched FeatureValue from the specified object, and set the value at the insertAt position.
      Parameters:
      object - the fUML runtime Object_ or SignalInstance
      featureName - the name of structural feature, nested structural features such as "part1.part2" are allowed.
      value - the value to be set. Can be Java value or fUML Value.
      insertAt - the inserted position. if it is not more than 0, the value will be added at the last position.
    • removeValue

      public void removeValue(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName, fUML.Semantics.Classes.Kernel.Value value)
      Find the matched FeatureValue from the specified object, remove the defined value or the value at removeAt position.
      Parameters:
      object - the fUML runtime Object_ or SignalInstance
      featureName - the name of structural feature, nested structural features such as "part1.part2" are allowed.
      value - the fUML value to be removed.
    • removeValueAt

      public void removeValueAt(fUML.Semantics.Classes.Kernel.StructuredValue object, String featureName, Integer removeAt)
      Find the matched FeatureValue from the specified object, remove the defined value or the value at removeAt position.
      Parameters:
      object - the fUML runtime Object_ or SignalInstance
      featureName - the name of structural feature, nested structural features such as "part1.part2" are allowed.
      removeAt - if the removeAt is defined. it will remove the value at removeAt position, ignoring the value value
    • getState

      @CheckForNull public State getState(fUML.Semantics.Classes.Kernel.Object_ object)
      Get the current State from the specified object. If object has more than one active states, return the first one.
      Parameters:
      object - the instance of Object_(or its subclasses)
      Returns:
      the current State from the specified object
      Throws:
      IllegalArgumentException - if object is null.
    • getTokenValue

      public Object getTokenValue()
      Get Tokens values from the current context.
      Returns:
      the instance of subclasses of the Object representing the token values of the current context
    • getLastSignal

      public fUML.Semantics.CommonBehaviors.Communications.SignalInstance getLastSignal(fUML.Semantics.Classes.Kernel.Object_ o)
      Get the last signal instance from the event pool.
      Parameters:
      o - the specified object
      Returns:
      the last signal instance from the list
    • createObject

      @CheckForNull public fUML.Semantics.Classes.Kernel.Object_ createObject(Class classifier)
      Create an Object_ with the given type (which must be a Class) in the Locus of the active SimulationSession.
      Parameters:
      classifier - the instance of Class(or its subclasses)
      Returns:
      the created Object_, or null if classifier is not instance of Class
    • createObject

      public fUML.Semantics.Classes.Kernel.Object_ createObject(String name)
      Create an Object_ with the given name (which must be name of Class) as its type. The name is used to search from com.nomagic.uml2.ext.magicdraw.auxiliaryconstructs.mdmodels.Model of the current Project.
      Parameters:
      name - the specified Class name
      Returns:
      the created Object_
      See Also:
    • callOperation

      public Object callOperation(String name)
      Execute the method of the Operation element that matches the specified name.
      Parameters:
      name - the specified name of Operation
      Returns:
      the return value of the execution.
      See Also:
    • callOperation

      @CheckForNull public Object callOperation(String name, @CheckForNull List<?> arguments)
      Execute the method of the Operation element that matches the specified name.
      Parameters:
      name - the specified name of Operation
      arguments - argument values
      Returns:
      the return value of the execution.
      See Also:
    • callOperation

      public Object callOperation(fUML.Semantics.Classes.Kernel.Object_ object, String name)
      Execute the method of the Operation element that matches the specified name.
      Parameters:
      object - The target object to which the request is sent
      name - the specified name of Operation
      Returns:
      the return value of the execution.
      See Also:
    • callOperation

      public Object callOperation(fUML.Semantics.Classes.Kernel.Object_ object, String name, List<?> arguments)
      Execute the method of the Operation element that matches the specified name.
      Parameters:
      object - The target object to which the request is sent
      name - the specified name of Operation
      arguments - argument values
      Returns:
      the return value of the execution.
      See Also:
    • callOperation

      public Object callOperation(fUML.Semantics.Classes.Kernel.Object_ object, String name, List<?> arguments, boolean isSynchonous)
      Execute the method of the Operation element that matches the specified name.
      Parameters:
      object - The target object to which the request is sent
      name - the specified name of Operation
      arguments - argument values
      isSynchonous - true if call synchronously, false --> asynchronously
      Returns:
      the return value of the execution.
      See Also:
    • callBehavior

      public Object callBehavior(String name)
      Execute the Behavior element that matches the specified name.
      Parameters:
      name - the specified name of Behavior
      Returns:
      the return value of the execution.
      See Also:
    • callBehavior

      public Object callBehavior(String name, List<?> arguments)
      Execute the CallBehaviorAction element that matches the specified name.
      Parameters:
      name - the specified name of Behavior
      arguments - argument values
      Returns:
      the return value of the execution.
      Throws:
      IllegalArgumentException - if cannot find Behavior or size of arguments are not equal to in/inout parameters size.
      See Also:
    • callBehavior

      public Object callBehavior(String name, @CheckForNull List<?> arguments, boolean isSynchonous)
      Execute the CallBehaviorAction element that matches the specified name.
      Parameters:
      name - the specified name of Behavior
      arguments - argument values
      isSynchonous - true if call synchronously, false --> asynchronously
      Returns:
      the return value of the execution.
      Throws:
      IllegalArgumentException - if cannot find Behavior or size of arguments are not equal to in/inout parameters size.
      See Also:
    • sendSignal

      public void sendSignal(String signalName, fUML.Semantics.Classes.Kernel.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 void sendSignal(String signalName, String targetName)
      Create SignalInstance instance of the specified Signal name, and send it to the specified targetName.

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

      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:
      signalName - the specified Signal name
      targetName - the specified target object name
    • sendSignal

      public void sendSignal(String signalName, fUML.Semantics.Classes.Kernel.Object_ target, String portName)
      Create SignalInstance instance of the specified Signal name, and send it to the target Object_ via the specified port name.

      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_
      portName - the specified port name
    • sendSignal

      public void sendSignal(fUML.Semantics.CommonBehaviors.Communications.SignalInstance signal, fUML.Semantics.Classes.Kernel.Object_ target)
      Send the specified SignalInstance to the specified target Object_.
      Parameters:
      signal - the specified SignalInstance
      target - the specified target Object_
    • sendSignal

      public void sendSignal(fUML.Semantics.CommonBehaviors.Communications.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 void sendSignal(fUML.Semantics.CommonBehaviors.Communications.SignalInstance signal, fUML.Semantics.Classes.Kernel.Object_ target, String portName)
      Send the specified SignalInstance to the specified target Object_ via the specified port name.
      Parameters:
      signal - the specified SignalInstance
      target - the specified target Object_
      portName - the specified port name
    • evaluate

      @CheckForNull public Object evaluate(String language, String expression)
      Evaluate the string expression based on the specified scripting language.
      Parameters:
      language - the specified scripting language
      expression - the specified string expression
      Returns:
      the evaluation result
    • evaluate

      public Object evaluate(String expression)
      Evaluate the string expression.
      Parameters:
      expression - the specified string expression
      Returns:
      the evaluation result
    • createList

      public ArrayList<Object> createList()
      A convenience method for creating the list. The new empty ArrayList is created and returned.
      Returns:
      the new empty ArrayList
    • createList

      public ArrayList<Object> createList(Object object)
      A convenience method for creating the list with one added item in the list. The new empty ArrayList is created and being added the specified item.
      Parameters:
      object - the specified item being added to the created list
      Returns:
      the new empty ArrayList with the added item
    • inState

      public boolean inState(String stateName)
      Check whether the current runtime object is in the specified state name or not.
      Parameters:
      stateName - the specified state name
      Returns:
      true if one of the active states matches with the specified state name
    • inState

      public boolean inState(fUML.Semantics.Classes.Kernel.Object_ object, String stateName)
      Check whether the specified object is in the specified state name or not.
      Parameters:
      object - the specified object
      stateName - the specified state name
      Returns:
      true if one of the active states matches with the specified state name
    • wasInState

      public boolean wasInState(String stateName)
      Check that the state matching with the name was already visited or not.
      Parameters:
      stateName - the state name
      Returns:
      true, if yes
    • wasInState

      public boolean wasInState(fUML.Semantics.Classes.Kernel.Object_ object, String stateName)
      Check that the state matching with the name was already visited or not.
      Parameters:
      object - the object
      stateName - the state name
      Returns:
      true, if yes
    • createSignal

      public fUML.Semantics.CommonBehaviors.Communications.SignalInstance createSignal(Signal signal)
      Create the instance of SignalInstance.
      Parameters:
      signal - the specified Signal
      Returns:
      the created SignalInstance
    • createSignal

      @CheckForNull public fUML.Semantics.CommonBehaviors.Communications.SignalInstance createSignal(String keyword)
      Create the instance of SignalInstance.
      Parameters:
      keyword - the keyword for find Signal
      Returns:
      the created SignalInstance
    • getTimeUnit

      public String getTimeUnit()
      Gets time unit of the running execution.
      Returns:
      Time unit.
    • getCurrentTime

      public double getCurrentTime()
      Gets current time.
      Returns:
      Current time
    • getCurrentTime

      public double getCurrentTime(String timeUnit)
      Gets current time in forms of the specified timeUnit.
      Parameters:
      timeUnit - the unit of time, that the current time should be converted to. Valid parameters: "nanosecond"/"ns", "microsecond"/"µs", "millisecond"/"ms", "second"/"s", "minute"/"min", "hour"/"h", "day"/"d", "week"/"w", "month"/"mo", "year"/"y"
      Returns:
      Current time in the unit of specified timeUnit.
    • getGlobalVariable

      public Object getGlobalVariable(String variableName)
      Gets global variable from the execution.
      Parameters:
      variableName - Variable name
      Returns:
      global variable value. if the global variable does not exist, return null.
    • setGlobalVariable

      public void setGlobalVariable(String variableName, Object value)
      Sets global variable for the execution.
      Parameters:
      variableName - Variable name
      value - Variable value
    • isGlobalVariable

      public Boolean isGlobalVariable(String variableName)
      Checks whether or not the given variableName is global variable.
      Parameters:
      variableName - Variable name
      Returns:
      true, if the given variableName is global variable. Otherwise, false.
    • removeGlobalVariable

      public void removeGlobalVariable(String variableName)
      Removes global variable from the execution.
      Parameters:
      variableName - Variable name
    • getCaller

      public NamedElement getCaller()
      Get the calling element of the script evaluation.
      Returns:
      the calling element of the script evaluation
    • getTagValue

      public Object getTagValue(String tagName) throws Exception
      Get tag value from classifier of context.
      Parameters:
      tagName - the tag name possible to be the dot notation.
      Returns:
      the value of tagName as the primitive object.
      Throws:
      Exception - the exception
    • getTagValue

      public Object getTagValue(@CheckForNull fUML.Semantics.Classes.Kernel.Object_ object, String tagName) throws Exception
      Get tag value from classifier of Object, and structural feature that Object represented
      Parameters:
      object - the runtime object
      tagName - the tag name possible to be the dot notation.
      Returns:
      the value of tagName as the primitive object.
      Throws:
      Exception - the exception