Jump to: navigation, search

Difference between revisions of "AMW/Model Handler"

< AMW
(Model Handler methods)
(getElementID)
 
(10 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
[[Image:AmwLogo.png|right]]
 
[[Image:AmwLogo.png|right]]
  
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.
+
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. See the [[ATL Model Handlers]] page to know the base model handlers provided by the ATL plug-ins.
+
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 inherits from the ATL EMF ModelHandler, thus it supports all the base EMF primitives. It can be used for weaving models and for woven models as well. The model handler is being improved with new primitives, according to new user requirements. It will be separated in two different model handlers (one for the woven and one for the weaving models) in future versions.
+
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''.
  
==Model Handler methods==
+
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.
  
The AMW model handler provides methods that can be called on elements of a weaving model or on the elements of the woven models. They are explained below.
+
==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===
 
===Weaving models===
Line 51: Line 53:
 
====getElementID====
 
====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.: [http://dev.eclipse.org/viewcvs/indextech.cgi/org.eclipse.gmt/AMW/org.eclipse.weaver/src/org/eclipse/weaver/providers/XMIIdentifierAdapter.java?view=markup XMIIdentifierAdapter], [http://dev.eclipse.org/viewcvs/indextech.cgi/org.eclipse.gmt/AMW/org.eclipse.weaver/src/org/eclipse/weaver/providers/GenericIdentifierAdapter.java?revision=1.2&view=markup GenericIdentifierAdapter].
+
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 [http://dev.eclipse.org/viewsvn/viewvc.cgi/plugins/trunk/org.eclipse.gmt.weaver/src/org/eclipse/gmt/weaver/providers/?diff_format=s&root=Modeling_AMW&pathrev=4 providers sources] contains implementations of these adapters, such as the ''XMIIdentifierAdapter'' and the ''GenericIdentifierAdapter''].
  
 
Example:
 
Example:
Line 65: Line 67:
 
             ref <- '''element.getElementID('IN')'''
 
             ref <- '''element.getElementID('IN')'''
 
         )
 
         )
   }
+
   }
  
 
====getElementIDbyRefType====
 
====getElementIDbyRefType====
Line 82: Line 84:
 
             modelRef <- element.setModelRef
 
             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')''',
 +
      }
 
   }
 
   }
  
Line 94: Line 116:
 
[[Image:sample_model_handler.png|center]]
 
[[Image:sample_model_handler.png|center]]
  
==Download and install==
 
  
The Amw Model Handler plug-in ('''org.eclipse.gmt.weaver.amw4atl''') is available for download in the [http://dev.eclipse.org/viewcvs/indextech.cgi/org.eclipse.gmt/AMW/ AMW CVS].
+
==Download and install==
  
The plug-in must be checked out in the Eclipse workspace and a new Runtime Workspace must be launched. Then, the model handler is ready to use.
+
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.
  
A binary release will be available in the next complete release of the AMW plug-ins.
+
    <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
 +
[http://dev.eclipse.org/viewsvn/viewvc.cgi/plugins/trunk/org.eclipse.gmt.weaver.transformation/src/org/eclipse/gmt/weaver/transformation/operations/UtilOperation.java?view=markup&revision=22&root=Modeling_AMW&pathrev=22 org.eclipse.gmt.weaver.transformation.operations.UtilOperation] to understand how to create new helper methods.
  
 
[[Category:Modeling]]
 
[[Category:Modeling]]
Line 107: Line 136:
 
[[Category:GMT]]
 
[[Category:GMT]]
 
[[Category:AMMA]]
 
[[Category:AMMA]]
 +
[[Category:AMW]]

Latest revision as of 11:33, 17 December 2010

< To: AMMA
< To: GMT
< To: AMW

AmwLogo.png

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.

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.

Sample model handler.png


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.