public interface EvaluationContext extends PropertySet
An instance of EvaluationContext
is always accessible from templates and scripts through the context
variable.
This interface is not intended to be implemented by clients.
Modifier and Type | Method and Description |
---|---|
void |
cancelEvaluation()
Provides an easy way to interrupt the evaluation.
|
GeneratedCode |
createGeneratedCode()
Creates a dynamic generated contents.
|
GeneratedCode |
createGeneratedCode(String templateName,
List<?> arguments)
Evaluates the specified text template and returns the generated contents.
|
Model |
createModel(String metamodelID)
Creates an empty model based on the specified metamodel.
|
Object |
evaluateRule(String ruleSetName,
List<?> ruleSetArguments,
String ruleName,
List<?> ruleArguments)
Evaluates the specified rule and returns the evaluation result.
|
void |
generate(String templateName,
List<?> arguments)
Evaluates the specified text template and write on disk the generated contents.
|
EvaluationConfiguration |
getConfiguration()
Return the configuration that define options of this evaluation.
|
Logger |
getLogger()
Returns the logger used to report errors and warnings, as well as debugging information.
|
ProgressMonitor |
getProgressMonitor()
Returns the progress monitor used to report progress information.
|
Project |
getProject()
Return the project in which the evaluation takes place.
|
TransientLinkManager |
getTransientLinks()
Returns the transient link manager, which provides facilities to dynamically create virtual links between objects of any type.
|
MDWorkbench |
getWorkbench()
Returns the workbench in which the evaluation is performed,
which may be used to access configuration properties.
|
Object |
invoke(EObject object,
String scriptName)
Invokes the specified script.
|
Object |
invoke(EObject object,
String scriptName,
List<?> arguments)
Invokes the specified script.
|
Object |
superInvoke(EObject object,
String scriptName)
Invokes the specified script defined on the super-type.
|
Object |
superInvoke(EObject object,
String scriptName,
List<?> arguments)
Invokes the specified script defined on the super-type.
|
<E> MDWList<E> |
wrap(Collection<E> collection)
Returns an
MDWList that wraps the specified collection. |
getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyNames, loadProperties, saveProperties, setProperties, setProperties, setProperty, setProperty, setProperty, setProperty, setProperty
MDWorkbench getWorkbench()
Logger getLogger()
ProgressMonitor getProgressMonitor()
A script designer may report progress information to the end-user by calling the subTask()
method this way :
context.getProgressMonitor().subTask("Analyzing packages");
context.evaluateRule(...);
context.getProgressMonitor().subTask("Generating some files");
context.generate(...);
null
).void cancelEvaluation() throws OperationCanceledException
OperationCanceledException
,
to abort the evaluation, that is silently handled by the workbench.
This method is designed to respond to an end-user request. For example, if a selection dialog box is opened and the user press the Cancel
button, this method helps to silently terminate the evaluation. But if the evaluation cannot complete correctly because of invalid input or
missing configuration properties, you should rather throw an exception (like EvaluationException
).
OperationCanceledException
- to interrupt the evaluation.GeneratedCode createGeneratedCode()
GeneratedCode createGeneratedCode(String templateName, List<?> arguments)
The template name can be a fully qualified name ("myPackage.myTemplate"
for example), or a simple name if the template is part of
the caller package ("myTemplate"
if called from the package "myPackage"
).
The number and type of arguments must match the parameters of the template. If the template does not declare parameters, the arguments can be
an empty list or null
.
Important note : the text template is evaluated but the generated contents is not written out on disk. While this method may be helpful
in some specific cases, you will generally prefer to use the generate
method.
templateName
- the name of the template.arguments
- the template arguments (can be null
if no arguments expected)EvaluationException
- if anything prevents the template to be evaluated or its generated contents to be persisted.generate(String, List)
void generate(String templateName, List<?> arguments)
The template name can be a fully qualified name ("myPackage.myTemplate"
for example), or a simple name if the template is part of
the caller package ("myTemplate"
if called from the package "myPackage"
).
The number and type of arguments must match the parameters of the template. If the template does not declare parameters, the arguments can be
an empty list or null
.
The template is evaluated and the generated contents is written out, as specified by the file property of the text template. If the template
does not specify a file property, an EvaluationException
if thrown.
templateName
- the name of the template.arguments
- the template arguments (can be null
if no arguments expected)EvaluationException
- if anything prevents the template to be evaluated or its generated contents to be persisted.GeneratedCode.write()
Object evaluateRule(String ruleSetName, List<?> ruleSetArguments, String ruleName, List<?> ruleArguments)
The rule set name can be a fully qualified name ("myPackage.myRuleSet"
for example), or a simple name if the rule set is part of
the caller package ("myRuleSet"
if called from the package "myPackage"
).
The rule name must match a rule declared by the rule set and that is:
private
).
The number and type of arguments must match the parameters of the rule set and of the rules. If the rule set or the rule does not declare
parameters, the arguments can be an empty list or null
.
ruleSetName
- the name of the rule set.ruleSetArguments
- the rule set arguments (can be null
if no arguments expected)ruleName
- the name of the rule.ruleArguments
- the rules arguments (can be null
if no arguments expected)null
)EvaluationException
- if anything prevents the rule to be evaluated.TransientLinkManager getTransientLinks()
Project getProject()
Note : template and script designers should generally not have to consider this advanced facility.
EvaluationConfiguration getConfiguration()
Note : template and script designers should generally not have to consider this configuration, which is directly handled by the workbench.
Model createModel(String metamodelID)
metamodelID
- a metamodel unique identifier.EvaluationException
- if no metamodel matches this ID.Object invoke(EObject object, String scriptName)
The specified name can reference a structural feature (EAttribute
or EReference
) defined in the related metamodel.
object
- the object on which to evaluate a script.scriptName
- the name of the script to evaluate (which must not expect any parameter).null
if the scripts returns nothing.InvalidCallException
- if the script does not exist or is not visible.EvaluationException
- if the evaluation of the script failed.Object invoke(EObject object, String scriptName, List<?> arguments)
The number and type of arguments must match the parameters of the script.
object
- the object on which to evaluate a script.scriptName
- the name of the script to evaluate.arguments
- the script arguments.null
if the scripts returns nothing.InvalidCallException
- if the script does not exist or is not visible.EvaluationException
- if the evaluation of the script failed.Object superInvoke(EObject object, String scriptName)
This is useful when overriding a script: when you redefine a script on a subtype, you're still able to call the super-type script and refine its behavior.
If the related type has many super-types (for example in UML, Classifier
inherits from GeneralizableElement
and from
Namespace
), the specified script may be defined on more than one super-type, and the call can be ambiguous. To resolve this
ambiguity, the expected script can be prefixed by its defining super-type name. For example, from a Classifier
element, you can
call self.superScript("Namespace.myScript")
.
object
- the object on which to evaluate a script.scriptName
- the name of the script to evaluate (which must not expect any parameter).InvalidCallException
- if the script does not exist or is not visible.EvaluationException
- if the evaluation of the script failed.NoSuchTypeException
- if the super-type (if specified) does not existsObject superInvoke(EObject object, String scriptName, List<?> arguments)
This is useful when overriding a script: when you redefine a script on a subtype, you're still able to call the super-type script and refine its behavior.
If the related type has many super-types (for example in UML, Classifier
inherits from GeneralizableElement
and from
Namespace
), the specified script may be defined on more than one super-type, and the call can be ambiguous. To resolve this
ambiguity, the expected script can be prefixed by its defining super-type name. For example, from a Classifier
element, you can
call self.superScript("Namespace.myScript")
.
The number and type of arguments must match the parameters of the script.
object
- the object on which to evaluate a script.scriptName
- the name of the script to evaluate.arguments
- the script arguments.InvalidCallException
- if the script does not exist or is not visible.EvaluationException
- if the evaluation of the script failed.NoSuchTypeException
- if the super-type (if specified) does not exists<E> MDWList<E> wrap(Collection<E> collection)
MDWList
that wraps the specified collection.
This method does not copy the list content but just delegates all method calls to the underlying collection.
If the underlying collection does not implement the List
interface, UnsupportedOperationException
will be thrown for
calls on List
specific methods.E
- the type of elements in the collection.collection
- the collection to be wrapped into a list.