Language of an executable opaque behavior can be OCL 2.0, binary, BeanShell, Groovy, JRuby, JavaScript, Jython, or StructuredExpression. Also, it must have the proper number of parameters with proper types.
The number of parameters an opaque behavior can have depends on the selected language of the opaque behavior body:
To create a parameter for the opaque behavior
Specify the multiplicity of the parameter: either select a value from the drop-down list or type a new one.
In this case, only the upper bound of the multiplicity is important. For example, the multiplicity [0..1] has the same meaning as the multiplicity [1]. |
Specify the type of the parameter: either select a value from the drop-down list or create a new one by typing directly in the cell.
Available types:
|
Whether the arguments are ordered.
If you do not see the Is Unique and Is Ordered properties, select All from the Properties drop-down list in the upper right of the Specification window. |
The following instructions applies to BeanShell, Groovy, JRuby, JavaScript, and Jython scripts only. |
To access an argument from a script body, you should refer to the corresponding parameter name.
The script body can access the following values:
The following instructions applies to BeanShell, Groovy, JRuby, JavaScript, and Jython scripts only. |
The script can have multiple statements. In this case the result of the entire script is the result of the last statement.
Limitations in Jython make it so returning a value from the multi-statement Jython script is not straightforward. Instead of:
<statement1> ... <statement n> <expression returning result> |
you have to use result.set(... ):
<statement1> ... <statement n> result.set(<expression returning result>) |
The following instructions applies to BeanShell, Groovy, JRuby, JavaScript, and Jython scripts only. |
The script can call MagicDraw Open API.
More complex model access operations are available in ModelHelper and StereotypesHelper.
Use import statements to shorten java class names as shown in the following figure. |