ATL: ATLAS Transformation
Language
Rubby Casallas
Grupo de Construccin de Software
Uniandes
Models are first class
entities
Transformations are
models
Transformations are
assets
2
What is ATL?
ATL is a model transformation language
(MTL) developed at INRIA to answer the QVT
Request For Proposal.
It is specified both as a metamodel and as a
textual concrete syntax.
It is a hybrid of declarative and imperative.
What is ATL?
In declarative style:
simple mappings can be expressed simply.
Imperative constructs:
are provided to express more complex mappings
What is ATL?
An ATL transformation program is composed
of rules that define:
how source model elements are matched and
navigated
how to create and initialize the elements of the
target models.
ATL and Ecore
ATL Transformation rules
Input MM
Input M
Output M
ATL Engine
XMI
Output MM
XMI
Example
module UML2JAVA;
create OUT : JAVA from IN : UML ;
module UML2Java
.atl
XMI
XMI
UML MM
UML M
ATL Engine
M Java
JAVA MM
Structure of an ATL transformation
An ATL module corresponds to a model to model
transformation.
Elements:
A header section:
defines attributes that are relative to the transformation
module;
An optional import section:
A set of helpers:
A set of rules:
enables to import some existing ATL libraries
can be viewed as an ATL equivalent to Java methods
defines the way target models are generated from source
ones.
ATL modules
They are the files that contain the
transformations
.atl extension
Consist of:
Header (mandatory)
Import
Helpers
Rules
10
Import
This section is optional
Defines the ATL libraries to be imported
Example:
uses strings;
11
Header
The target models declaration is introduced by the create
keyword
the source models are introduced either by the keyword from (in
normal mode) or refines (in case of refining transformation)
module module_name;
create output_models
[from|refines] input_models;
module Book2Publication; ;
create OUT : Publication
from IN: Book;
output Metamodel
input Metamodel
12
Helpers
They are variables or functions used to implement
code that can be reused
helper def: objectIdType : Relational!Type =
Class!DataType.allInstances()->
select(e | e.name = 'Integer')->first();
Using a variable:
type <- thisModule.objectIdType;
13
Helpers
Using a function:
helper context Book!Book def : getAuthors() : String =
self.chapters->collect(e | e.author)
->asSet()->
iterate(authorName; acc : String = '' |
acc +
if acc = ''
then authorName
else ' and ' + authorName
endif);
Calling the function:
b.getAuthors()
14
Transformation Rules
three different kinds of rules:
matched rules (declarative programming)
called rules (imperative programming).
Lazy rules (?)
15
Matched Rules
rule DataType2Type {
from
dt : Class!DataType
to
out : Relational!Type (
name <- dt.name
)
}
16
Matched Rules
Input Metamodel
rule DataType2Type {
from
dt : Class!DataType
to
out : Relational!Type (
name <- dt.name
)
}
Output Metamodel
17
Matched Rules
We need:
To access any element of the input model
To create elements of the output model from
information of the elements of the input model
The access to the elements is done using
The OCL: Object Constraint language
18
Matched Rules: Input
The input pattern consists of:
the keyword from,
the declaration of an input variable
an OCL expression that returns the input element
to be transformed
from
dt :
Class!DataType
19
Matched Rules: Input (cont.)
A filter is an OCL expression that restraints
the elements of the input model to those that
satisfy a set of constraints
Example:
Refer to the instances of the Parameter element
in the UML Metamodel, where its kind is
different from the value #pdk_eturn:
e : UML!Parameter (e.kind <> #pdk_return)
20
10
Matched Rules: Output
The output pattern declares:
on which output elements of the output model, the
input elements matching the input pattern will be
transformed
The implementation of the output pattern
declares the details of the transformation
It is possible to have more than one element in
the output pattern
21
Matched Rules: Output (cont.)
Declares a variable and a sequence of
assignment statements.
to
out : Relational!Type (
name <- dt.name
)
Building and instance of the element Type of the output model
The name attribute of the new element will have as value the
value of the name attribute of the element referenced by the variable dt
22
11
Called Rules
They are a particular type of helpers
They have to be explicitly called to be
executed
They can accept parameters.
They can generate target model elements as
matched rules do.
A called rule has to be called from an
imperative code section, either from a match
rule or another called rule.
23
Called Rules
rule NewPerson (na: String, s_na: String) {
to
p : MMPerson!Person (
name <- na
)
do {
p.surname <- s_na
}
}
Generates Person target model elements.
Accepts two parameters that correspond to the name and the
surname of the Person
The target pattern allocates a Person class each time the rule is
called, and initializes the name attribute of the allocated model
element.
The imperative code section is executed after the initialization of the
allocated element
24
12
Tranformation examples
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
ATL to Problem
Ant to Maven
BibTeXML to DocBook
Book to Publication
Class to Relational
Geometrical transformations
Grafcet to PetriNet
Java to Table
KM3 to DOT
KM3 to Metrics
KM3 to Problem
Make to Ant
Maven to Ant
Microsoft Office Excel Extractor
Microsoft Office Excel Injector
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
Microsoft Office Excel to
Software
Quality Control
Monitor to Semaphore
PathExp to PetriNet
Software Quality Control to
Bugzilla
Software Quality Control to
Mantis Bug Tracker
Table to Microsoft Office Excel
UML to Amble
UML to Java
UML to MOF
UML Activity Diagram to
MSProject
UMLDI to SVG
XSLT to XQuery
25
UML2Java
26
13
UML MM expressed using MOF XMI
<Model:Class xmi.id = 'a9' name = 'JavaElement' annotation = ''
isRoot = 'false'
isLeaf = 'false' isAbstract = 'true' visibility = 'public_vis'
isSingleton = 'false'>
<Model:Namespace.contents>
<Model:Attribute xmi.id = 'a10' name = 'name' annotation = ''
scope = 'instance_level'
visibility = 'public_vis' isChangeable = 'true'
isDerived = 'false'>
<Model:StructuralFeature.multiplicity>
<XMI.field>1</XMI.field>
<XMI.field>1</XMI.field>
<XMI.field>true</XMI.field>
<XMI.field>true</XMI.field>
</Model:StructuralFeature.multiplicity>
<Model:TypedElement.type>
<Model:PrimitiveType xmi.idref = 'a6'/>
</Model:TypedElement.type>
</Model:Attribute>
</Model:Namespace.contents>
</Model:Class>
27
28
14
UML model in XMI
<UML:Package xmi.id = 'sm$8809ce:fb81b88162:-7fe2'
name = 'view' visibility = 'public'
isSpecification = 'false' isRoot = 'false'
isLeaf = 'false' isAbstract = 'false'>
<UML:Namespace.ownedElement>
<UML:Class xmi.id = 'sm$ec9b3a:fb81dfe2ed:-7ff7'
name = 'BoundedIntegerView'
visibility = 'public' isSpecification = 'false'
isRoot = 'false' isLeaf = 'false'
isAbstract = 'false' isActive = 'false'>
<UML:Classifier.feature>
<UML:Attribute xmi.id = 'sm$ec9b3a:fb81dfe2ed:-7fca'
name = 'value' visibility = 'public'
isSpecification = 'false'
ownerScope = 'instance'
changeability = 'changeable'>
29
UML2Java: Transformation rules
For each Package element of UML MM
create an element Package of Java MM
1.
The names have to be the same in the java
case the name have be extended
rule P2P {
from e: UML!PAckage (e.oclIsTypeOf (UML!Package))
to out : JAVA!Package (
name <- e.getExtendedName()
)
}
30
15
UML2Java: Transformation rules
2. For each Operation element of UML MM
create an Method element of Java MM
names, types, modifiers have to be the same
31
UML2Java: Transformation rules
rule O2M {
from e : UML!Operation
to out : JAVA!Method (
name <- e.name,
isStatic <- e.isStatic(),
isPublic <- e.isPublic(),
owner <- e.owner,
type <e.parameter->
select(x|x.kind= #pdk_return)->asSequence()->first().type,
parameters <e.parameter->select(x|x.kind<>
#pdk_return)->asSequence()
)
}
32
16
Transformation Engine
Implemented in Java
Can use EMF or MDR as model repository
Input/output models and metamodelos are
managed by the underlying model repository
ATL has a proprietary repository to load the
model transformations.
33
ATL Eclipse Plug-in
There is a complete ATL perspective in
Eclipse
Also a perspective to Debug ATL
transformations
There are:
an ATL editor
an Ouline view to review the current elements
34
17
ATL Eclipse Plug-in
35
Referencias
http://dev.eclipse.org/viewcvs/indextech.cgi/~
checkout~/gmthome/subprojects/ATL/index.html
http://www.sciences.univnantes.fr/lina/atl/atlProject
36
18