Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
AMW/Model Handler
< To: AMMA
< To: GMT
< To: AMW
The AMW Model Handler enables a better integration of ATL transformations and weaving models. It provides a set of primitives constantly needed when developing transformations that have weaving models as input or output.
In the ATL terminology, a model handler is a library providing primitives for handling models, such creating new models, or adding and deleting elements.
This model handler is an extension to the ATL library of operations. It contributes to the extension point org.eclipse.m2m.atl.engine.emfvm.libextension.
The class org.eclipse.gmt.weaver.transformation.operations.UtilOperation implements a set of helper methods that can be called when developing ATL transformations that have weaving models as input or as output. The methods can be used for weaving models and for woven models as well. The UtilOperation class is being improved with new primitives.
Contents
Helper methods methods
The AMW UtilOperation class provides methods that can be called on elements of a weaving model or on the elements of the woven models. They are explained below.
Weaving models
getReferredElement
This method takes as input a WLinkEnd of a weaving model and it returns the referred element of a woven model (e.g., a MOF!EClassifier).
Example:
rule Example { from mmw : AMW!ElementEqual ( not mmw.left.getReferredElement().oclIsUndefined() ) to ...
Woven models
generateModelRef
This methods generates the value of the "ref" attribute for a woven model. In other words, it generates an identifier for woven models. The current implementation returns the models' URI.
Example:
create OUT : AMW from left : MOF, right : MOF; ... rule Example { from ... to lefta : AMW!ModelRefXMI ( name <- 'leftModel', ref <- MOF!EPackage.generateModelRef('left') ) }
getElementID
This method returns the identifier (ID) of a woven element. It is necessary to pass as parameter the related weaving model. In that way it is possible to find which WElementRef is used, and which adapter class is called. The adapter class is the implementation of the identification mechanisms. Ex.: the providers sources contains implementations of these adapters, such as the XMIIdentifierAdapter and the GenericIdentifierAdapter].
Example:
create OUT : AMW from IN : AMW, left : MOF, right : MOF; ... rule example { from element : MOF!EClass to out : AMW!ElementRef ( name <- element.name, ref <- element.getElementID('IN') ) }
getElementIDbyRefType
This method returns the identifier (ID) of a woven element. In this method it is necessary to pass the type of element ref (that inherits from WElementRef) as parameter. The type of WElementRef specifies which identification mechanism is used. The WElementRefs are associated with adapters of identification mechanisms (see below). For instance, the ElementRefXMI is associated with the XMIIdentifierAdapter class. It returns the XMI ID.
This method is used when the user wants to create a new weaving model and he does not have yet the information concerning its identification mechanism.
rule NewElementRef { from element : MOF!EClassifier to out : AMW!ElementRefXMI ( name <- element.name, ref <- element.getElementIDbyRefType('ElementRefXMI'), modelRef <- element.setModelRef ) }
setElementIDbyRefType
This method sets up the identifier (ID) of a model element. In this method it is necessary to pass the type of element ref (that inherits from WElementRef) as parameter. The type of WElementRef specifies which identification mechanism is used. The WElementRefs are associated with adapters of identification mechanisms (see below). For instance, the ElementRefXMI is associated with the XMIIdentifierAdapter class. It sets up the XMI ID.
The value of the new ID is passed as second parameter. It must be a string object, because it is the same value that should be saved in the ref attribute of the WElementRefs. If the second parameters is null (OclIsUndefined), the ID will be set up based on the value of the object.
This method is used when the user wants to set up the ID of an element and he does not have yet the information concerning its identification mechanism.
rule NewElement { from element : MOF!EClassifier to out : MOF!EClassifier ( ) do { out.setElementIDbyRefType('ElementRefXMI', 'newIDValue'), } }
Creating an ATL launch configuration
The screenshot below shows how to set up an ATL launch configuration with the AMW model handler. The AMW handler will be available in the list of model handlers .
First the user sets up the input and output models . Then the user must select the weaving metamodel (e.g., mmw_weaving.core) or the woven metamodels (e.g., MOF), or both as shown below. Then select 'AMW', and click on the Select Model Handler button. AMW is shown in the third column of the Path Editor.
The transformation is ready to run.
Download and install
The UtilOperation class is implemented in the org.eclipse.gmt.weaver.transformation plug-in. So, this plug-in must be installed. To add user-defined methods, it is necessary to contribute to the org.eclipse.m2m.atl.engine.emfvm.libextension extension point. Below there is an example of how to declare it.
<extension point="org.eclipse.m2m.atl.engine.emfvm.libextension"> <libextension class="org.eclipse.gmt.weaver.transformation.operations.UtilOperation" name="UtilOperation"> </libextension> </extension>
Check the class org.eclipse.gmt.weaver.transformation.operations.UtilOperation to understand how to create new helper methods.