6 - Architetture Software - Model transformation


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

6 - Architetture Software - Model transformation

  1. 1. Model transformations Paolo Ciancarini
  2. 2. Agenda  Modeling platforms and Platform Independence  Model Transformations  MDA in the Eclipse IDE  The Atlas Transformation Language
  3. 3. CIM, PIM and PSM  CIM: Computation Independent Model   A vocabulary of a problem domain useful to a variety of stakeholders  PIM: Platform Independent Model   A specification of a system that does not take into account technical details of a specific platform  PSM: Platform Specific Model   A specification of a system expressed in terms of the specification model of the platform
  4. 4. The MDA process (abstraction)www.ibm.com/developerworks/ibm/library/i-modev1/!
  5. 5. PIM: an Example
  6. 6. PSM: an Example
  7. 7. MDA process for a complex system
  8. 8. MDA: Mappings between Models From PIM to Specific Platform- Middleware Independent Technologies via OMG Model Standard Mappings CORBA Java/EJB XML/SOAP Other Model Model Model Model From PSM to application interfaces, code, GUI descriptors, SQL queries, etc. CORBA Java/EJB XML/SOAP Other
  9. 9. Model Representation UML Model (PIM) XMI Document Auto <Auto> <Color> Red </Color> Color : String MOF <Door> 4 </Door> Door : Integer <Engine> 2 </Engine> Engine : Integer </Auto> XMI DTD, Schema IDL, Java… <!Element Autointerface Auto (Color*, { Class Auto Door*, }; {public String color; Engine*)> public int Door; public int Engine; }
  10. 10. Model Transformation  Working with interrelated models requires to ensure their vertical, horizontal, and evolutionary consistency  This activity can be performed taking one or more source models as input and producing one or more target models as output  The process of model transformation must comply with a set of transformation rules
  11. 11. Model Transformation
  12. 12. PIM to PSM Transformation  It is used when the PIM is mapped into a platform specific infrastructure   The transformation is based on a set of platform features   These features should be described by UML
  13. 13. PIM to PIM Transformation  It is used when models are enhanced, refined or filtered during the development lifecycle without needing any platform specific information   Example: analysis-to-design model transformation
  14. 14. PSM to PSM Transformation  It is used for component realization and deployment   Generally, it is related to platform dependent model refinement
  15. 15. PSM to PIM Transformation  It is performed for abstracting models of existing technology-dependent implementations into a platform independent model   It is a refactoring process hard to be fully automated
  16. 16. Model Mapping  A technique for setting the specifications, that drives the transformation from the source model to the target model  The main mapping techniques are [8s]:   Model-Type mapping   The mapping is realized between platform-independent data types and platform- specific data types. The two kinds of data type drive the transformation   Metamodel mapping   The mapping is realized between the PIM metamodel data type and the PSM metamodel data type.   Model-Instance mapping   It uses marks, i.e. concepts of the target-model explaining how to transform source model elements
  17. 17. Model-Type Mapping
  18. 18. Metamodel Mapping
  19. 19. Model-Instance Mapping
  20. 20. Approaches to Model Transformations  The tools performing model transformations can use:   Direct transformations: internal model representation manipulated by specific APIs   Intermediate transformations: model exported in an external standard form (e.g., XMI) that can be manipulated   Transformation language: a language with specific constructs for defining and applying transformations
  21. 21. Platform Independence  Platform Independence is a “fuzzy” concept  It means independence from a specific execution and development domains  The domains from which the independence can be asserted are the usual software engineering abstraction domains:   Programming Languages   Software Architectures   Operative Systems   Data Representation
  22. 22. Ex.: Bank Account Architectural PIM•  Nothing said about thearchitecture and thedeveloping technologies•  It is the model used by bankmanager and stakeholders
  23. 23. Ex.: Bank Account Architectural PSM•  It specifies a remote and some local objects•  It adds some implementation information•  It is the model used by analyst and programmers•  it conforms to the PIM•  it can be a PIM for a further platform specific model
  24. 24. MDA Tools  Currently, there are no tools that implement MDA as envisioned by the OMG community   MDA itself is still being defined  Existing tools allow partial transformations  They are usually limited to   specific platforms   specific languages   specific transformations  Usually they are evolutions of tools born in other research fields   Especially in Generative programming and Metaprogramming
  25. 25. EMF and ATL  Two interesting technologies are emerging that are more and more used in MDA tools:1.  The Eclipse Modeling Framework (EMF) is the analogous of MOF in the Eclipse IDE Platform   It consists of an extended set of API, a metamodelling framework named Ecore and an Eclipse IDE plug-in2.  The Atlas Transformation Language (ATL) is a language specifically targeted for model transformations   It supports MOF 1.4 and Ecore while conforming to MDA transformation specifications
  26. 26. MDA and Middleware Middleware is an enabling technology for MDA Generators’ increasing complexity
  27. 27. From Coding to Modeling  What is the difference between programming language abstractions and MDE/MDA abstractions?   The former allow to abstract the solution space   they are “computing oriented”   MDE/MDA allow to abstract the problem space   they are “application domain oriented”  The current Enterprise Computing scenario requires to move the software development emphasis from coding to modeling systems
  28. 28. Metadata Integration   Why we cannot use a single language to describe all the aspects of a system?  The problem is not that we use different languages to describe different aspects of software components  The problem is that we have no overall architecture for integrating specifications made in different languages  MDA defines a single architecture for the integrated management of metadata
  29. 29. The Eclipse IDE in a Nutshell  Eclipse is an open Universal Tooling Platform   Open Source licensed via Common Public License   Managed via the Eclipse Project (www.eclipse.org)   Maintained by the Eclipse Foundation   An independent consortium whose members include: IBM, SuSe, Borland, RedHat, HP, SAP, OMG  It provides an open platform for application development tools   It runs on a wide range of operating systems   It is language-neutral   It facilitates seamless tool integration   It adds new tools to existing installed products
  30. 30. What is Eclipse?   A general purpose IDE   An open, extensible architecture based on plug-insPlug-in development environment PDE Java development tools JDT Eclipse Platform Platform Standard Java2 Virtual Machine Java VM
  31. 31. The Eclipse Architecture Another Eclipse Platform App Java Workbench Help Development Tools JFace (JDT) SWT Team Your Tool/App Plug-in Workspace Development Debug Environment (PDE) Their Platform Runtime Tool Eclipse Project
  32. 32. MDA in Eclipse  There are a number of plug-ins that support the MDA features in Eclipse  Indeed, there is not a single tool that gives a full support of MDA features as envisioned by the OMG  Three MDA plug-in categories can be identified basing on their focus: 1.  Models representation and management 2.  Models transformation 3.  Models-to-Code generation
  33. 33. Notable MDA Projects in Eclipse Name Description Categ./ License Acceleo A MDA based code generator for various target middleware 3 / Free and languages: Java EE, C#, Python, PHP etc. Atlas It defines a management environment for MDE repositories 1 / Free based on the "megamodel" approach. A megamodel is a Megamodel registry of model resources available in a given scope (a Management zone) In order to manage megamodels users may use (AM3) metamodels from a library or invent their own ones for new kinds of artifacts. Atlas Model A tool for representing correspondence between models by 1 / Free means of a model (named weaving model). CommonWeaver (AMW) weaving use cases are: data exchange, data integration, model merging, etc Atlas A model transformation language that provides 2 / Free ways to produce a set of target models from aTransformation set of source models. It also provide a toolkitLanguage (ATL) (the ATL IDE) with a number of tools aimed to ease the development of ATL transformations.
  34. 34. Notable MDA Projects in Eclipse Name Description Categ./ License Epsilon It can be used to manage models of different modeling 1/Free technologies using a family of integrated model management languages. It can be used for model navigation, modification, transformation, validation and comparison. It also provides tools for defining and executing wizard and for code profiling and monitoring. IBM Model Is a set of tools that helps to make comparisons, check 2 / IBM consistency, and implement transformations between LicenseTransformation Eclipse Modeling Framework (EMF) models. Framework Kermeta A metaprogramming environment based on an object 2 / Free oriented executable meta-modeling paradigm: a Domain Specific Language (DSL) optimized for metamodel engineering. It allows model and metamodel management, weaving and transformation.
  35. 35. Notable MDA Projects in Eclipse Name Description Categ./ LicenseopenArchitectur It is suite of tools and components supporting in 1, 3 / Free model driven software development. It is built upon a eWare modular model-to-code generator framework implemented in Java. It supports arbitrary import (model) formats, meta models, and output (code) formats It is “a tool for building MDA tools” AndroMDA AndroMDA is an extensible generator framework that 3 / Free adheres to MDA. Models from UML tools are transformed into deployable components different platforms: J2EE, Spring, .NET. It provides patterns for Axis, Struts, JSF, Spring, Hibernate and other toolkits QiQu It transforms an UML-model into source-code (Java, C#, 3 / Free Cobol etc.). It relies on XMI and allows to build a domain-specific generator that transform models into code or anything else (XML, HTML, Scripts, Excel etc.)Modeling Eclipse Plugins: http://www.eclipseplugincentral.com/Web_Links-index-req-viewcatlink-cid-11.html
  36. 36. MDA Enabling Technologies in Eclipse  There are a set of de-facto standard Eclipse plug-ins that enable MDE features  These plug-ins enable upper-standing MDA plug-ins to operate  We consider an essential subset of these plug-ins in order to start experiencing with MDA
  37. 37. MDA Plug-ins in Eclipse
  38. 38. QVT (Query View Transform)  QVT is an OMG specification  QVT extends OCL 2.0 to imperative OCL  QVT defines 3 DSL named Relations, Core and Operational Mappings  Relations and Core are declarative languages  OperationalMapping is an imperative language with constructs like loops, conditions, etc.
  39. 39. A Transformation Language: ATL  The Atlas Transformation Language (ATL) is an answer to the OMG Query View and Transformation (QVT) RFP  ATL is a QVT-like transformation language and engine with a large user community and an open source library of transformations  ATL provides the developers with a mean to specify the way to produce a number of target models from a set of source models
  40. 40. Eclipse and Modeling Plug-ins  The Eclipse Modeling Framework (EMF) is a framework and a code generation facility   It allows to define and mange models in Java, XML and UML   It relies on a meta-metamodel named Ecore  UML2 is an EMF-based implementation of the UML 2.x metamodel   It provides the support for UML model plug-ins   It defines a common XMI schema for diagram interchange
  41. 41. Eclipse and Graphical Plug-ins  The Graphical Editing Framework (GEF) allows to create a graphical editor under Eclipse   GEF provides a layout and rendering toolkit for displaying graphs, manage palettes, handle and resize graphical objects  The Graphical Modeling Framework (GMF) provides components and runtime infrastructures for developing graphical editors based on EMF and GEF   reusable components for graphical editors   generative infrastructure to graphical editor production
  42. 42. UML Modeler Plug-ins Name Description OmondoUML It is a visual modeling tool based on UML2. It supports reverse engineering and production code for EJB, Struts, Web Services. It is based on GEF and EMF. Papyrus It is an open source product to model in UML2. It allows to graphically represent diagrams in the Diagram Interchange (DI2) OMG standard. It supports Java and C++ code production and some UML profiles (e.g. SysML) Topcased It is a software engineering toolkit that provides various modelers such as UML, Ecore, SysML. It is compliant with the requirements of critical and embedded applicationsEclipse ArgoUML It integrates the ArgoUML open source tool in the Eclipse platform. It is a complete UML modeler integrated with the AndroMDA MDA plug-in.
  43. 43. The ATLAS Transformation Language  ATL is a model transformation language   Specified both as a metamodel and as a textual concrete syntax   It is both declarative and imperative   declarative style is the default choice for simple transformations   source model elements are navigated by means of a set of rules that create target model elements   It relies on a ATL Virtual Machine that allows transformations   A transformation from the ATL metamodel to the VM code enables to “execute” ATL transformations   It has been implemented as an Eclipse plug-in
  44. 44. ATL Architecture  Execution Engine   Virtual Machine   ATL to bytecode compiler  Eclipse IDE used for   Editor with syntax highlighting   ATL launch support   Source debug
  45. 45. ATL Mapping Technique   The mapping technique used by ATL is metamodel-based MMM: MOF or Ecore [13] MMt: ATL metamodel Mt: ATL transformation model MMa: source metamodel MMb: target metamodel Ma: source model Mb: target modelConforming to OMG Q/V/T specifications the transformations (Mt) aredefined as models as well conforming to the ATL metamodel (MMt)
  46. 46. ATL Transformations  ATL allows to define different types of transformations   ATL Modules: are model to model transformations   ATL Queries: are model to primitive datatype transformations   ATL Libraries: factorize the ATL code in order to be imported and used in multiple transformations  An ATL transformation file has the .atl extension
  47. 47. ATL Modules  Modules enable ATL developers to specify   the way to produce a set of target models starting from a set of source model  Modules are structured in three sections:   Header section that defines some attributes relative to the transformation   Helpers that are similar to Java methods   Rules that define the way target models are generated from source models
  48. 48. ATL Rules  There are two different types of rules   Matching Rules: for ATL declarative specifications   to define for which kind of source elements target elements must be generated   to define the way the generated target elements have to be initialized   Called Rules: for ATL imperative programming   they are a particular type of header that can generate target model elements   It has to be called from an imperative code section
  49. 49. ATL Execution Modes  ATL defines two different execution modes for its modules:   Normal execution Mode   Explicitly specifies how each target model element must be generated from source model elements   Refinement execution Mode   Source model elements are implicitly copied from the source to the target model   ATL developers focus on the generation of the modified target elements   It is limited to the transformation of a single source model to a single target model conforming to the same metamodel
  50. 50. Source Meta-model Simplified UML meta-model
  51. 51. Target Meta-modelSimplified Java meta-model
  52. 52. Transformation Rules Transformation declaration and a transformation rule:TRANSFORMATION uml2java(SOURCE UML, TARGET Java)! TRACKING TModel;! ! RULE umlClassifierToJavaClass(X, Y)! FORALL UMLClassifier X! WHERE X.name = N! MAKE JavaClass Y,! Y.name = N! LINKING X, Y BY JavaClassFromUMLClassifier;! ...!
  53. 53. Tracking RelationshipsTracking class and a transformation rule:CLASS JavaClassFromUMLClassifier {! UMLClassifier a;! JavaClass c;! KEY (a);!}!!RULE umlAttributeToJavaField! FORALL UMLAttribute X! WHERE JavaClassFromUMLClassifier LINKS X.owner, JC! MAKE JavaField Y,! Y.owner = JC! LINKING X, Y BY FieldFromAttr;!
  54. 54. Rule InheritanceRule inheritance and Superseding:CLASS JavaIntfFromUMLIntf EXTENDS JavaClassFromUMLClassifier;!!RULE umlInterfaceToJavaInterface(X, Y)! SUPERSEDES umlClassifierToJavaClass(X, Y)! FORALL UMLInterface X! MAKE JavaInterface Y,! Y.name = X.name! LINKING X, Y BY JavaIntfFromUMLIntf;!!RULE umlClassToJavaClass(X, Y)! EXTENDS umlClassifierToJavaClass(X, Y)! MAKE JavaMethod M,! M.name = X.name,! Y.constructor = M! LINKING X, M BY JavaConsFromUMLClass;!
  55. 55. ATL Syntax Essentials  Header syntaxmodule module_name;create (output_model:output_metamodel)+ [from | refines](input_model:imput_metamodel)+;  Import syntaxuses extensionless_library_file_name;  Helper syntaxhelper context context_of_definitiondef: (par_name: par_type) helper_code
  56. 56. ATL Syntax Essentials  Matching Rule rule rule_name { from source_pattern : source_metamodel!element to target_pattern : target_metamodel!element ( [targt_entity <- source_pattern.source_entity]* ) [do { imperative_code }]? }  Called Rule rule rule_name ([param_name: paramType]){ [[to target_pattern : target_metamodel!element ( targt_entity <- local_variable )]*| [do { imperative_code} ] *] ? }
  57. 57. ATL DataTypes  The ATL language is based on the OMG Object Constraint Language (OCL)   Primitive DataType   Boolean, Integer, Real, String   Collection DataType   Set, OrderedSet, Sequence, Bag as collection_type (element_datatype)   Tuple DataType   TupleType(var_name1 : var_type1, ..., var_namen : var_typen)   Map DataType   Map{(key1, value1), ..., (keyn, valuen)}   Model Element DataType   metamodel!class
  58. 58. An ATL Transformation Author Person +name : String +name : String +surname : String +surname : String The Author Source Metamodel The Person Target Metamodel  The goal is a model to model PIM to PSM transformation  name and surname attributes must be preserved  An instance of Author is mapped into an instance of Person
  59. 59. An ATL Transformationmodule Author2Person;create OUT : Person from IN : Author;rule Author {from a : Author!Authorto p : Person!Person ( name <- a.name, surname <- a.surname )}
  60. 60. ConclusionMDE is a new step of the object technology   In the 80s objects and classes were seen as "first class entities", with libraries of several hundred of classes hierarchically organized   Models and metamodels are considered first class entities now   Libraries (lattices) of hundreds of metamodels highly abstract are beginning to appear. Each metamodel may contain several hundreds of concepts and relations   Several tools can work with these libraries of models and metamodels   Research is needed to bring together theory and practice of model engineering (ontologists, methodologists, software engineers, information system designers, database specialists, etc.)
  61. 61. Self-test questions  What is a model transformation?  What is the goal of model transformations?  What is QVT?  What is ATL?
  62. 62. ReferencesBézivin: On the unification power of models. Software and System Modeling, Springer, 4:2(171-188), May 2005Frankel, Model Driven Architecture: Applying MDA to Enterprise Computing, Wiley, 2003Kurtev, Bezivin, Jouault, Valduriez, “Model-Based DSL Framework” . ACM OOPSLA, 602—616. 2006.Mellor, Scott, Uhl, Weise MDA Distilled: Principles of Model-Driven Architecture, Addison-Wesley, 2004Schmidt, Model-Driven Engineering. IEEE Computer, 39:2 (25-31), February 2006.
  63. 63. Specifications and URLs[1s] Eclipse ATL Project, http://www.eclipse.org/m2m/atl[2s] Eclipse EMF Project, http://www.eclipse.org/modeling/emf/[3s] OMG, “Common Warehouse Meta-model (CWM)”, Version 1.0, October 2001, http://www.omg.org/cgi-bin/doc?formal/01-10-01.pdf[4s] OMG, “XML Metadata Interchange (XMI) Specification v1.2”, January 2002, http://www.omg.org/cgi-bin/doc?formal/02-01-01.pdf[5s] OMG, “Meta Object Facility (MOF) Specification”, Version 1.4, OMG, April 2002, http://www.omg.org/cgi-bin/doc?formal/02-04-03.pdf[6s] OMG, “Meta Object Facility (MOF) Core Specification”, Version 2.0, January 2006, http://www.omg.org/docs/formal/06-01-01.pdf[7s] OMG, “Meta Object Facility 2.0 Query/View/Transformation Specification”, November 2005, http://www.omg.org/docs/ptc/05-11-01.pdf[8s] OMG, “MDA Guide Version 1.0.1”, June 2003, http://www.omg.org/docs/omg/03-06-01.pdf[9s] OMG, “Unified Modeling Language (UML), version 1.4”, September 2001, http://www.omg.org/cgi-bin/doc?formal/01-09-67[10s] OMG, “Unified Modeling Language: Infrastucture”, version 2.2.1, February 2007, http://www.omg.org/docs/formal/07-02-04.pdf[11s] Sun, “Java Metadata Interface (JMI) API 1.0 Specification”, http://jcp.org/aboutJava/communityprocess/final/jsr040/index.html
  64. 64. Questions?