Scripts are called using APIs defined on the interface
com.sodius.mdw.core.model.MDWObject
, root of metatypes:
toObject(String)
:
invokes the specified script (which expects no argument) or metamodel feature.toObject(String, List)
:
invokes the specified script with some arguments.Additional script call methods are provided to convert the evaluation result to a specific type.
Here are the most commonly used:
toString
:
invokes the specified script and returns a String
representation of the evaluation result.
toList
:
invokes the specified script and returns a MDWList
representation of the evaluation result.
toBoolean
:
invokes the specified script and returns a boolean
representation of the evaluation result.
When the script defines parameters, you have to give arguments using
a java.util.List
.
The class ScriptContainer
,
root of Java classes where scripts are defined, provides some facilities to build an argument list:
asList(Object)
:
creates a new list with the specified argument.asList(Object, Object)
:
creates a new list with the specified arguments....
asList(Object, Object, Object, Object, Object, Object)
:
creates a new list with the specified arguments.
package com.mycompany.example; import com.sodius.mdw.core.model.MDWList; import com.sodius.mdw.metamodel.uml21.scripts.ClassScriptContainer; public class uml21_Class extends ClassScriptContainer { public String qualifiedName() { // Calls 'qualifiedName' defined on the namespace return self.getNamespace().toString("qualifiedName") + "." + self.getName(); } public MDWList callWithArgs(Object value) { // Uses asList() to provide script arguments return self.toList("myScript", asList("Hello", Boolean.TRUE, value)); } }