Interface EvaluationContext
-
- All Superinterfaces:
PropertySet
public interface EvaluationContext extends PropertySet
Provides services that helps to build model transformators/generators.An instance of
EvaluationContextis always accessible from templates and scripts through thecontextvariable.This interface is not intended to be implemented by clients.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcancelEvaluation()Provides an easy way to interrupt the evaluation.GeneratedCodecreateGeneratedCode()Creates a dynamic generated contents.GeneratedCodecreateGeneratedCode(String templateName, List<?> arguments)Evaluates the specified text template and returns the generated contents.ModelcreateModel(String metamodelID)Creates an empty model based on the specified metamodel.ObjectevaluateRule(String ruleSetName, List<?> ruleSetArguments, String ruleName, List<?> ruleArguments)Evaluates the specified rule and returns the evaluation result.voidgenerate(String templateName, List<?> arguments)Evaluates the specified text template and write on disk the generated contents.EvaluationConfigurationgetConfiguration()Return the configuration that define options of this evaluation.LoggergetLogger()Returns the logger used to report errors and warnings, as well as debugging information.ProgressMonitorgetProgressMonitor()Returns the progress monitor used to report progress information.ProjectgetProject()Return the project in which the evaluation takes place.TransientLinkManagergetTransientLinks()Returns the transient link manager, which provides facilities to dynamically create virtual links between objects of any type.MDWorkbenchgetWorkbench()Returns the workbench in which the evaluation is performed, which may be used to access configuration properties.Objectinvoke(org.eclipse.emf.ecore.EObject object, String scriptName)Invokes the specified script.Objectinvoke(org.eclipse.emf.ecore.EObject object, String scriptName, List<?> arguments)Invokes the specified script.ObjectsuperInvoke(org.eclipse.emf.ecore.EObject object, String scriptName)Invokes the specified script defined on the super-type.ObjectsuperInvoke(org.eclipse.emf.ecore.EObject object, String scriptName, List<?> arguments)Invokes the specified script defined on the super-type.<E> MDWList<E>wrap(Collection<E> collection)Returns anMDWListthat wraps the specified collection.-
Methods inherited from interface com.sodius.mdw.core.util.PropertySet
getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyNames, loadProperties, saveProperties, setProperties, setProperties, setProperty, setProperty, setProperty, setProperty, setProperty
-
-
-
-
Method Detail
-
getWorkbench
MDWorkbench getWorkbench()
Returns the workbench in which the evaluation is performed, which may be used to access configuration properties. The workbench configuration provides for example access to the command line that launched the workbench, and can determine whether the workbench runs in headless (no user interface) mode.- Returns:
- the workbench.
-
getLogger
Logger getLogger()
Returns the logger used to report errors and warnings, as well as debugging information.- Returns:
- the logger.
-
getProgressMonitor
ProgressMonitor getProgressMonitor()
Returns the progress monitor used to report progress information.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(...);
- Returns:
- the progress monitor used to report progress information (never
null).
-
cancelEvaluation
void cancelEvaluation() throws OperationCanceledExceptionProvides an easy way to interrupt the evaluation. This method throws anOperationCanceledException, 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).- Throws:
OperationCanceledException- to interrupt the evaluation.
-
createGeneratedCode
GeneratedCode createGeneratedCode()
Creates a dynamic generated contents. This method might help to generate a content not contributed through a text template.- Returns:
- an empty generated code instance.
- Since:
- 3.5.1
-
createGeneratedCode
GeneratedCode createGeneratedCode(String templateName, List<?> arguments)
Evaluates the specified text template and returns the generated contents.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
generatemethod.- Parameters:
templateName- the name of the template.arguments- the template arguments (can benullif no arguments expected)- Returns:
- a generated code, which describes the text template output.
- Throws:
EvaluationException- if anything prevents the template to be evaluated or its generated contents to be persisted.- See Also:
generate(String, List)
-
generate
void generate(String templateName, List<?> arguments)
Evaluates the specified text template and write on disk the generated contents.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
EvaluationExceptionif thrown.- Parameters:
templateName- the name of the template.arguments- the template arguments (can benullif no arguments expected)- Throws:
EvaluationException- if anything prevents the template to be evaluated or its generated contents to be persisted.- See Also:
GeneratedCode.write()
-
evaluateRule
Object evaluateRule(String ruleSetName, List<?> ruleSetArguments, String ruleName, List<?> ruleArguments)
Evaluates the specified rule and returns the evaluation result.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:
- a top-level rule : you can't call subrules outside of the declaring rule set.
- visible from the caller (the rule must no be
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.- Parameters:
ruleSetName- the name of the rule set.ruleSetArguments- the rule set arguments (can benullif no arguments expected)ruleName- the name of the rule.ruleArguments- the rules arguments (can benullif no arguments expected)- Returns:
- the rule evaluation result (can be
null) - Throws:
EvaluationException- if anything prevents the rule to be evaluated.
-
getTransientLinks
TransientLinkManager getTransientLinks()
Returns the transient link manager, which provides facilities to dynamically create virtual links between objects of any type. These links do not exist before the evaluation and are automatically garbaged at the end of the evaluation process. They do never alter the models.- Returns:
- the transient link manager.
-
getProject
Project getProject()
Return the project in which the evaluation takes place. The project provides a way to dynamically discover available scripts and templates.Note : template and script designers should generally not have to consider this advanced facility.
- Returns:
- the project in which the evaluation takes place.
-
getConfiguration
EvaluationConfiguration getConfiguration()
Return the configuration that define options of this evaluation.Note : template and script designers should generally not have to consider this configuration, which is directly handled by the workbench.
- Returns:
- the evaluation configuration.
-
createModel
Model createModel(String metamodelID)
Creates an empty model based on the specified metamodel.- Parameters:
metamodelID- a metamodel unique identifier.- Returns:
- an empty model.
- Throws:
EvaluationException- if no metamodel matches this ID.
-
invoke
Object invoke(org.eclipse.emf.ecore.EObject object, String scriptName)
Invokes the specified script.The specified name can reference a structural feature (
EAttributeorEReference) defined in the related metamodel.- Parameters:
object- the object on which to evaluate a script.scriptName- the name of the script to evaluate (which must not expect any parameter).- Returns:
- the script result, or
nullif the scripts returns nothing. - Throws:
InvalidCallException- if the script does not exist or is not visible.EvaluationException- if the evaluation of the script failed.- Since:
- 3.4.0
-
invoke
Object invoke(org.eclipse.emf.ecore.EObject object, String scriptName, List<?> arguments)
Invokes the specified script.The number and type of arguments must match the parameters of the script.
- Parameters:
object- the object on which to evaluate a script.scriptName- the name of the script to evaluate.arguments- the script arguments.- Returns:
- the script result, or
nullif the scripts returns nothing. - Throws:
InvalidCallException- if the script does not exist or is not visible.EvaluationException- if the evaluation of the script failed.- Since:
- 3.4.0
-
superInvoke
Object superInvoke(org.eclipse.emf.ecore.EObject object, String scriptName)
Invokes the specified script defined on the super-type.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,
Classifierinherits fromGeneralizableElementand fromNamespace), 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 aClassifierelement, you can callself.superScript("Namespace.myScript").- Parameters:
object- the object on which to evaluate a script.scriptName- the name of the script to evaluate (which must not expect any parameter).- Returns:
- the script result.
- Throws:
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- Since:
- 3.4.0
-
superInvoke
Object superInvoke(org.eclipse.emf.ecore.EObject object, String scriptName, List<?> arguments)
Invokes the specified script defined on the super-type.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,
Classifierinherits fromGeneralizableElementand fromNamespace), 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 aClassifierelement, you can callself.superScript("Namespace.myScript").The number and type of arguments must match the parameters of the script.
- Parameters:
object- the object on which to evaluate a script.scriptName- the name of the script to evaluate.arguments- the script arguments.- Returns:
- the script result.
- Throws:
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- Since:
- 3.4.0
-
wrap
<E> MDWList<E> wrap(Collection<E> collection)
Returns anMDWListthat 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 theListinterface,UnsupportedOperationExceptionwill be thrown for calls onListspecific methods.- Type Parameters:
E- the type of elements in the collection.- Parameters:
collection- the collection to be wrapped into a list.- Returns:
- a list wrapping the specified collection.
- Since:
- 3.4.0
-
-