Model Transformations Rien ne se perd rien ne
- Slides: 79
Model Transformations "Rien ne se perd, rien ne se crée, tout se transforme. " Antoine-Laurent de Lavoisier (1743 -1794) Marcellus Tavares Ricardo Roberto de Lima
Outline E E E E What is model General idea of model transformations Classification of model transformations Transformation techniques Comparison Conclusion References
Raising the level of abstraction
An Introduction to Model Transformations E Model as key artifact of MDA E Model transformations as central operation E Model transformations are also modeled
The Model-Driven Architecture E Metamodel is defined by its metamodel E Metamodel introduce semantics required to specify metamodels E Metamodel is self defined EIts specified in term of its own semantics E MOF e Ecore
The Model-Driven Architecture
Model Transformations E Specify the way to produce target models from a number source models E Developers define the way source model elements must be matched and navigated in order to initialize the target models E A model transformation is a mapping of a set of models onto another set of models or onto themselves, where a mapping defines correspondences between elements in the source and target models Caplat and Sourrouille
Model Transformation MOF Meta-model Model Transformation Meta-model PIM Meta-model Model Transformations Rules PSM Meta-model Model Transformation Engine PSM PIM
Model Transformation Ontology Model Transformation complete, disjoint Monolithic Transformation QVT ATL Compositional Transformation Viatra GRe. AT Optimal. J complete, disjoint Vertical Transformation JET Andro. MDA complete, disjoint Horizontal Transformation Endogenous Transformation Exogenous Transformation QVT ATL MMa=MMb Mma!=MMb complete, disjoint Declarative Transformation Fora QVT ATL Imperative Transformation General purpose programmi ng language
Model Transformation Ontology E Vertical EHigh-level to low-level representation EModel refinement EPIM to PSM E Horizontal EDoes not preserve source model structure EEndogen transformation ERefactoring, Update
Transformations categories E Model-to-code EVisitor-Based EVisitor mechanism to transverse model and write code EJamda (OO FW providing set of classes to represent UML Models and a visitor mechanism “code writers”) ETemplate-based EJET, Andro. MDA, Optimal. J
Transformations categories E Model-to-model ETranslate between source and target models EMost existing MDA tools do not provide EDirect-Manipulation Approach (imperative) EInternal model representation + API EOO framework ETransformations rules implemented from scratch EJava
Transformations categories E Relational approach (declarative) ESource and target as a relation ELogic programming (predicates used to describe relations) EFlora E Hybrid approach ECombine different techniques EQVT, ATL E Others EXSLT
Desirable properties of a transformation language E Be executable; E Be implementable in an efficient way; E Be fully expressive, yet unambiguous. E Facilitate developer productivity with precise, concise and clear descriptions: E Provide a means to combine transformations to form composite ones [reuse] E Provide a means to define scheduling E Defined upon a Metamodel
General purpose programming languages E Java, C++, C# E Available via APIs, Ehowever rules are implemented from scratch EAdvantage: No overhead to learn a new language EExample: Java + EMF SDK
Book To Publication considering the UML 2. 0 metamodel
Example Java + EMF SDK E E Metamodel using Ecore API provided by EMF Code Generation Model exported to XMI my. Book. xmi <? xml version="1. 0" encoding="ASCII"? > <xmi: XMI xmi: version="2. 0" xmlns: xmi="http: //www. omg. org/XMI" xmlns: book="http: //book. ecore"> <book: Book title=“Java"/> <book: Chapter num. Pages=“ 10" title="Basic" author="Deitel"/> <book: Chapter num. Pages=“ 15" title="Advanced" author="Jose"/> </xmi: XMI>
Example Java + EMF SDK public class Java. Transformation { public static void main(String[] args) { // Create a resource set. Resource. Set resource. Set = new Resource. Set. Impl(); // Register the default resource factory resource. Set. get. Resource. Factory. Registry(). get. Extension. To. Factory. Map(). put( Resource. Factory. Registry. DEFAULT_EXTENSION, new XMIResource. Factory. Impl()); // Register the package -- only needed for stand-alone! Book. Package book. Package = Book. Package. e. INSTANCE; // Source model URI file. URI = URI. create. File. URI(new File("mybook. xmi"). get. Absolute. Path()); // Get the resource Resource resource = resource. Set. get. Resource(file. URI, true); Tree. Iterator<EObject> tree. Iterator= resource. get. All. Contents(); Publication. Factory factory = Publication. Factory. e. INSTANCE; Publication publication = factory. create. Publication();
Example Java + EMF SDK String authors = null; while(tree. Iterator. has. Next()){ EObject object = tree. Iterator. next(); if (object instanceof Book){ publication. set. Title(((Book) object). get. Title()); } else { String tmp = ((Chapter) object). get. Author(); authors = publication. get. Authors(); if (authors != null){ authors = authors + ", " + tmp; } else { authors = tmp; } publication. set. Authors(authors); publication. set. Nb. Pages( ((Chapter) object). get. Num. Pages() + publication. get. Nb. Pages()); } }
Example Java + EMF SDK resource. Set = new Resource. Set. Impl(); resource. Set. get. Resource. Factory. Registry(). get. Extension. To. Factory. Map(). put( Resource. Factory. Registry. DEFAULT_EXTENSION, new XMIResource. Factory. Impl()); file. URI = URI. create. File. URI(new File("mypublication. xmi"). get. Absolute. Path()); // Create a resource for this file. resource = resource. Set. create. Resource(file. URI); // Add the publication objects to the contents. resource. get. Contents(). add(publication); // Save the contents of the resource to the file system. try { resource. save(Collections. EMPTY_MAP); } catch (IOException e) {} } } // end of class
Example Java + EMF SDK E Generated Model E my. Publication. xmi <? xml version="1. 0" encoding="ASCII"? > <publication: Publication xmi: version="2. 0" xmlns: xmi="http: //www. omg. org/XMI" xmlns: publication="http: ///publication. ecore" title="Java" nb. Pages=“ 25" authors="Deitel, Jose"/>
Flora (F-Logic) Introduction E Flora-2 is a sophisticated object-oriented knowledge base language and application development platform. E F-Logic t. RAnslator RA E Realizes the vision of logic-based KR with frames, meta, and sideefects. Founded on EF-logic EHi. Log ETransaction Logic E Practical & usable KR and programming environment EDeclarative EObject-oriented ELogic-programming style EOvercomes most of the usability problems with Prolog
Flora (F-Logic) E Implements Structural and Behavioural Inheritance with support for Single-source Multiple Inheritance E Flora is an implementation for F-logic over XSB Prolog E Frame Logic is an object oriented deductive database language E Syntactical integration between Object Oriented Paradigm and Rules E Combines expressivity and declarative semantics to object oriented concepts.
Flora - Meta. Model Sequential Transaction Frame Logic Programming Sequential Transaction Logic Programming General Logic Programming Frame Logic Programming Hilog Logic Programming Definit Logic Programming
Flora - Meta. Model DLP Package
Flora - Meta. Model DLP: : Core
Flora - Meta. Model Exemple: criminal(X) : - american(X), sells. Weapons. To(X, cuba). american(X) : - born. In(X, usa). born. In(west, usa). Program
Flora - Meta. Model Exemple: Clause criminal(X) : - american(X), sells. Weapons. To(X, cuba). american(X) : - born. In(X, usa). born. In(west, usa).
Flora - Meta. Model Exemple: Logical. Predicative. Atom criminal(X) : - american(X), sells. Weapons. To(X, cuba). american(X) : - born. In(X, usa). born. In(west, usa).
Flora - Meta. Model Exemple: Query criminal(X) : - american(X), sells. Weapons. To(X, cuba). american(X) : - born. In(X, usa). born. In(west, usa).
Flora - Meta. Model Exemple: Operator criminal(X) : - american(X), sells. Weapons. To(X, cuba). american(X) : - born. In(X, usa). born. In(west, usa).
Flora - Meta. Model a : - b , c. DLP: : Operations
Flora - Meta. Model a : - b ; c. DLP: : Operations
Flora - Meta. Model f f(a, b) g(A, 2) DLP: : Atom
Flora - Meta. Model 2 x 2. 78 “teste” f(“teste”) DLP: : Terms
Flora - Meta. Model solteiro(P) : - homem(P), not casado(P). GLP: : Operators
Flora - Meta. Model fecho(R)(X, Y) : - R(X, Y). fecho(R)(X, Y) : - R(X, Z), fecho(R)(Z, Y). HLP: : Atom
Flora - Meta. Model STLP: : Atom
Flora - Meta. Model new. Rule : - insert{p(X, Y) : - q(Y, Z)}, delete{p(2)}. Logical. Backtrackable. Update. Atom STLP: : Operators
Flora - Meta. Model FLP: : Path. Expression
Flora - Meta. Model FLP: : Atom
Flora - Meta. Model F-Logic OO Concepts F-Logic X: : Y X: Y Taxonomic F-Atom C[M->V] C[M->>V] C[M=>>V] C[M*->>V] C[M*=>>V] Non-Inheritable Value Multiplicity: single Specification Multiplicity: multi Signature Specification Inheritable
F-Logic OO Concepts X: aposentado : - X[idade->I], I>65. mary[spouse->john]. mary[spouse->joe]. john[son*->>frank].
Flora - Meta. Model Tipos de F-Atoms E Definição de hierarquia de classes (Subclass. FAtom) E cachorro : : mamifero, jacare : : reptil E mamifero : : animal, reptil : : animal E Definição de relações entre objetos/classes (Instance. FAtom): E cao 1 : cachorro, jacare 1 : jacare E Definição de valores de atributos e métodos (Attribute. Value. Specification / Method. Value. Specification): E cao 1[qtd. Patas -> 4], joao[salario(2005)->1200] E Definição dos valores e tipos herdáveis para atributos e métodos de classes (Attribute. Value. Specification / Method. Value. Specification – inheritable = true): E cachorro[qtd. Patas *-> 4], empregado[salario(2005)*->1200] E Definição de valores de atributos e métodos (Attribute. Value. Specification / Method. Value. Specification): E cao 1[qtd. Patas -> 4], joao[salario(2005)->1200]
Transformation Example
Flora E Exemplo: Livro[Titulo => string, capitulos =>> Capitulo[Numpaginas => integer, Titulo => string, Autor => string]]. Publicacao[Titulo => string, Numpaginas => integer, Autores =>> string]. P: Publicacao[Titulo -> T, Numpaginas -> N, Autores -> As] : L: Livro[Titulo -> T, capitulos ->> C], N = sum{M|C[Numpaginas -> M]}, As = collectset{A|C[Autor -> A]}. Livro 2 Publicacao : L: Livro[Titulo -> T, capitulos ->> C], N = sum{M|C[Numpaginas -> M]}, As = collectset{A|C[Autor -> A], Ltinsert{Publicacao[Titulo -> T, Numpaginas -> N, Autores -> As]}.
XSLT E e. Xtensible Stylesheet Language Transformation (XSLT) E Language (XML) for creation of documents that contains rules for processing XML documents. E Documents written in XSLT are called leaves of styles and contain: EElement XSLT: <template>, <if>, <foreach>, … EExpression XPath us to find the tree-source E Text or XML to be generated in the document-result.
XSLT
XSLT – How? E In the process of transformation, XSLT uses XPath to define parts of the document of origin which combine with one or more moulds. E When a combination is found, XSLT transform the combinante part of the document of origin in the outcome document of. E Parts of the document of origin that do not match a template will remain unchanged in the outcome document.
XSLT – Transformations E Transformation process: E Source document matching patterns E XSLT document specifying actions that copy matched elements and attributes from source document and assemble them in a novel way E Target document matching transformations XMLS Document 1 Valid XML Document 1 Source Schema Fragment Matching Patterns Target Schema XSLT Fragment Document Insertion Actions Matched Source Fragments XSLT Engine XMLS Document 2 Valid XML Document 2
XSLT – Example of Transformation 1/3 EConsider the following document-source: <aeronave id="PTGWZ"> <origem partida="08: 15">Rio de Janeiro</origem> <destino>Itabuna</destino> </aeronave>
XSLT – Example of Transformation 2/3 E The following template (part of a style sheet XSLT) can extract data from the source document.
XSLT – Example of Transformation 3/3 E XSLT elements are generally used with a prefix related to its namespace: <xsl: elemento> to avoid conflicts with the documentresult. After processing the result will be: <p>A aeronave de prefixo PTGWZ decolou de Rio de Janeiro às 8: 15 tendo como destino o aeroporto de Itabuna. </p>
XSLT – Other example. E Example: Source file: livro. xmi <model xmlns: uml="http: //www. eclipse. org/uml 2/1. 0. 0/UML" xmlns: xmi="http: //www. omg. org/XMI"> <package id="pck 1" name=“library"> <class id="c 1" name=“Livro"> <association aggregation. Type="composite" id="c 1_ass 1" name=“capitulos" target. Class="c 2"/> <attribute cardinality="1. . 1" id="c 1_atr 1" name=“Titulo" type="dt 1"/> </class> <class id="c 2" name=“Capitulo"> <attribute cardinality="1. . 1" id="c 2_atr 1" name=“Numpaginas" type="dt 2"/> <attribute cardinality="1. . 1" id="c 2_atr 2" name=“Titulo" type="dt 2"/> <attribute cardinality="1. . 1" id="c 2_atr 3" name=“Autor" type="dt 1"/> <association aggregation. Type="none" id="c 2_ass 1" name=“Livro" target. Class="c 1"/> </class> </package> </model>
XSLT – Other Example. E Example: Source file: Livro 2 Publicacao. xslt <? xml version="1. 0" encoding="UTF-8"? > <xsl: transform version="1. 0" xmlns: xsl="http: //www. w 3. org/1999/XSL/Transform" > <xsl: output method="xml" /> <xsl: template match=“publicacao. Livro" > <xsl: variable name=“Titulo" select="@Titulo" /> <xsl: variable name=“Autores" select="concat(@capitulos. autor, ', ')"/> <xsl: variable name=“Numpaginas" select="sum(@capitulos. Numpaginas)"/> <xsl: call-template name="create. Publication"> <xsl: with-param name=“Titulo" select="$Titulo"/> <xsl: with-param name=“Autores" select="$Autores"/> < xsl: with-param name=“Numpaginas" select="$Numpaginas"/> </xsl: call-template> </xsl: transform>
XSLT – Other example. E Example: Source file: Publicacao. xmi <model xmlns: uml="http: //www. eclipse. org/uml 2/1. 0. 0/UML" xmlns: xmi="http: //www. omg. org/XMI"> <package id="pck 1" name=“library"> <class id="c 1" name=“Publicação"> <attribute cardinality="1. . 1" id="c 1_atr 1" name=“Titulo" type="dt 1"/> <attribute cardinality="1. . 1" id="c 1_atr 2" name=“Numpaginas" type="dt 2"/> <attribute cardinality="1. . 1" id="c 1_atr 3" name=“Autores" type="dt 1"/> </class> <datatype id="dt 1" name="String"/> <datatype id="dt 2" name="Integer"/> </package> </model>
QVT E Standard for model transformation proposed by OMG E RFP issued by OMG on MOF Query/Views/Transformations E Key ideas ESource and target models conform to MOF metamodels. ETransformation program as a model E Hybrid nature E Two level declarative model
QVT Overview E Core EPattern matching over a flat set of variables EDefined using minimal extensions to EMOF and OCL EFine grained (one mapped identity per rule) ESimple transformation language E Relations EObject pattern matching and object template creation ECoarse grained (many mapped identities per rule) ESpecification of relations over model elements E Operational EProcedural definition EExtends Relations language with imperative constructs ETwo mechanisms for invoking imperative implementations EOperational Mapping (standard) EBlack box MOF Operations implementations
Relationship between Relations and Core E Core is a small extension of EMOF classes and OCL expressions Emanipulates trace models explicitly E Relations adds Eextended pattern syntax Eimplicit trace models E Both languages have a similar evaluation semantics Emulti-direction execution Eincremental update / change propagation semantics Eimplicit object creation and deletion E Relations is mapped (reduced) to Core to provide its full semantics
QVT - Package dependencies
Relation Language – Abstract Syntax
QVT – Relation Language E Relation E Transformation between candidate model is specified as a set of relations that must hold transformation uml. Rdbms (uml : Simple. UML, rdbms : Simple. RDBMS) { } E A relation declare constraints that must be satisfied by the elements of candidate models E Domains E When Pattern E Where Pattern
QVT – Relation Language E Domain Edistinguished typed variable that can be matched in a model of a given model type EA domain has patterns ESet of variables and a set of constraints that model elements bound to those variables must satisfy to qualify as a valid binding of the pattern relation Package. To. Schema /* map each package to a schema */ { domain uml p: Package {name=pn} domain rdbms s: Schema {name=pn} }
QVT – Relation Language E When Especifies the conditions under which the relationship needs to hold E Where Especifies the condition that must be satisfied by all model elements participating in the relation E The when and where clauses may contain any arbitrary OCL expressions in addition to the relation invocation expressions.
Example QVT Relational
QVT - Core Language E Transformation consists of a number of Mapping Rules. E Each Mapping Rule consists of a constellation of Patterns E Patterns consist of variables and OCL expressions. E A binding of a pattern is a unique set of values for all of its variables, for which all the OCL expressions hold
Core Language - Abstract Syntax
QVT – Core Language E Domain E Has an associated model type of the transformation (model candidates) E Area E Consists of two patterns E Pattern E Set of variables, predicates and assignments E Can be matched or enforced E Can depend on each other E Guard Pattern E Narrow the selection of model elements to be considered for the mapping E Only used for defined a context E Bottom Pattern E Defines the derivations E Can have realized variables, assignments and black-box operation E Mapping E One are for the trace and one for each model type E Defines a relation between bottom patterns
Mapping Rule Example Class to Table Attribute to Column UML/Rel Relational c : Class c 2 t : Class. Table | c 2 t. table = t; c 2 t. class = c; t : Table 1 1 1 * * * a : Attribute | a. class : = c; 1 a 2 c : Attr. Column | 1 a 2 c. owner : = c 2 t; 1 a 2 c. attr : = a; a 2 c. column : = c; 1 c : Column | c. table : = t; Bottom pattern is evaluated using the variable values of the valid binding of the guard pattern.
Core/Relational comparison E Aspects that have to be defined explicitly when using core language EThe patterns that match against, and create the instances of the classes that are the trace objects of the transformation (e. g. the links between the transformed model elements). EAtomic sets of model elements that are created or deleted as a whole, specified in smaller patterns than commonly specified in the Relational Language.
QVT Operational – Abstract Syntax
QVT - Operational Language E Operational Transformations EDefinition of a unidirectional transformations that is expressed imperatively EIts signature defines E Models involved in transformation E Entry E operation for execution
QVT - Operational Language E Mapping Eoperation that implements a mapping between one or more source model elements into one or more target model elements. E Libraries Econtains definitions that can be reused by transformations EIt may define specific types and may define operations
QVT E Helper EAllow writing complex navigations in a confortable way EReuse
Model Transformation expressed in Operational Mappings Language Overall structure of a transformation program: metamodel 'http: //www. borland. com/together/uml 20'; transformation Book. To. Publication (in Input. Metamodel): Output. Metamodel Signature: Declares the identifier of the transformation ………………………………… main () { ………………………………… Entry point: The execution of the transformation starts here by executing the operations in the body of main. It also declares the source and target metamodels. } ………………………………… in keywords indicate source and target model variables. The target is represented by the return of main. …helpers……………………… …mapping operations………………………… Transformation elements: Transformation consists of mapping operations and helpers. They form the transformation logic.
Book. To. Publication Example in the OMG QVT Specification metamodel BOOK { class Book {title: String; composite chapters: Chapter; } class Chapter {title : String; nb. Pages : Integer; } } metamodel PUB { class Publication {title : String; nb. Pages : Integer; } } transformation Book 2 Publication(in book. Model: BOOK, out pub. Model: PUB) main() { book. Model->object. Of. Type(Book)->map book_to_publication(); } mapping Class: : book_to_publication () : Publication { title : = self. title; nb. Pages : = self. chapters->nb. Pages->sum(); }
Comparation Table Java FLORA XSLT QVT Concise + + - +/- well-know languages - - + - Efficient + + - - Executable + + + - Expressive + + Metamodel + + - + Formal semantics - + - - Standards + - +/- + All OO/MOF concepts + +/- + Tools + - - +/- Legend: +: requirement well fulfilled +/-: requirement partially, weakly, impractically fulfilled -: not fulfilled
Conclusions E Model Transformations are assets Eguided by sound Soft. Engineering principles EAnalysis, Design, Implementation, V & V (Test), and Configuration Management (evolution) E Transformations should also be models (principles of MDE) EIn order to tackle complexity
References E E E E http: //en. wikipedia. org/wiki/QVT http: //en. wikipedia. org/wiki/XSLT http: //en. wikipedia. org/wiki/VIATRA http: //en. wikipedia. org/wiki/GRe. AT http: //en. wikipedia. org/wiki/Visitor_pattern http: //modelware. inria. fr http: //www. modelware-ist. org (Main Repository Page Training) http: //www. eclipse. org/gmt/EMF Czarnecki and Helsen: Classification of Model Transformation Approaches. Shane Sendall and Wojtek Kozaczynski: Model Transformation – the Heart and Soul of Model-Driven Software Development Anna Gerber at al: Transformation: The Missing Link of MDA QVT Specification Dariusz Gall, Michal Molenda: EDOC to EJB transformations within MDA
- Rien ne se perd
- Rien ne se perd tout se transforme citation
- Que rien ne te trouble paroles
- Vark manlik en vroulik
- Manlike en vroulike
- Stadsmariniers rotterdam
- édith piaf non je ne regrette rien letras
- Ne manger rien ou jeuner voila bien votre grande bêtise
- Levons nos mains vers le ciel
- Ce matin paroles
- Loi du tout ou rien
- Le travail c'est la santé ne rien faire
- Sans jesus je ne peux vivre
- La mort nest rien
- Henry scott holland l'amour ne disparaît jamais
- La tendresse on peut vivre sans richesse
- Rien visser
- Prends rien
- Ils font rien
- Cuantos años rien
- Pourquoi y a t il quelque chose plutôt que rien heidegger
- Difference between concentric zone model and sector model
- Sine and cosine graphs
- Intercept form
- Using transformations to graph quadratic functions
- Absolute value graph transformations
- Rational function parent function
- Exponential form examples
- Types of transformations
- Tan function period
- Algebra 2 transforming linear functions
- Rotations on a coordinate plane
- Transformations of sine and cosine functions
- How to find the amplitude of a graph
- Four types of transformations
- Translation rule geometry
- Energy transformations lab
- Mathisfun tetris
- Figure abcde is similar to figure vwxyz
- Proving figures are similar using transformations
- Non-rigid transformations
- Graph transformations
- Reported speech transformations
- Standard form transformations
- Jordan peterson personality and its transformations
- Properties of transformations
- Function family graphs
- Transformations of functions
- Lorentz transformation equation derivation
- Types of lexical transformations
- Complete correspondences of lexical units of
- Kinds of transformations
- 9-3 transformations of quadratic functions
- Process transformation
- Multiple transformations geometry
- Power law transform
- Energy conversion in car
- Translating graphs worksheet
- Xnnn
- Absolute value graph translations
- 4-7 congruence transformations
- Lorentz transformation equation derivation
- Drfrostmaths
- Exponential function description
- Exponential function transformation calculator
- Energy transformations in photosynthesis
- 3 types of energy transformations
- Multiple transformations occur when
- What is a composition of rigid motions
- Imagep unscramble
- 8-2 practice the reciprocal function family
- Sin cos tan graph
- Draw the thevenin equivalent circuit
- Congruence and transformations
- Block diagram transformation theorems
- 2-7 parent functions and transformations answer key
- 9-6 dilations
- 9-4 compositions of transformations
- Compositions of transformations
- Transformation of quadratic functions calculator