1 / 61

Model Transformations

Model Transformations. Fabrício Teles, Rodrigo Teixeira {fst,rtr}@cin.ufpe.br. Outline. What is a model transformation? Purposes in MDD Taxonomy Techniques General purpose programming languages Generic transformation tools (XSLT and Viatra) Dedicated transformation language (QVT and ATL)

verde
Télécharger la présentation

Model Transformations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Model Transformations Fabrício Teles, Rodrigo Teixeira {fst,rtr}@cin.ufpe.br

  2. Outline • What is a model transformation? • Purposes in MDD • Taxonomy • Techniques • General purpose programming languages • Generic transformation tools (XSLT and Viatra) • Dedicated transformation language (QVT and ATL) • Comparison

  3. What is a model transformation? • Transformations takes model and produces model • PIM to PSM a la OMG MDA • Refining and refactoring models • Reverse engineering • Generate new views • Applying design patterns • Deriving products in a product line ...Any model engineering activity that can be automated...

  4. Typical example (UML to RDMS)

  5. Taxonomy • Declarative • What is mapped • Imperative • How it is mapped • Hybrid

  6. Operational Context MOF conformsTo conformsTo Define Transformation Meta-model A Meta-model B Transformation based on based on conformsTo conformsTo output input Model A Model B Apply Transformation using Engine

  7. Model transformationstechniques • General purpose programming languages • Imperative object-oriented programming (Java) • Declarative object-oriented logic programming (Flora) • Generic transformation tools • Graph transformations (VIATRA) • XSLT • Case tools scripting languages (Rose) • Dedicated model transformations tools • OMG QVT style (QVT, ATL) • Meta-modeling tools (Kermeta)

  8. General purpose programming languages • Java, VB, C# (take your favourite lang.) • Available via APIs, • however rules are implemented from scratch • Example: JMI (MOF-compliant Java Interface) • No overhead to learn a new language • The programming complexity problem, which MDD wish mastering, continues

  9. Flora (F-Logic) • Frame Logic is an object oriented deductive database language • Syntactical integration between Object Oriented Paradigm and Rules • Combines expressivity and declarative semantics to object oriented concepts. • Implements Structural and Behavioural Inheritance with support for Single-source Multiple Inheritance • Flora is an implementation for F-logic over XSB Prolog

  10. Flora - MetaModel Sequential Transaction Frame Logic Programming Sequential Transaction Logic Programming Frame Logic Programming General Logic Programming Hilog Logic Programming Definit Logic Programming

  11. Flora - MetaModel DLP Package

  12. Flora - MetaModel DLP::Core

  13. Program Flora - MetaModel Exemple: criminal(X) :- american(X), sellsWeaponsTo(X,cuba). american(X) :- bornIn(X,usa). bornIn(west, usa).

  14. Clause Flora - MetaModel Exemple: criminal(X) :- american(X), sellsWeaponsTo(X,cuba). american(X) :- bornIn(X,usa). bornIn(west, usa).

  15. LogicalPredicativeAtom Flora - MetaModel Exemple: criminal(X) :- american(X), sellsWeaponsTo(X,cuba). american(X) :- bornIn(X,usa). bornIn(west, usa).

  16. Query Flora - MetaModel Exemple: criminal(X) :- american(X), sellsWeaponsTo(X,cuba). american(X) :- bornIn(X,usa). bornIn(west, usa).

  17. Operator Flora - MetaModel Exemple: criminal(X) :- american(X), sellsWeaponsTo(X,cuba). american(X) :- bornIn(X,usa). bornIn(west, usa).

  18. a :- b , c. Flora - MetaModel DLP::Operations

  19. a :- b ; c. Flora - MetaModel DLP::Operations

  20. f f(a,b) g(A,2) Flora - MetaModel DLP::Atom

  21. 2 x 2.78 “teste” f(“teste”) Flora - MetaModel DLP::Terms

  22. Flora - MetaModel solteiro(P) :- homem(P), not casado(P). GLP::Operators

  23. Flora - MetaModel fecho(R)(X,Y) :- R(X,Y). fecho(R)(X,Y) :- R(X,Z), fecho(R)(Z,Y). HLP::Atom

  24. Flora - MetaModel STLP::Atom

  25. LogicalBacktrackableUpdateAtom Flora - MetaModel newRule :- insert{p(X, Y) :- q(Y,Z)}, delete{p(2)}. STLP::Operators

  26. Flora - MetaModel FLP::PathExpression

  27. Flora - MetaModel FLP::Atom

  28. F-Logic X::Y X:Y C[M->V] C[M->>V] Taxonomic F-Atom C[M=>V] C[M=>>V] Non-Inheritable C[M*->V] C[M*->>V] Multiplicity: single Multiplicity: multi Signature Specification Value Specification C[M*=>V] Inheritable C[M*=>>V] F-Logic OO Concepts Flora - MetaModel

  29. F-Logic OO Concepts X:aposentado :- X[idade->I], I>65. mary[spouse->john]. mary[spouse->joe]. john[son*->>frank].

  30. Flora - MetaModel Tipos de F-Atoms • Definição de hierarquia de classes (SubclassFAtom) • cachorro :: mamifero, jacare :: reptil • mamifero :: animal, reptil :: animal • Definição de relações entre objetos/classes (InstanceFAtom): • cao1 : cachorro, jacare1 : jacare • Definição de valores de atributos e métodos (AttributeValueSpecification / MethodValueSpecification): • cao1[qtdPatas -> 4], joao[salario(2005)->1200] • Definição dos valores e tipos herdáveis para atributos e métodos de classes (AttributeValueSpecification / MethodValueSpecification – inheritable = true): • cachorro[qtdPatas *-> 4], empregado[salario(2005)*->1200] • Definição de valores de atributos e métodos (AttributeValueSpecification / MethodValueSpecification): • cao1[qtdPatas -> 4], joao[salario(2005)->1200]

  31. Book To Publication Example

  32. Flora • Exemple: book[title => string, chapters =>> chapter[nbPages => integer, title => string, author => string]]. publication[title => string, nbPages => integer, authors =>> string]. P:publication[title -> T, nbPages -> N, authors -> As] :- B:book[title -> T, chapters ->> C], N = sum{M|C[nbPages -> M]}, As = collectset{A|C[author -> A]}. book2publication :- B:book[title -> T, chapters ->> C], N = sum{M|C[nbPages -> M]}, As = collectset{A|C[author -> A], btinsert{publication[title -> T, nbPages -> N, authors -> As]}. F-logic file

  33. eXtensible Stylesheet Language Transformation (XSLT) • XML-based language used for the transformation of XML documents • Part of a W3C family of languages (XSL) • Describes how to format and transform XML files • XSLT, XSL-FO, XPath • Used to model transformation • Where models are in XMI encoding format

  34. eXtensible Stylesheet Language Transformation (XSLT) • XSLT Characteristics • Declarative rather than imperative • Consist of a template rules collection • Each rule specifies what to add to a target fragment • Based on a source fragment and a fixed algorithm • XSLT processor scan the source tree, apply rules and generate de target tree • Syntactical & ineffic for model transformations • XML (XMI) is verbose • Operates on tree structures • More batch than interactive • Parameters passed by value

  35. Target Schema Fragment Insertion Actions Matched Source Fragments XSLT Document XMLS Document 2 XMLS Document 1 Source Schema Fragment Matching Patterns Valid Valid XML Document 2 XML Document 1 XSLT Engine eXtensible Stylesheet Language Transformation (XSLT) • Transformation process: • Source document matching patterns • XSLT document specifying actions that copy matched elements and attributes from source document and assemble them in a novel way • Target document matching transformations

  36. eXtensible Stylesheet Language Transformation (XSLT) • Exemple: <model xmlns:uml="http://www.eclipse.org/uml2/1.0.0/UML" xmlns:xmi="http://www.omg.org/XMI"> <package id="pck1" name=“library"> <class id="c1" name="Book"> <association aggregationType="composite" id="c1_ass1" name="chapters" targetClass="c2"/> <attribute cardinality="1..1" id="c1_atr1" name="title" type="dt1"/> </class> <class id="c2" name="Chapter"> <attribute cardinality="1..1" id="c2_atr1" name="nbPages" type="dt2"/> <attribute cardinality="1..1" id="c2_atr2" name="title" type="dt2"/> <attribute cardinality="1..1" id="c2_atr3" name="author" type="dt1"/> <association aggregationType="none" id="c2_ass1" name="book" targetClass="c1"/> </class> </package> </model> Source file: book.xmi

  37. eXtensible Stylesheet Language Transformation (XSLT) • Exemple: <?xml version="1.0" encoding="UTF-8"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output method="xml" /> <xsl:template match="library.Book" > <xsl:variable name="title" select="@title" /> <xsl:variable name="authors" select="concat(@chapters.author, ',')"/> <xsl:variable name="nbPages" select="sum(@chapters.nbPages)"/> <xsl:call-template name="createPublication"> <xsl:with-param name="title" select="$title"/> <xsl:with-param name="authors" select="$authors"/> < xsl:with-param name="nbPages" select="$nbPages"/> </xsl:call-template> </xsl:template> </xsl:transform> XSLT file: book2Publicartion.xslt fragment

  38. eXtensible Stylesheet Language Transformation (XSLT) • Exemple: <model xmlns:uml="http://www.eclipse.org/uml2/1.0.0/UML" xmlns:xmi="http://www.omg.org/XMI"> <package id="pck1" name=“library"> <class id="c1" name="Publication"> <attribute cardinality="1..1" id="c1_atr1" name="title" type="dt1"/> <attribute cardinality="1..1" id="c1_atr2" name="nbPages" type="dt2"/> <attribute cardinality="1..1" id="c1_atr3" name="authors" type="dt1"/> </class> <datatype id="dt1" name="String"/> <datatype id="dt2" name="Integer"/> </package> </model> Target file: publication.xmi

  39. CASE tool scripting language • Ex.: Rose, OptimalJ, Arcstyler, Fujaba • Pro • Good level of maturity • Excellent integration with their CASE tool • Drawback • Proprietary language • Often developed as a second thought, not central • Many limitations when model transformations get complex • Structuration, modularity, reuse and configuration management problems

  40. Query-View-Transformation (QVT) • OMG standard language for expressing queries, views, and transformations on MOF models • DSL for transformation aimed for • Simple development and maintenance of model transformations • With higher expression power • And enhanced structuration • Composition of rules and Interoperability OCL-based hybrid procedural and declarative transformation language

  41. QVT [hybrid] Architecture Imperative Declarative

  42. Overview of the Architecture • Declarative Relations transformation language • Specification of relations over model elements • Declarative Core transformation language • Simple transformation language • Reference point for defining the semantics of the Relations language • Operational Mappings • Imperative transformation language • Extends Relations language with imperative constructs

  43. Package dependencies in QVT

  44. QVT Operational Package

  45. Model Transformation expressed inOperational Mappings Language Overall structure of a transformation program: metamodel 'http://www.borland.com/together/uml20'; transformation BookToPublication (in InputMetamodel): OutputMetamodel ………………………………………………………………… main () { ………………………………………………………………… } ………………………………………………………………… …helpers…………………………………………… …mapping operations……………… ………………………………………………… Signature: Declares the identifier of the transformation 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. Transformation elements: Transformation consists of mapping operations and helpers. They form the transformation logic.

  46. BookToPublication Example in the OMG QVT Specification [05-11-01.pdf] metamodel BOOK { class Book {title: String; composite chapters: Chapter;} class Chapter {title : String; nbPages : Integer;} } metamodel PUB { class Publication {title : String; nbPages : Integer;} } transformation Book2Publication(in bookModel:BOOK,out pubModel:PUB) main() { bookModel->objectOfType(Book)->map book_to_publication(); } mapping Class::book_to_publication () : Publication { title := self.title; nbPages := self.chapters->nbPages->sum(); }

  47. Book To Publication considering the UML 2.0 metamodel

  48. BookToPublication - Together (imperative QVT implementation) mappingmain(in model: uml::together::Model): ... Model { ownedMembers += replaceClasses (model); ownedMembers += replaceInstances (model); } query getClasses (in root: ...Model): OrderedSet(...Class){ root.ownedMembers->...collect(c | class2class(c.oclAsType(...Class)))-> asOrderedSet(); } query publicationClass () : ...Class object uml20::classes::Class { name := 'Publication'; ownedAttributes += object uml20::kernel::Property { name := 'title'; type := string}; ...

  49. BookToPublication – Together (cont.) mapping publicationInstance (in bookInstance: InstanceSpecification) :... when { bookInst.instantiates->...exists(c | c.name = 'Book')} var publicationClass := bookInst.instantiates->select( ... 'Publication‘... name := 'Publication'+bookInst.name; instantiates += bookInst.instantiates->resolve(‘class2class’) .... slots += object uml20::kernel::instances::Slot { definingFeature := publicationClass >select...-> any(... | feature.name = 'authors'); values += select (bookInst.dependencies ... -> select( ... 'chapters')-> ....select( ...definingFeature.name = 'authors')-> .... iterate(authorName; acc : String = ‘ ' | acc + (if acc = ‘ ' then authorName else ' and ' + authorName endif)); ...

  50. ATL • Source models and target models are distinct: • Source models are read-only (they can only be navigated, not modified), • Target models are write-only (they cannot be navigated). • The language is a declarative-imperative hybrid: • Declarative part: • Matched rules with automatic traceability support, • Side-effect free navigation (and query) language: OCL 2.0 • Imperative part: • Called rules, • Action blocks. • Recommended programming style: declarative

More Related