ATL - Moodle

Download Report

Transcript ATL - Moodle

6-3b. Atlas
Transformation
Language (ATL)
Tutorial / Exercise
<Presenter>
<Company>, <Country>
<E-mail>
© 2005-2006 The ATHENA Consortium.
Exercise
• Objective
– Hands-on experience with ATL
– Develop a PIM4SOA information to XSD model transformation
• References
– The Atlas Transformation Language Home Page
• http://www.sciences.univ-nantes.fr/lina/atl
– ATL in Eclipse
• http://www.eclipse.org/gmt/atl/
• Technical requirements
– Eclipse 3.2
– EMF 2.2.0
– ATL needs:
• antlr-2.7.5
• mdr-standalone
© 2005-2006 The ATHENA Consortium.
2
Transformation overview
Ecore
conforms to
conforms to
conforms to
PIM4SOA
meta-model
ATL
conforms to
conforms to
modelPIM
© 2005-2006 The ATHENA Consortium.
PIM4SOA-2-XSD
is tranformed into
XSD
meta-model
conforms to
outputXSD
3
PIM4SOA metamodel
© 2005-2006 The ATHENA Consortium.
4
Simple XSD metamodel
© 2005-2006 The ATHENA Consortium.
5
The mapping
mapped to
mapped to
mapped to
mapped to
mapped to
© 2005-2006 The ATHENA Consortium.
6
The input model
© 2005-2006 The ATHENA Consortium.
7
Create an ATL project
© 2005-2006 The ATHENA Consortium.
8
Models and metamodels
© 2005-2006 The ATHENA Consortium.
9
Create an ATL file
© 2005-2006 The ATHENA Consortium.
10
ATL rules and helpers
• Two kind of rules
– Matched rules:
• Declarative transormation
• Specify source and target
• Specify the way to generate target
– Called rules:
• Imperative transformation
• Seen as some kind of helpers
• Helpers
– Viewed as equivalent to Java methods
– Factorized code called from different points in
transformation
© 2005-2006 The ATHENA Consortium.
11
Document2Schema
rule Document2Schema{
from doc : PIM4SOA!Document
to sch : XSD!XSDSchema(
document <- doc.name,
targetNamespace <- 'http://www.w3.org/2001/XMLSchema')
}
© 2005-2006 The ATHENA Consortium.
12
Entity2ComplexType
helper context PIM4SOA!Entity def : getAssociations() :
PIM4SOA!Entity = PIM4SOA!Association.allInstances()
->select(assoc | assoc.container = self);
rule Entity2ComplexType{
from ent : PIM4SOA!Entity
to ct : XSD!XSDComplexType(
name <- ent.name,
xsd_attribute <- Sequence{ent.attribute},
xsd_element <- ent.getAssociations() )
}
© 2005-2006 The ATHENA Consortium.
13
Association2Element and
Attribute2Attribute
rule Association2Element{
from assoc : PIM4SOA!Association
to el : XSD!XSDElement(
name <- assoc.name,
type <-assoc.contained)
}
rule Attribute2Attribute{
from att : PIM4SOA!Attribute
to el : XSD!XSDAttribute(
name <- att.name,
type <- att.type )
}
© 2005-2006 The ATHENA Consortium.
14
ItemType2SimpeType
rule ItemType2SimpleType{
from it : PIM4SOA!ItemType(
-- transform only ItemTypes and not Entities
it.oclIsKindOf(PIM4SOA!Entity)= false
)
to st : XSD!XSDSimpleType(
name <- it.name
)
© 2005-2006 The ATHENA Consortium.
15
Run the file
© 2005-2006 The ATHENA Consortium.
16
The result
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsd="http:///xsd">
<xsd:XSDSchema document="Order" targetNamespace="http://www.w3.org/2001/XMLSchema"/>
<xsd:XSDSimpleType name="String"/>
<xsd:XSDSimpleType name="Integer"/>
<xsd:XSDComplexType name="productRecord">
<xsd_attribute name="supplierProductCode" type="/1"/>
<xsd_attribute name="buyerProductCode" type="/1"/>
<xsd_attribute name="quantity" type="/2"/>
<xsd_attribute name="description" type="/1"/>
<xsd_attribute name="model" type="/1"/>
<xsd_attribute name="productPrice" type="/1"/>
<xsd_attribute name="comments" type="/1"/>
</xsd:XSDComplexType>
<xsd:XSDComplexType name="orderHeader">
<xsd_attribute name="id" type="/2"/>
<xsd_attribute name="issuedDate" type="/1"/>
</xsd:XSDComplexType>
<xsd:XSDComplexType name="productsInfo">
<xsd_element name="productRecords" type="/3"/>
<xsd_attribute name="productName" type="/1"/>
<xsd_attribute name="productCode" type="/1"/>
</xsd:XSDComplexType>
</xmi:XMI>
© 2005-2006 The ATHENA Consortium.
17
This course has been developed under the funding of the EC with the support of the EC ATHENA-IP Project.
Disclaimer and Copyright Notice: Permission is granted without fee for personal or educational (non-profit) use, previous notification
is needed. For notification purposes, please, address to the ATHENA Training Programme Chair at [email protected]. In other cases please,
contact at the same e-mail address for use conditions. Some of the figures presented in this course are freely inspired by others reported
in referenced works/sources. For such figures copyright and all rights therein are maintained by the original authors or by other copyright
holders. It is understood that all persons copying these figures will adhere to the terms and constraints invoked by each copyright holder.
© 2005-2006 The ATHENA Consortium.
18