© 2005-2006 the athena consortium. ap6 – model-driven development of interoperable web services,...

44
© 2005-2006 The ATHENA Consortium. AP6 – Model- Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations from PIM4SOA to Web services, agents and P2P software solutions.

Upload: herbert-griffith

Post on 13-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

© 2005-2006 The ATHENA Consortium.

AP6 – Model-Driven Development of

Interoperable Web Services, Agents and

P2P Solutions

Learn about model transformations from PIM4SOA to Web services, agents and P2P software solutions.

Page 2: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

2© 2005-2006 The ATHENA Consortium.

Course description

• A PIM4SOA model is a basis for model transformation and code generation.

• The course teaches how to refine a PIM4SOA into specific system realisations such as Web services (XSD, WSDL and BPEL), agents and P2P solutions using for example the transformation tools developed in ATHENA.

• However, an important part of the training is to understand the use of model transformation and be able to develop your own model transformations according to your integration needs.

Page 3: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

3© 2005-2006 The ATHENA Consortium.

Course objective

• This course aims to be a method engineering course that will teach the students how to develop their model transformations to support their own model-driven development methodologies.

• This is shown using examples from PIM4SOA, Web services, agents and P2P.

• Participants will gain an understanding of the use of model transformations in a software engineering development and integration process.

Page 4: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

4© 2005-2006 The ATHENA Consortium.

MDI training trackNo Topic Presenter

A

P

4

4-1 Interoperability & Model-Driven Architecture (MDA) <Person>, <Company>, <Country>

A

P

5

5-1 ATHENA Model-Driven Interoperability (MDI) Framework <Person>, <Company>, <Country>

5-2 Metamodelling• Eclipse Modeling Framework (EMF) Tutorial / Exercise

<Person>, <Company>, <Country>

5-3 UML Profiles and Domain-Specific Languages (DSLs)• Eclipse Graphical Modeling Framework (GMF) Tutorial / Exercise

<Person>, <Company>, <Country>

5-4 Method Engineering• Eclipse Process Framework (EPF) Tutorial / Exercise

<Person>, <Company>, <Country>

A

P

6

5-1 Model Mappings and Transformations• ATL Tutorial (optional)• MOFScript Tutorial (optional)

<Person>, <Company>, <Country>

5-2 Model-Driven Development with PIM4SOA <Person>, <Company>, <Country>

5-3 From PIM4SOA to Web Services• PIM4SOA to XSD ATL Tutorial / Exercise

<Person>, <Company>, <Country>

5-4 From PIM4SOA to Agents <Person>, <Company>, <Country>

5-5 From PIM4SOA to Peer-2-Peer (P2P) <Person>, <Company>, <Country>

Page 5: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

5© 2005-2006 The ATHENA Consortium.

MDI website

http://www.modelbased.net/mdi

Page 6: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

© 2005-2006 The ATHENA Consortium.

6-1. Model Mappings and

Transformations

<Presenter>

<Company>, <Country>

<E-mail>

Page 7: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

7© 2005-2006 The ATHENA Consortium.

ATHENA Model-Driven Interoperability (MDI) Framework

MDA & Interoperability

Metamodelling

UML Profiles & DSLs

Model Transformations

Method Engineering

Reusable MDI Assets

• Method chunks• Tools and services

• Models and metamodels• Model transformations• DSLs and UML profiles

• Reference examples

Page 8: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

8© 2005-2006 The ATHENA Consortium.

Outline

• Foundations of model mappings and transformations

• Model transformation technologies and examples• References

Page 9: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

9© 2005-2006 The ATHENA Consortium.

Foundations of model mappings and transformations

Page 10: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

10© 2005-2006 The ATHENA Consortium.

About MOF

• MOF is short for Meta-Object Facility• OMG standard• MOF is constructed to store and manage

metamodels and model instances of these.• One can view MOF as a generic storage which

lets you define a (meta)model of what to store, and MOF will manage storage of data according to this (meta)model.

• Is now used in various UML tools.• MOF support for Java in the form of JMI (Java

Metadata Interface)

Page 11: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

11© 2005-2006 The ATHENA Consortium.

MOF usage

• Core technology for flexible model repositories– A commonly used term for denoting a structured

storage for information of various kinds.

• Define new metamodels in a standardized way.• Base technology for different modelling tools

(UML).

Page 12: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

12© 2005-2006 The ATHENA Consortium.

Model mapping (1/2)

• Mapping is performed by defining relations between two models

• The relations can be – 1-to-1, n-to-1, 1-to-n or n-to-n

• Mapping is performed in “design time”

Page 13: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

13© 2005-2006 The ATHENA Consortium.

Model mapping (2/2)

• The mapping is defined with models one meta-level higher than the input and output of the transformation.

• The mapping is used to perform transformation of instances of the mapped models.

• “The mapping describes the rules used for the transformation”.

Page 14: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

14© 2005-2006 The ATHENA Consortium.

Mapping and transformation

SourceMetamodel

Input Model

OutputModel

TargetMetamodel

Mapping

Transformation

<<InstanceOf>> <<InstanceOf>>

based on

Page 15: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

15© 2005-2006 The ATHENA Consortium.

Different mappings

PSM1metamodel

PSM2metamodel

PIM2metamodel

PIM1metamodel

HorizontalMapping

HorizontalMapping

Vertical Mapping Vertical Mapping

HighAbstraction

LowAbstraction

Page 16: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

16© 2005-2006 The ATHENA Consortium.

Transformations

• Takes input and produces output– One-way process

• Transforms according to a predefined mapping• Transformation is used in “run time”• Two main categories of transformation

– Vertical transformation– Horizontal transformation

Page 17: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

17© 2005-2006 The ATHENA Consortium.

Horizontal transformation

• Source model has the same level of abstraction as target model– Not to be confused with “meta-levels”

• Examples of horizontal transformation– Refactoring – Merging

Page 18: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

18© 2005-2006 The ATHENA Consortium.

Vertical transformation

• Source model is at a different level of abstraction than the target model

• Examples of vertical transformation– Refinement (specialization)

• PIMPSM transformations

– Abstraction (generalization)

Page 19: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

19© 2005-2006 The ATHENA Consortium.

MOF QVT (Query/View/Transformation)

• High-level– Definition of query/view/transformation language for

MOF– Important part of realizing the OMG MDA vision

• Part of the MOF 2.0 specification work in OMG– MOF 2.0 Facility / Object Lifecycle RFP– MOF 2.0 IDL RFP MOF 2.0 Versioning RFP– MOF 2.0 Query / View / Transformation RFP– MOF 2.0 Core

• We focus on the transformation part– But we will need both the Q and the V for it to work

Page 20: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

20© 2005-2006 The ATHENA Consortium.

Involved partners

• Codagen• Compuware• DSTC• France Telecom• IBM• INRIA• Interactive Objects• Kings College London• Softteam

• Sun Microsystems• Tata Consultancy

Services• Thales• TNI-Valiosys• University of Paris VI• University of York

Page 21: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

21© 2005-2006 The ATHENA Consortium.

QVT - Query/View/Transformation

• Queries are performed on input models for finding specific elements or information– Example: Return all classes

• Views are models derived from other models– The result of a query is a kind of view

• Transformations takes a model as input and creates a new model– Example: PIM PSM– Defined in Relations language or Core language– Uses Queries and Views

Page 22: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

22© 2005-2006 The ATHENA Consortium.

How to define a transformation?

• The abstract syntax must be defined as a metamodel in MOF

• Concrete syntax expressed as text (program code) or models

• Variations– Declarative– Imperative

Page 23: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

23© 2005-2006 The ATHENA Consortium.

QVT overview

Core

Relations

BlackBox

OperationalMappings

RelationsToCoreTransformation

Page 24: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

24© 2005-2006 The ATHENA Consortium.

QVT overview – Declarative part

• Relations– Declarative specification of the mapping between MOF

models– Equivalent with Java code (high-level)

• Relations to Core transformation– Equivalent with compiling Java code into byte code

• Core– Equivalent with Java byte code (low-level)

Page 25: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

25© 2005-2006 The ATHENA Consortium.

QVT overview – Imperative part

• Operational mappings– Standard language for defining Relations (or Core) in

an imperative way

• Black box– Offers the possibility to plug-in code from any

programming language with a MOF binding

Page 26: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

26© 2005-2006 The ATHENA Consortium.

QVT in practice – most transformation

• Given a defined metamodel for source and target– Metamodels must be well-defined according to MOF

(models on level M2)

• One can define transformations between these two worlds in a general, standardized manner– The transformation can be used on all instances of the

source metamodel– The result will be an instance of the target metamodel

Page 27: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

27© 2005-2006 The ATHENA Consortium.

Model transformation technologies and examples

Page 28: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

28© 2005-2006 The ATHENA Consortium.

Technology overview

• Multiple technologies for mapping and transformation– Java– IBM Model Transformation Framework (MTF)– Atlas Transformation Language (ATL)

• Not many QVT-based ones– QVT support in Borland Together Architect 2006

Page 29: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

29© 2005-2006 The ATHENA Consortium.

Java

• Technologies such as MDR and EMF allow for generation of Java API toward arbitrary metamodels

• Using these APIs mappings can be defined in a Java program

• The transformation is performed by running the Java program on a model instance given as input

• Drawback– API generation for metamodels needed

• Pros– Well known language for mapping definition

Page 30: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

30© 2005-2006 The ATHENA Consortium.

IBM MTF

• MTF was developed in order to experiment with QVT related concepts

• MTF is not QVT compliant• MTF rules describe the relationships between the

input and the output metamodel• Provides functionality to define mappings

between metamodels• And execute the model transformations

Page 31: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

31© 2005-2006 The ATHENA Consortium.

ATL

• The Atlas Transformation Language (ATL) is a hybrid language (a mix of declarative and imperative constructions) designed to express model transformations as described by the MDA approach.

• It is not QVT, but similar and with the corresponding functionality

• A transformation model in ATL is expressed as a set of transformation rules.

• The recommended style of programming is declarative.• OCL is used to expression constraints on rules

– Guards (constraints) on the entry point for a rule• Different kinds of M3/M2 (meta)metamodel technology

supported: Netbeans MDR and EMF Ecore– Can use either EMF or MDR metamodels as input and output.

• Can also be used to produce textual output.

Page 32: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

32© 2005-2006 The ATHENA Consortium.

Example: UML RDBMS

PrimitiveDataType

Classifier

Attribute

visibility : String

Association

PackageModelElement

name : Stringkind : String **+ownedElement

Class*

1

+attribute

*1

*

1

+forward

*

+source

1

*

1

+reverse

*

+destination

1

**

+derived*

+super *

TypedElement1

*+type1

+typed

*

Operation

visibility : String*

1

+operation

*

1

Parameter

kind : String*

1

+parameter

*

1

Parts of UMLmetamodel

Page 33: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

33© 2005-2006 The ATHENA Consortium.

Example: UML RDBMS

ForeignKey Table

10..1+owner

1

+foreignKey

0..1

Column

type : String

*

1

+column*

+owner1

*

*

+column *

+foreignKey*

Key

1*+refersTo

1

+referredBy

*

1 1

+owner

1

+key

1

*

*

+column*

+belongsTo

*

ForeignKey Column Table Key

ModelElement

name : Stringkind : String

Simple RDBMS metamodel

Page 34: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

34© 2005-2006 The ATHENA Consortium.

Example: Informal rules

• A persistent class maps to a table, a primary key and an identifying column.

• Attributes of the persistent class map to columns of the table: an attribute of a primitive datatype maps to a single column; an attribute of a complex data type maps to a set of columns corresponding to its exploded set of primitive datatype attributes; attributes inherited from the class hierarchy are also mapped to the columns of the table.

• An association between two persistent classes maps to a foreign key relationship between the corresponding tables.

Page 35: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

35© 2005-2006 The ATHENA Consortium.

Example: Java transformation (1/2)

public Model model2model(org.eclipse.uml2.Model inModel){Model retval = RdbmsFactory.eINSTANCE.createModel();Iterator it = inModel.getOwnedElements().iterator();while (it.hasNext()){

Object element = it.next();if(element instanceof Class){

Class toProcess = (Class)element;retval.getElements().add(class2table(toProcess));

}}return retval;

}

public Table class2table(Class inClass){Table retval = RdbmsFactory.eINSTANCE.createTable();retval.setName(inClass.getName());Iterator it = inClass.getOwnedAttributes().iterator();while (it.hasNext()){

Object attrib = it.next();if(attrib instanceof Property){

Property toProcess = (Property)attrib;retval.getColumns().add(attrib2column(toProcess));

}}return retval;

}

Page 36: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

36© 2005-2006 The ATHENA Consortium.

Example: Java transformation (2/2)

public Column attrib2column(Property inAttr){Column retval = RdbmsFactory.eINSTANCE.createColumn();retval.setName(inAttr.getName());retval.setType(inAttr.getType().getName());return retval;

}

• It is all about traversing the model tree– And building an output model

Page 37: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

37© 2005-2006 The ATHENA Consortium.

Example: MTF transformation

/* UML Packages map to EPackages */relate umlpkg2ecore( uml:Package pkg, ecore:EPackage epkg) when equals(pkg.name, epkg.name){

// map sub-packagesumlpkg2ecore( over pkg.ownedMember, over epkg.eSubpackages),

// map classifiersumlclassifier2ecore( over pkg.ownedMember, over epkg.eClassifiers )

}

/* UML Classifiers map to EClassifiers */abstract relate umlclassifier2ecore( uml:Classifier class,

ecore:EClassifier eclass) when equals(class.name, eclass.name)

/* Map UML Class to EClass */relate umlclass2ecore extends umlclassifier2ecore( uml:Class class,

ecore:EClass eclass){

// check that super classes map to each other check umlclass2ecore(over class.superClass, over eclass.eSuperTypes)}

Page 38: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

38© 2005-2006 The ATHENA Consortium.

Example: ATL transformation (1/2)

module uml2rdbms; -- Module Templatecreate OUT : rdbms from IN : uml2;

rule model{from inMod:uml2!Modelto modi:rdbms!Model(

elements <-inMod.ownedMember)

}

rule class2table{from cl:uml2!Class (cl.oclIsTypeOf(uml2!Class))to tbl:rdbms!Table( name <- cl.name, columns <- cl.ownedAttribute)

}

Page 39: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

39© 2005-2006 The ATHENA Consortium.

Example: ATL transformation (2/2)

rule attr2col{ from attr:uml2!Property

to col:rdbms!Column(

name <- attr.name, type <-attr.type.name )}

• Compared to Java ATL provides simpler mechanisms for model traversal

Page 40: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

40© 2005-2006 The ATHENA Consortium.

Example: QVT graphical notation

A persistent class maps to a table, a primary key and an identifying column

c:Class t:Table

name=cnkind=‘Persistent’

name=cn

C E

uml rdbms

p:Package S:Schema

cl:Column

name=cn+’_tid’type=‘NUMBER’

k:Key

name=cn+’_pk’

where

when

PackageToSchema(p,s)

AttributeToColumn(c,t,’’)

Page 41: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

41© 2005-2006 The ATHENA Consortium.

Example: QVT textual notation

top relation ClassToTable {cn, prefix: String; checkonly domain uml c:Class {namespace=p:Package {},

kind='Persistent', name=cn}; enforce domain rdbms t:Table {schema=s:Schema {},name=cn,

column=cl:Column {name=cn+'_tid', type='NUMBER'},key=k:Key {name=cn+'_pk', column=cl}};

when { PackageToSchema(p, s);

} where { prefix = ''; AttributeToColumn(c, t, prefix);

}}

A persistent class maps to a table, a primary key and an identifying column

Page 42: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

42© 2005-2006 The ATHENA Consortium.

References

Page 43: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

43© 2005-2006 The ATHENA Consortium.

References

• OMG, "Meta Object Facility (MOF) 2.0 Query/View/Transformation Specification", Object Management Group (OMG), Document ptc/05-11-01, November 2005. http://www.omg.org/docs/ptc/05-11-01.pdf

• INRIA, "ATL - The Atlas Transformation Language Home Page". http://www.sciences.univ-nantes.fr/lina/atl/

• Eclipse.org, "ATL Home page". http://www.eclipse.org/gmt/atl/• IBM, "Model Transformation Framework". http://www.alphaworks.ibm.com/tech/mtf/• IBM, "Model Transformation with the IBM Model Transformation Framework".

http://www-128.ibm.com/developerworks/rational/library/05/503_sebas/

Page 44: © 2005-2006 The ATHENA Consortium. AP6 – Model-Driven Development of Interoperable Web Services, Agents and P2P Solutions Learn about model transformations

44© 2005-2006 The ATHENA Consortium.

This course has been developed under the funding of the EC with the support of the EC ATHENA-IP Project.

Disclaimer and Copyright Notice: Permission is granted without fee for personal or educational (non-profit) use, previous notification is needed. For notification purposes, please, address to the ATHENA Training Programme Chair at [email protected]. In other cases please, contact at the same e-mail address for use conditions. Some of the figures presented in this course are freely inspired by others reported in referenced works/sources. For such figures copyright and all rights therein are maintained by the original authors or by other copyright holders. It is understood that all persons copying these figures will adhere to the terms and constraints invoked by each copyright holder.