Upload
majong-devjfu
View
3.563
Download
0
Embed Size (px)
Citation preview
Model transformations
Paolo Ciancarini
Agenda
Modeling platforms and Platform Independence Model Transformations MDA in the Eclipse IDE The Atlas Transformation Language
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
The MDA process (abstraction)
www.ibm.com/developerworks/ibm/library/i-modev1/!
PIM: an Example
PSM: an Example
MDA process for a complex system
MDA: Mappings between Models
Platform- Independent
Model
CORBA Model
Java/EJB Model
CORBA
XML/SOAP Model
Java/EJB XML/SOAP Other
Other Model
From PSM to application interfaces, code, GUI descriptors,
SQL queries, etc.
From PIM to Specific Middleware
Technologies via OMG Standard Mappings
Model Representation
UML Model (PIM) Auto
Color : StringDoor : IntegerEngine : Integer
<!Element Auto (Color*, Door*, Engine*)>
XMI DTD, Schema interface Auto { };
IDL, Java…
Class Auto {public String color; public int Door; public int Engine; }
<Auto> <Color> Red </Color> <Door> 4 </Door> <Engine> 2 </Engine> </Auto>
XMI Document
MOF
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
Model Transformation
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
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
PSM to PSM Transformation
It is used for component realization and deployment Generally, it is related to platform
dependent model refinement
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
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
Model-Type Mapping
Metamodel Mapping
Model-Instance Mapping
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
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
Ex.: Bank Account Architectural PIM
• Nothing said about the architecture and the developing technologies • It is the model used by bank manager and stakeholders
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
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
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-in 2. 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
MDA and Middleware
Generators’ increasing complexity
Middleware is an enabling technology for MDA
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
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
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
What is Eclipse?
Java VM Standard Java2 Virtual Machine
Platform Eclipse Platform
Java development tools JDT
PDE Plug-in development environment
A general purpose IDE An open, extensible architecture based on plug-ins
Platform Runtime
Workspace
Help
Team
Workbench
JFace
SWT
Eclipse Project
Java Development
Tools (JDT)
Their Tool
Your Tool/App
Another App
The Eclipse Architecture
Plug-in Development Environment
(PDE)
Eclipse Platform
Debug
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
Notable MDA Projects in Eclipse Name Description Categ./
License Acceleo
A MDA based code generator for various target middleware and languages: Java EE, C#, Python, PHP etc.
3 / Free
Atlas Megamodel
Management (AM3)
It defines a management environment for MDE repositories based on the "megamodel" approach. A megamodel is a registry of model resources available in a given scope (a zone) In order to manage megamodels users may use metamodels from a library or invent their own ones for new kinds of artifacts.
1 / Free
Atlas Model Weaver (AMW)
A tool for representing correspondence between models by means of a model (named weaving model). Common weaving use cases are: data exchange, data integration, model merging, etc
1 / Free
Atlas Transformation Language (ATL)
A model transformation language that provides ways to produce a set of target models from a set of source models. It also provide a toolkit (the ATL IDE) with a number of tools aimed to ease the development of ATL transformations.
2 / Free
Notable MDA Projects in Eclipse
Name Description Categ./ License
Epsilon
It can be used to manage models of different modeling 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.
1/Free
IBM Model Transformation
Framework
Is a set of tools that helps to make comparisons, check consistency, and implement transformations between Eclipse Modeling Framework (EMF) models.
2 / IBM License
Kermeta A metaprogramming environment based on an object oriented executable meta-modeling paradigm: a Domain Specific Language (DSL) optimized for metamodel engineering. It allows model and metamodel management, weaving and transformation.
2 / Free
Notable MDA Projects in Eclipse
Name Description Categ./ License
openArchitectureWare
It is suite of tools and components supporting in model driven software development. It is built upon a 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”
1, 3 / Free
AndroMDA AndroMDA is an extensible generator framework that 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
3 / Free
QiQu It transforms an UML-model into source-code (Java, C#, 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.)
3 / Free
Modeling Eclipse Plugins: http://www.eclipseplugincentral.com/Web_Links-index-req-viewcatlink-cid-11.html
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
MDA Plug-ins in Eclipse
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.
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
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
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
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 applications
Eclipse 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.
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
ATL Architecture Execution Engine
Virtual Machine ATL to bytecode compiler
Eclipse IDE used for Editor with syntax highlighting ATL launch support Source debug
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 model
Conforming to OMG Q/V/T specifications the transformations (Mt) are defined as models as well conforming to the ATL metamodel (MMt)
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
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
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
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
Source Meta-model
Simplified UML meta-model
Target Meta-model
Simplified Java meta-model
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;! ...!
Tracking Relationships Tracking 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;!
Rule Inheritance Rule 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;!
ATL Syntax Essentials
Header syntax
Import syntax
Helper syntax
module module_name; create (output_model:output_metamodel)+ [from | refines] (input_model:imput_metamodel)+;
uses extensionless_library_file_name;
helper context context_of_definition def: (par_name: par_type) helper_code
ATL Syntax Essentials
Matching Rule
Called 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 }]? }
rule rule_name ([param_name: paramType]){ [[to target_pattern : target_metamodel!element ( targt_entity <- local_variable )]*| [do { imperative_code} ] *] ?
}
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
An ATL Transformation
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
Author +name : String +surname : String
Person +name : String +surname : String
An ATL Transformation
module Author2Person;
create OUT : Person from IN : Author;
rule Author { from a : Author!Author
to p : Person!Person ( name <- a.name, surname <- a.surname )
}
Conclusion
MDE is a new step of the object technology In the 80's 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.)
Self-test questions
What is a model transformation? What is the goal of model
transformations? What is QVT? What is ATL?
References
Bézivin: On the unification power of models. Software and System Modeling, Springer, 4:2(171-188), May 2005
Frankel, Model Driven Architecture: Applying MDA to Enterprise Computing, Wiley, 2003
Kurtev, 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, 2004
Schmidt, Model-Driven Engineering. IEEE Computer, 39:2(25-31), February 2006.
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
Questions?