Model Transformations @ Google

Model Transformations

An overview

Pierre-Alain Muller INRIA [email protected] Artist2 Summer School 05 Pierre-Alain Muller 2

Outline Principles of Model-Driven Engineering

►MDE basic principles ►A kind of (software) development approach ►What is a model-transformation? ►Models as first class entities ►Typology of model-transformations ►Everything is a model ►Examples of transformations ►A model conforms to an other model (meta- model) ►A model transformation takes models and produces models ►A model-transformation is a model

Artist2 Summer School 05 Pierre-Alain Muller 3 Artist2 Summer School 05 Pierre-Alain Muller 4

MDA = MDE à la OMG Meta-modeling architecture

Computer ►OMG, Object Management Group M3 Meta-Metamodel ►MDA, Model-Driven Architecture ►PIM, Platform Independent Model M2 Metamodel ►PSM, Platform Specific Model M3 M2 M1 M0 M1 Model ►(PDM, Platform Description Model)

►Transformation (PIM, PDM) -> PSM M0 Computer Manifestation RFP MOF Q/V/T Query, Views, Transformations RFP MOF to Text Real World Often misleading

Artist2 Summer School 05 Pierre-Alain Muller 5 Artist2 Summer School 05 Pierre-Alain Muller 6

1 Motivation But also

►Model transformation is key to Model-Driven ►Refining models Engineering ►Reverse engineering (code to models) Automation of the transition from Business Automation of the transition from Business ►Generating new views models to Implementation models ►Applying design patterns

Business ►Refactoring models Transformation Implementation Description

Platform

Artist2 Summer School 05 Pierre-Alain Muller 7 Artist2 Summer School 05 Pierre-Alain Muller 8

Typical scope for transformations Related fields

Program transformation and compiler techniques Meta-programming techniques Graph rewriting techniques

Artist2 Summer School 05 Pierre-Alain Muller 9 Artist2 Summer School 05 Pierre-Alain Muller 10

MOF 2.0 Transformation Architecture Queries/Views/Transformations RFP Transformation Architecture

► Define a language for querying MOF models Define Transformation ► Define a language for transformation definitions Meta-model A Meta-model B ► Allow for the creation of views of a model ► Ensure that the transformation language is declarative and expresses complete Conforms To Transformation Conforms To transformations ► Ensure that incremental changes to source models can be immediately propagated to the target Model A Model B models Apply Transformation ► Express all new languages as MOF models

Artist2 Summer School 05 Pierre-Alain Muller 11 Artist2 Summer School 05 Pierre-Alain Muller 12

2 Typical Example Transformations as models

From UML to RDBMS ►Composition of transformations ►Transformation of transformations

Meta-Meta-model

Transformation Transformation Meta-model Meta-model

Model Transformation Model

Artist2 Summer School 05 Pierre-Alain Muller 13 Artist2 Summer School 05 Pierre-Alain Muller 14

Toward Model-Transformations General purpose language approach

►CRUD on model elements ► Java, VB, C++, C#,... Your favorite language! ► Currently available in the tools via APIs Create, Read, Update, Delete ► No overhead to learn a new language ► Tool support to write the transformations ►Transformation rules written in Tool support to write the transformations General purpose languages + API Intermediate transformation language => Monsieur Jourdain’s approach Dedicated Model-Transformation languages ► It’s going to be challenging to do better!

Artist2 Summer School 05 Pierre-Alain Muller 15 Artist2 Summer School 05 Pierre-Alain Muller 16

Action Language Intermediate transformation language

►Use a general purpose action language ► Typically XML based Better navigation facility (associations) But XML (XMI) is verbose Get access to the types defined in the models ► XSLT can be used to transform XML trees into Procedural rule description other (XML) (trees) More batch than interactive Parameters are passed by values XSLT transformations are not really easy to maintain ► Better for simple transformations

Artist2 Summer School 05 Pierre-Alain Muller 17 Artist2 Summer School 05 Pierre-Alain Muller 18

3 Example of XSLT transformation Dedicated Transformation Language

►Kind of DSL for transformation If isSynchronous

►Simplify development and maintenance of Do this model-transformations ►Higher expression power Else ►Enhanced structuration Composition of rules Do that Interoperability

Artist2 Summer School 05 Pierre-Alain Muller 19 Artist2 Summer School 05 Pierre-Alain Muller 20

Dedicated transformation languages Query

►Terminology ►An expression evaluated over a model ►Features of model transformations Returns one or more instances of types defined either in the source model or by the query language

►OCL is an example of a query language

Artist2 Summer School 05 Pierre-Alain Muller 21 Artist2 Summer School 05 Pierre-Alain Muller 22

Examples of OCL queries View

►A view is a model that is completely derived OCL from another model Standard Lib Type The meta-model of the view is typically not the same as the meta-model of the source Query: Has Pierre-Alain Muller sent a message about a given subject s?

s.post->exists (author.name='Muller' and author.firstname='Pierre-Alain') Meta-Model A Meta-Model A’

Query: Knowing that there is only one subject about QVT, I want to retrieve it. Model Transformation View Subject.allInstances()->any (title = ‘QVT’) Model Type Artist2 Summer School 05 Pierre-Alain Muller 23 Artist2 Summer School 05 Pierre-Alain Muller 24

4 Transformation Q vs V vs T

►A transformation generates a target model ►A query is a restricted kind of view from a source model

Source Target ►A view is a restricted kind of transformation Transformation Model Model The target model cannot be modified independently of the source model

May be bi-directional ►A transformation generates a target model from a source model

Artist2 Summer School 05 Pierre-Alain Muller 25 Artist2 Summer School 05 Pierre-Alain Muller 26

Declarative Imperative

►Declarative languages describe relationships ►Any programming language that specifies between variables in terms of functions or explicit manipulation of the state of the inference rules and the language executor computer system, not to be confused with a (interpreter or compiler) applies some fixed procedural language algorithm to these relations to produce a result

Artist2 Summer School 05 Pierre-Alain Muller 27 Artist2 Summer School 05 Pierre-Alain Muller 28

Declarative vs. Imperative Style Execution Strategy

► Declarative (what to do) ►Invocation of the transformation rules Invariant relations between source and target models Explicit, via invocation operations (Java like) Implicit, based on contextcontext and rules’ signature ► Imperative (how to do it) How to derive a target from a source (Prolog like)

► May be combined via pre- and post-conditions

Declarative Declarative Pre-Condition Imperative Rule Post-Condition

Artist2 Summer School 05 Pierre-Alain Muller 29 Artist2 Summer School 05 Pierre-Alain Muller 30

5 Trace Rule

►Trace associates one (or more) target ►Rules are the units in which transformations element with the source elements that lead are defined to its creation A rule is responsible for transforming a For Round-trip development particular selection of the source model to the Incremental propagation corresponding target model elements.

►Rules may be able to match elements based on the trace without knowing the rules that created the trace

Artist2 Summer School 05 Pierre-Alain Muller 31 Artist2 Summer School 05 Pierre-Alain Muller 32

Declaration Implementation

►A declaration is a specification of a relation ►An implementation is an imperative between elements in the LHS and RHS specification of how to create target model models elements from source model elements An implementation explicitly constructs elements in the target model Implementations are typically directed

Artist2 Summer School 05 Pierre-Alain Muller 33 Artist2 Summer School 05 Pierre-Alain Muller 34

Match Incremental

►A match occurs during the application of a ►A transformation is incremental if individual transformation when elements from the LHS changes in a source model can lead to and/or RHS model are identified as meeting execution of only those rules which match the constraints defined by the declaration of the modified elements a rule A match triggers the creation (or update) of model elements in the target model

Artist2 Summer School 05 Pierre-Alain Muller 35 Artist2 Summer School 05 Pierre-Alain Muller 36

6 Classification of model transformations Model-to-Text Approaches

►Visitor-Based Approaches ►Template-Based Approaches

Artist2 Summer School 05 Pierre-Alain Muller 37 Artist2 Summer School 05 Pierre-Alain Muller 38

Model-to-Model Approaches M2T: Visitor-based

►Direct-Manipulation Approaches ►Some visitor mechanisms to traverse the ►Relational Approaches internal representation of a model and write code to a text stream ►Graph-transformation-based Approaches Iterators ►Structure-Driven Approaches Write () ►Hybrid Approaches ►Other

Artist2 Summer School 05 Pierre-Alain Muller 39 Artist2 Summer School 05 Pierre-Alain Muller 40

M2T: Template-Based M2T : Template

►A template consists of the target text containing slices of meta-code to access information from the source and to perform text selection and iterative expansion The structure of a template resembles closely the text to be generated Textual templates are independent of the target language and simplify the generation of any textual artefacts

Artist2 Summer School 05 Pierre-Alain Muller 41 Artist2 Summer School 05 Pierre-Alain Muller 42

7 M2M: Direct Manipulation JMI examples

package javax.jmi.model; Attributes ►Internal representation plus some API to import javax.jmi.reflect.*; manipulate it public interface Attribute extends StructuralFeature { ► public boolean isDerived(); ►Object-oriented framework public void setDerived(boolean newValue); ►Rules and scheduling implemented from } package javax.jmi.model; scratch using a programming language import javax.jmi.reflect.*; Operations public interface Operation extends BehavioralFeature { ►JMI (MOF-compliant Java Interface) public boolean isQuery(); public void setQuery(boolean newValue); JSR-000040 Java™ Metadata Interface public java.util.List getExceptions(); }

Artist2 Summer School 05 Pierre-Alain Muller 43 Artist2 Summer School 05 Pierre-Alain Muller 44

M2M: Relational Approaches Example of logic programming

► Declarative, based on mathematical relations ►Excerpt of Mercury code Good balance between flexibility and declarative expression

► Implementable with logic programming Mercury, F-Logic programming languages Predicate to describe the relations Unification based-matching, search and backtracking

Artist2 Summer School 05 Pierre-Alain Muller 45 Artist2 Summer School 05 Pierre-Alain Muller 46

M2M : Graph-Transformation-Based About Graphs

►Declarative, based on the theoretical work ►G. Rozenberg (ed.); “Handbook of graph on graph transformations grammars and computing by graph Operates on typed, attributed, labeled graphs transformation: Volume I Foundations”. Rule (LHS, RHS : Graph Pattern) World Scientific Publishing, 1997.

►Automated source element selection ►Web site of Reiko Heckel ☺

Artist2 Summer School 05 Pierre-Alain Muller 47 Artist2 Summer School 05 Pierre-Alain Muller 48

8 M2M : Graph-Transformation-Based M2M : Structure-Driven Approaches

►Powerfull, but complex because of the non- ►1st Phase determinism in scheduling and application Creation of hierarchical structure of target strategy model Require careful consideration of termination of ►2nd Phase the transformation process and the rule 2nd Phase application ordering Set the attributes and references in the target

►It is unclear how practitioners will receive ►Users provide the transformation rules these complex approaches ►Framework determines the scheduling

Artist2 Summer School 05 Pierre-Alain Muller 49 Artist2 Summer School 05 Pierre-Alain Muller 50

M2M : Structure-Driven Approaches M2M : Hybrid Approaches - others

►Pragmatic approaches developed in the ►Any combination of different techniques context of EJB and Databases schema generation from UML models ►Practical approaches are very likely to have ►Strong support for 1-to-1 and 1-to-n the hybrid character correspondence between source and target ►Unclear how well these approaches can support other kinds of applications

Artist2 Summer School 05 Pierre-Alain Muller 51 Artist2 Summer School 05 Pierre-Alain Muller 52

Practically speaking Tools

►How many developers are familiar with the ►Generic transformation tools prolog-like style of rules writing? ►CASE tools scripting languages ►Dedicated model transformation tools ►Where is the advantage of a dedicated explicit language vs. a general purpose ►Meta-modeling tools language?

►Hybrid Languages or transformation libraries for general purpose languages…

Artist2 Summer School 05 Pierre-Alain Muller 53 Artist2 Summer School 05 Pierre-Alain Muller 54

9 Generic transformation tools CASE tools scripting languages

►XSLT ►Arcstyler from Interactive Objects MDA-Cartridge, JPython (Python & Java) ►Graph Transformation tools ►Objecteering from Objecteering Software Ask Reiko ☺ J language ►OptimalJ from Compuware TPL language ►Fujaba (From UML to Java and Back Again) Open Source

Artist2 Summer School 05 Pierre-Alain Muller 55 Artist2 Summer School 05 Pierre-Alain Muller 56

Dedicated model transformation tools Meta-modeling tools

►Mia-Transformation from Mia-Software ►MetaEdit+ from MetaCase Inference rules + Java ►XMF-Mosaic from Xactium ►PathMATE from Pathfinder Solutions Esay to integrate with modeling tools ►Open-Source KerMeta from INRIA ►Open-Source www.kermeta.org ATL, MTL, AndroMDA, BOTL, Coral Mod- Transf, QVTEclipse or UMT-QVT

Artist2 Summer School 05 Pierre-Alain Muller 57 Artist2 Summer School 05 Pierre-Alain Muller 58

Coming soon References

► M. Andries, G. Engels, A. Habel, B. Hoffmann, H.-J. Kreowski, S. Kuske, D. ►Model Transformations in Practice Kuske, D. Plump, A. Schürr, and G. Taentzer. Graph Transformation for Specification and Programming. Technical Report 7/96, Universität Bremen, Workshop 1996, see http://citeseer.nj.nec.com/article/andries96graph.html ► D. H. Akehurst, S.Kent. A Relational Approach to Defining Transformations in a October 3rd 2005 Metamodel. In J.-M. Jézéquel, H. Hussmann, S. Cook (Eds.): UML 2002 - The October 3rd 2005 Unified Modeling Language 5th International Conference, Dresden, Germany, Part of the MoDELS 2005 Conference September 30 - October 4, 2002. Proceedings, LNCS 2460, 243-258, 2002. Part of the MoDELS 2005 Conference ► Alcatel, Softeam, Thales, TNI-Valiosys, Codagen Corporation, et al. MOF Query/Views/Transformations, Revised Submission. OMG Document: ad/03-08- ►Comparing and contrasting various 05 ► CBOP, DSTC, and IBM. MOF Query/Views/Transformations, Revised approaches Submission. OMG Document: ad/03-08-03 ► C. Cleaveland. Program Generators with XML and Java. Prentice-Hall, 2001, see http://www.craigc.com/pg/ ► K. Czarnecki, S. Helsen, Classification of Model Transformation Approaches, OOPSLA’03 Workshop on Generative Techniques in the Context of Model- Driven Architecture.

Artist2 Summer School 05 Pierre-Alain Muller 59 Artist2 Summer School 05 Pierre-Alain Muller 60

10 References

► T.Gardner, C. Griffin, J. Koehler, R. Hauser, A review of OMF MOF 2.0 QVT Submissions and Recommandations towards the finalm standard, Metamodeliing for MDA, Firstr International Workshop, York, UK, November 2003. ► A. Gerber, M. Lawley, K. Raymond, J. Steel, A. Wood. Transformation: The Missing Link of MDA, In A. Corradini, H. Ehrig, H.-J. Kreowski, G. Rozenberg (Eds.): Graph Transformation: First International Conference (ICGT 2002), Barcelona, Spain, October 7-12, 2002. Proceedings. LNCS vol. 2505, Springer-Verlag, 2002, pp. 90 – 105 ► Object Management Group, The Object Constraint Language Specification 2.0, OMG Document: omg/2003-01-07 ► Object Management Group, the Model-Driven Architecture Guide, OMG Document: omg/2003-06-01 ► Object Management Group, MOF 2.0 Query / Views / Transformations RFP, OMG Document: ad/2002-04-10, revised on April 24, 2002 ► QVT-Partners. MOF Query/Views/Transformations, Revised Submission. OMG Document: ad/2003-08-08 ► Model Transformation – the Heart and Soul of Model-Driven Software Development, tech report 200352

Artist2 Summer School 05 Pierre-Alain Muller 61 Artist2 Summer School 05 Pierre-Alain Muller 62

11