Presentation is loading. Please wait.

Presentation is loading. Please wait.

ATL The ATLAS Transformation Language. 2 ATL (ATLAS Transformation Language) ATL transformation pattern ATL metamodel Helpers – Operation helpers – Attribute.

Similar presentations


Presentation on theme: "ATL The ATLAS Transformation Language. 2 ATL (ATLAS Transformation Language) ATL transformation pattern ATL metamodel Helpers – Operation helpers – Attribute."— Presentation transcript:

1 ATL The ATLAS Transformation Language

2 2 ATL (ATLAS Transformation Language) ATL transformation pattern ATL metamodel Helpers – Operation helpers – Attribute helpers Transformation rules – Matched rules (Declarative rules) – Imperative features ATL tools – Execution engine – IDE

3 3 Model transformation By definition, a model transformation is the automatic creation of target models from source models. Model transformation is not only about M1 to M1 transformations: – M1 to M2: promotion, – M2 to M1: demotion, – M3 to M1, M3 to M2, etc.

4 4 ATL transformation pattern MOF MMa MMb Ma Mb MMa2MMb.atl ATL MMa is the source metamodel Ma is the source model Mb is the target model MMB is the target metamodel

5 5 ATL overview Unidirectional transformation Source models and target models are distinct. Source models cannot be modified, only navigated. Target models cannot be navigated. The language is a declarative-imperative hybrid: – There are imperative or called rules. – There are declarative or matched rules. An imperative/called rule is basically a procedure. A declarative/matched rule specifies: – a source pattern to be matched in the source models, – a target pattern to be created in the target model for each match.

6 6 ATL metamodel

7 7 ATL helpers The term helper comes from the OCL specification Can only be specified on an OCL type or a source type (coming from a source metamodel) Are specified in OCL Have a name, a context and a type Can be recursively defined

8 8 ATL helpers Operation helpers – Purpose : to perform navigation over source models – Can be used to specify operations in the context of a model element or a module – Can have input parameters Attribute helpers – Can be considered as a means to decorate source models before transformation execution – Are used to associate read-only named values to source model elements. – Cannot have input parameters, their values are specified by an OCL expression. – Can be associated to a transformation and are not always attached to a metamodel – Can be initialized in a pass performed before running the rest of the transformation but can also be lazily evaluated when the helper value is read for the first time x

9 9 ATL operation helper - example helper context XML!Element def: getChildren(type : OclType, name : String) : Sequence(XML!Node) = self.children->select(e | e.oclIsKindOf(type) )->select(e | e.name = name ); A simple XML metamodel type can be: XML!Element XML!Attribute XML!Text Calling this operation with getChildren(XML!Element,’interface’) gives a sequence containing interface elements

10 10 ATL attribute helper - example helper context SimpleClass!Class def : allAttributes : Sequence(SimpleClass!Attribute) = self.attrs->union( if not self.parent.oclIsUndefined() then self.parent.allAttributes->select(attr | not self.attrs->exists(at | at.name = attr.name) ) else Sequence {} endif )->flatten(); SimpleClass metamodel allAttributes is recursively called

11 11 Matched rules (declarative rules) Source pattern The source pattern is composed of: – Source types coming from the source metamodels, – A guard (Boolean expression in OCL) used to filter matches. A source pattern is evaluated to a set of matches in source models A match corresponds to a set of elements coming from the source models that: – Are of the types specified in the source pattern (one element for each type), – Verify the guard.

12 12 Matched rules Target pattern The target pattern is composed of: – A set of target types coming from the target metamodels – For each element of this set, a set of bindings (identified by the symbol <-). – A binding specifies the initialization of a feature of a target element using an expression whose value is used to initialize the feature. For each match, the target pattern is applied: – Elements are created in the target models (one for each type of the target pattern), – Target elements are initialized by executing the bindings: First evaluating their value, Then assigning this value to the corresponding property.

13 13 Types of matched rules There exist three types of matched rules : – Standard rules are applied once for every match that can be found in source models – Lazy rules are triggered by other rules. They are applied on a match as many times as it is referred to by other rules. A lazy rule may be applied multiple times on a single match, each time producing a new set of target elements – Unique lazy rules are also triggered by other rules. They are applied only once for a given match. If a unique lazy rule is triggered later on the same match the already created target elements are used

14 14 Matched standard rules - example rule PersistentClass2Table{ from c : SimpleClass!Class ( c.is_persistent and c.parent.oclIsUndefined() ) to t : SimpleRDBMS!Table ( name <- c.name ) } Source pattern Target pattern

15 15 Matched lazy rules - example lazy rule R1 { from s : Element to t : Element ( value <- [R2.t]s ) }

16 16 Matched uniquely lazy rules - example unique lazy rule Feature2Column { from trace : Sequence(OclAny) to col : SimpleRDBMS!Column ( name iterate(e; acc : String = '' | acc + if acc = '' then '' else '_' endif + f.name), type last().type ) }

17 17 Execution order The order in which rules are matched and applied is not specified The order in which bindings are applied is not specified The execution of declarative rules can however be kept deterministic: – The execution of a rule cannot change source models: it cannot change the set of matches – Target elements are not navigable: the execution of a binding cannot change the value of another

18 18 Execution order Lazy rules may lead to executions that do not terminate – Transformations run in a cycle – Recursive references are present lazy rule R1 { from s : Element to t : Element ( value <- [R2.t]s ) } lazy rule R2 { from s : Element to t : Element ( value <- [R1.t]s ) }

19 19 Called rules (imperative rules) Are basically a procedure Are invoked by its name and may take arguments. Its implementation can be native or specified in ATL (e.g. as a target pattern without source pattern since no match is needed). Can lead to executions that do not terminate due to their imperative nature Called rules and action block helper def: id : Integer = 0; rule getId() { -- : Integer do { thisModule.id <- thisModule.id + 1; -- increment id thisModule.id; -- returns id } Hybrid rules (matched rule with action block) rule Test { from s : S!Test to t : T!Test do { t.id <- thisModule.getId(); }

20 20 ATL classification

21 21 ATL summary

22 22 Implementation of ATL The ATL execution engine is based on a Virtual Machine (VM). The VM executes bytecode. There is a compiler from ATL code to bytecode. The Virtual Machine can handle models that are: – Stored in Eclipse EMF, – Or stored in Netbeans MDR.

23 23 ATL engine algorithm - executing rules -- START OF ALGORITHM: execute called rule marked as entrypoint -- This results in a traditional imperative control flow. -- Match standard matched rules: ForEach standard rule R { ForEach candidate pattern C of R { -- a candidate pattern is a set of elements matching the -- types of the source pattern of a rule evaluate the guard of R on C If guard is true Then create target elements in target pattern of R create TraceLink for R, C, and target elements Else discard C EndIf } -- Apply standard matched rules: ForEach TraceLink T { R = the rule associated to T C = the matched source pattern of T P = the created target pattern of T -- Initialize elements in the target pattern: ForEach target element E of P { -- Initialize each feature of E: ForEach binding B declared for E { expression = initialization expression of B value = evaluate expression in the context of C featureValue = resolve value set featureValue to corresponding feature of B } execute action block of R in the context of C and T -- imperative blocks can perform any navigation in C or T and -- any action on T -- it is the programmer's responsibility to perform valid -- operations } execute called rule marked as endpoint -- We have again an imperative control flow. -- END OF ALGORITHM This algorithm does not suppose an order in  Rule matching  Creation of target elements for a match  Initialization of target elements for a TraceLink  Initialization of target element’s features. Action block (if present) must, however, be executed after having applied the declarative part of the rule. The imperative parts of the algorithm are not completely supported yet.

24 24 The ATL Virtual Machine Architecture ATL Virtual Machine EMF (Eclipse Modeling Framework) MDR (Netbeans MetaData Repository) Etc. ATL Compiler ATL programs

25 25 ATL Development Tools: perspective, editor and outline

26 26 ATL Development Tools: launch configuration

27 27 ATL Development Tools: source-level debugger

28 Book to Publication transformation

29 29 Book to Publication transformation Metamodel Book – Contains an ordered set of Chapters. – Chapters hold the information of the number of pages of Chapters, the authors. The metamodel Publication – Contains a class Publication with a title and the total number of pages. Transformation requirements – All chapters of a Book have to be visited to calculate the sum of all pages authors of all chapters

30 30 Book to Publication transformation CD of a Book metamodelCD of a Publication metamodel CD = Class Diagram +title : String +nbPages : Integer +author : String Chapter +title : String Book *+chapters {ordered} +book +title : String +nbPages : Integer +author : String Publication

31 31 A Book metamodel in KM3 package Book { class Book { attribute title : String; reference chapters[*] ordered container : Chapter oppositeOf book } class Chapter { attribute title : String; attribute nbPages : Integer; attribute author : String; reference book : Book oppositeOf chapters; } package PrimitiveTypes { datatype Integer; datatype String; datatype Boolean; } The Book.km3 file

32 32 A Publication metamodel in KM3 package Publication { class Publication { attribute title: String; attribute authors: String; attribute nbPages: Integer; } package PrimitiveTypes { datatype Integer; datatype String; datatype Boolean; } To obtain both metamodels in XMI format (.ecore extension in the ATL environment) they must be injected using the injector - KM3 file to KM3 Ecore metamodel The Publication.km3 file

33 33 A Book2Publication transformation module Book2Publication; create OUT : Publication from IN : Book; rule Book2Publication { from b : Book!Book ( b.getSumPages() > 2 -- only Books with more than 2 pages are publications ) to out : Publication!Publication ( title <- b.title, authors <- b.getAuthors(), nbPages <- b.getSumPages() ) } +title : String +nbPages : Integer +author : String Chapter +title : String Book *+chapters {ordered} +book +title : String +nbPages : Integer +author : String Publication The Book2Publication.atl file 1/3

34 34 A Book2Publication transformation -- getSumPages does the same as getNbPages, -- but it uses the OCL sum operation helper context Book!Book def : getSumPages() : Integer = self.chapters->collect(f | f.nbPages).sum() ; -- getNbPages collects all nbPages of all chapters -- and calculates the sum helper context Book!Book def : getNbPages() : Integer = self.chapters->collect(f | f.nbPages)-> iterate(pages; acc : Integer = 0 | acc + pages) ; +title : String +nbPages : Integer +author : String Chapter +title : String Book *+chapters {ordered} +book The Book2Publication.atl file 2/3

35 35 A Book2Publication transformation -- getAuthors collects all Autors of a Book -- the asSet operation removes all duplicates 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) ; +title : String +nbPages : Integer +author : String Chapter +title : String Book *+chapters {ordered} +book The Book2Publication.atl file 3/3

36 36 Global view Until here, we have : – The Book and Publication metamodels – The Book2Publication transformation

37 37 Global view M1 M2 M3 KM3 grammar EBNFME/EMF ANTLREcore ATL grammar ATL metamodel Book2Publ.atl Book2Publ model ATL file to ATL model Public.km3 Book metamdel Book.km3 A KM3 file to KM3 Ecore metamodel Public metamodel

38 38 Global view Now, we need to wonder how to define the source model. For this there exist several solutions, for instance 1. To write an XMI document. ATL transformations use as input XMI documents and generate as output XMI documents. That means that models in ATL are materialized as XMI documents. 2. To write an XML document, inject it using the XML file to XML model (Ecore) and to make a very simple transformation XML to Book. The second solution is used frequently in the ATL world. We adopt this solution in the rest of this example.

39 39 Global view – XML as input and XML2Book transformation M1 M2 M3 XML schema An XML schema XML metamodel inputMod.xml inputMod- XML.ecore XML file to XML model (Ecore) XMLME/EMF ATL metamodel XML2Book model EcoreANTLR ATL grammar XML2Book.atl EBNF ATL file to ATL model It is generated automatically when an.atl file is saved

40 40 The input example in XML +title : String +nbPages : Integer +author : String Chapter +title : String Book *+chapters {ordered} +book Book metamodel XML metamodel The inputModelXML.xml file

41 41 A XML metamodel in KM3 package XML { abstract class Node { attribute startLine[0-1] : Integer; attribute startColumn[0-1] : Integer; attribute endLine[0-1] : Integer; attribute endColumn[0-1] : Integer; attribute name : String; attribute value : String; reference parent[0-1] : Element oppositeOf children; } class Attribute extends Node {} class Text extends Node {} class Element extends Node { reference children[*] ordered container : Node oppositeOf parent; } class Root extends Element {} } package PrimitiveTypes { datatype Boolean; datatype Integer; datatype String; }

42 42 A XML2Book transformation module XML2Book; create OUT : Book from IN : XML; helper context XML!Element def: getAttrVal(name : String) : String = self.children->select(c | c.oclIsKindOf(XML!Attribute) and c.name = name)->first().value; rule Book { from e : XML!Element ( e.name = 'book' ) to b : Book!Book ( title <- e.getAttrVal('title'), chapters select(c | c.oclIsKindOf(XML!Element))->asSequence() ) } rule Chapter { from e : XML!Element ( e.name = 'chapter' ) to c : Book!Chapter ( title <- e.getAttrVal('title'), nbPages <- e.getAttrVal('nbPages').toInteger(), author <- e.getAttrVal('author') )} +title : String +nbPages : Integer +author : String Chapter +title : String Book *+chapters {ordered} +book

43 43 Launch configuration – transformation file

44 44 Launch configuration – model and metamodel files

45 45 The generated file – a Book model

46 46 Global view M1 M2 M3 XML metamodel inputMod- XML.ecore ME/EMF ATL metamodel XML2Book model Ecore As a last step, we have to execute our Book2Publication transformation! Book metamodel Public metamodel Book2Publ model inputMod- Book.ecore outputMod- Public.ecore

47 47 Launch configuration – transformation file

48 48 Launch configuration – model and metamodel files

49 49 The generated file – a Publication model

50 50 Bibliography GMT Home page. http://eclipse.org/gmt/http://eclipse.org/gmt/ ATL at GMT Home Page. http://www.eclipse.org/m2m/atl/http://www.eclipse.org/m2m/atl/ – ATL presentation sheet: Short presentation of ATL project. – ATL Starter's Guide: Working draft of the ATL Starter's Guide. – ATL User Manual: Working draft of the ATL User Manual. – Specification of the ATL Virtual Machine: Working draft of the specification of the ATL Virtual Machine. – ATL Transformation Description Template: Working draft of the transformation description template. ATL home page. http://www.sciences.univ-nantes.fr/lina/atl/atldemo/


Download ppt "ATL The ATLAS Transformation Language. 2 ATL (ATLAS Transformation Language) ATL transformation pattern ATL metamodel Helpers – Operation helpers – Attribute."

Similar presentations


Ads by Google