Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "ATL/Howtos"

< ATL
(added howto launch programmatically)
(creation of this HowTo)
Line 39: Line 39:
  
 
Remark: the [http://dev.eclipse.org/viewcvs/indextech.cgi/org.eclipse.gmt/ATL/org.atl.eclipse.engine/src/org/atl/eclipse/engine/AtlCompiler.java?rev=HEAD&content-type=text/vnd.viewcvs-markup AtlCompiler] class may be used to compile ATL transformations into .asm files executable on the ATL Virtual Machine.
 
Remark: the [http://dev.eclipse.org/viewcvs/indextech.cgi/org.eclipse.gmt/ATL/org.atl.eclipse.engine/src/org/atl/eclipse/engine/AtlCompiler.java?rev=HEAD&content-type=text/vnd.viewcvs-markup AtlCompiler] class may be used to compile ATL transformations into .asm files executable on the ATL Virtual Machine.
 +
 +
==How do I use extern parameters in ATL transformations?==
 +
 +
===Using an XML file===
 +
A solution is to save transformation parameters in a extern XML model. In the transformation, you will use an ''helper'' to get parameters from your model. The wanted parameters model will be chosen in the transformation launch configuration or in the [[AM3 Ant Tasks]].
 +
 +
The following code is a simple parameters XML file:
 +
<pre>
 +
<parameters>
 +
<param name="source" value="KM3"/>
 +
<param name="target" value="ATL"/>
 +
</parameters>
 +
</pre>
 +
 +
In the transformation header, you add the ''parameters'' model and its metamodel
 +
[http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/org.eclipse.gmt/AM3/org.eclipse.am3.zoos.atlantic/XML.km3?rev=1.1&only_with_tag=HEAD&content-type=text/vnd.viewcvs-markup XML.km3] :
 +
<pre>
 +
module AMW2ATL;
 +
create OUT : ATL from source : MOF, target : MOF, parameters : XML;
 +
</pre>
 +
 +
From ''parameters'' model, the following helper is used to get ''value'' attribute select in the ''param'' entities according to the given ''name'':
 +
<pre>
 +
helper def : getParameter(name : String) : String =
 +
XML!Element.allInstancesFrom('parameters')->select(e |
 +
e.name = 'param'
 +
)->select(e |
 +
e.getAttrVal('name') = name
 +
)->first().getAttrVal('value');
 +
</pre>
 +
 +
To used the previous helper (due to the ''getAttrVal'' call), you need to used [http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/org.eclipse.gmt/AM3/org.eclipse.am3.zoos.atlanticRaster/build/XMLHelpers.asm?rev=1.1&content-type=text/vnd.viewcvs-markup XMLHelpers.asm] ATL Library and add in the transformation:
 +
<pre>
 +
uses XMLHelpers;
 +
</pre>
 +
 +
The following code, it is a simple example to show how to used ''getParameter'' helper:
 +
<pre>
 +
helper def : sourceValue  : String = thisModule.getParameter('source');
 +
</pre>
 +
 +
In [[AM3 Ant Tasks]], you need to add the ''parameters'' model, the [http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/org.eclipse.gmt/AM3/org.eclipse.am3.zoos.atlantic/XML.km3?rev=1.1&only_with_tag=HEAD&content-type=text/vnd.viewcvs-markup XML.km3] metamodel and the [http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/org.eclipse.gmt/AM3/org.eclipse.am3.zoos.atlanticRaster/build/XMLHelpers.asm?rev=1.1&content-type=text/vnd.viewcvs-markup XMLHelpers.asm] library.
 +
See the following example:
 +
<pre>
 +
<am3.loadModel modelHandler="EMF" name="Parameters" metamodel="XML" path="Parameters.xml">
 +
<injector name="xml"/>
 +
</am3.loadModel>
 +
 +
<am3.atl path="myTransformation.atl">
 +
<inModel name="source" model="left"/>
 +
<inModel name="target" model="right"/>
 +
<inModel name="MOF" model="%EMF"/>
 +
 +
<inModel name="parameters" model="Parameters"/>
 +
<inModel name="XML" model="XML"/>
 +
<library name="XMLHelpers" path="XMLHelpers.asm"/>
 +
 +
<inModel name="ATL" model="ATL"/>
 +
<outModel name="OUT" model="ATLmodel" metamodel="ATL"/>
 +
</am3.atl>
 +
 +
<am3.saveModel model="ATLmodel" path="ATLmodel.ecore"/>
 +
</pre>

Revision as of 07:56, 26 July 2006

This page contains a list of problems related to ATL usage. It gives hints towards solutions and links to examples.

How do I generate text from models?

There are several possibilies. We only detail some of them here.

Using ATL

You can specify a query over your model in ATL. An example of this is available in the UML2Java transformation.

The atlanticRaster zoo is also using this technique. It first transforms KM3 metamodels into DOT models with the KM32DOT.atl transformation. It then uses DOT2Text.atl to query a String from the DOT model. This string corresponds to the generated DOT code. Then, the build.xml ant scripts makes use of the am3.saveModel task with an ATL extractor pointing to the DOT2Text.atl transformation.

Using TCS

TCS (Textual Concrete Syntax) is a tool enabling the specification of textual syntaxes for metamodels. Once such a syntax has been specified, models can be serialized to text files.

One advantage of TCS is that text can also be parsed into models. It is therefore possible to use the same specification to enable the definition of models with any text editor.

How do I launch transformations programmatically?

The ATL development environment (ATL Development Tools, or ADT) provides several means to launch transformations:

  • by specifying a launch configuration,
  • by writing an ant script using the AM3 Ant Tasks.

However, in some cases, it is necessary to launch an ATL transformation from Java code. The AtlLauncher class can be used for this purpose. The KM3Projector class of the KM3 plugin contains example usages of the AtlLauncher class (e.g. the getEcoreFromKM3 method).

Remark: the AtlCompiler class may be used to compile ATL transformations into .asm files executable on the ATL Virtual Machine.

How do I use extern parameters in ATL transformations?

Using an XML file

A solution is to save transformation parameters in a extern XML model. In the transformation, you will use an helper to get parameters from your model. The wanted parameters model will be chosen in the transformation launch configuration or in the AM3 Ant Tasks.

The following code is a simple parameters XML file:

<parameters>
	<param name="source" value="KM3"/>
	<param name="target" value="ATL"/>
</parameters>

In the transformation header, you add the parameters model and its metamodel XML.km3 :

module AMW2ATL;
create OUT : ATL from source : MOF, target : MOF, parameters : XML;

From parameters model, the following helper is used to get value attribute select in the param entities according to the given name:

helper def : getParameter(name : String) : String =
	XML!Element.allInstancesFrom('parameters')->select(e |
		e.name = 'param'
	)->select(e |
		e.getAttrVal('name') = name
	)->first().getAttrVal('value');

To used the previous helper (due to the getAttrVal call), you need to used XMLHelpers.asm ATL Library and add in the transformation:

uses XMLHelpers;

The following code, it is a simple example to show how to used getParameter helper:

helper def : sourceValue  : String = thisModule.getParameter('source');

In AM3 Ant Tasks, you need to add the parameters model, the XML.km3 metamodel and the XMLHelpers.asm library. See the following example:

<am3.loadModel modelHandler="EMF" name="Parameters" metamodel="XML" path="Parameters.xml">
	<injector name="xml"/>
</am3.loadModel>

<am3.atl path="myTransformation.atl">
	<inModel name="source" model="left"/>
	<inModel name="target" model="right"/>
	<inModel name="MOF" model="%EMF"/>

	<inModel name="parameters" model="Parameters"/>
	<inModel name="XML" model="XML"/>
	<library name="XMLHelpers" path="XMLHelpers.asm"/>

	<inModel name="ATL" model="ATL"/>
	<outModel name="OUT" model="ATLmodel" metamodel="ATL"/>
</am3.atl>

<am3.saveModel model="ATLmodel" path="ATLmodel.ecore"/>	

Back to the top