Model Transformation with a dedicated impertive language

caddiepastData Management

Jan 31, 2013 (4 years and 9 months ago)

281 views

Model transformation with a
dedicated OO language

Triskell team

IRISA Rennes (France)

www.irisa.fr/triskell

From contemplative to productive

+Applicant()
+ApplicantInfo()
+MakeApplication()
-companyName : CString
-experience : CString
-reference1 : CString
-reference2 : CString
-reference3 : CString
Applicant
+Person()
+PersonInfo()
-personID : unsigned long
-surname : CString
-givenName : CString
-middleInitial : char
-streetAddress : CString
-postCode : CString
-countryname : CString
-eMailAddress : CString
Person
-is taught by
1
-teaches
0..*
+CourseSession()
+CourseSessionInfo()
-courseSessionID : unsigned long
-courseDate : unsigned long
-courseID : unsigned long
-courseLocation : CString
CourseSession
+AppStatus()
+AppStatusInfo()
-statusCode : char
-statusName : CString
AppStatus
+CourseRegistration()
+CourseRegistrationInfo()
-registrationDate : unsigned long
-completionFlag : bool
-confirmedDate : unsigned long
CourseRegistration
+Test()
+TestInfo()
-testScore : unsigned long
Test
+Application()
+ApplicationInfo()
-productNr : unsigned long
-certificationLevel : unsigned long
-applicationDate : unsigned long
Application
+PermittedStatusChange()
+StatusChangeInfo()
-fromStatus : char
-toStatus : char
PermittedStatusChange
+ExamSession()
+ExamSessionInfo()
-examSession : unsigned long
-examlocation : CString
-examDate : unsigned long
ExamSession
-gives
0..*
-is achieved
1
-is made by
1
-makes
0..*
-allows change in
0..*
-has a
1..*
-is taken by
1
-takes
0..*
-is made by a
1
-made a
1..*
-is in
1
-is filled by
0..*
-uses
1
-is used in
0..*
-applies to a
0..*
-is for a
1
+Exam()
+ExamInfo()
-examID : unsigned long
-certificationLevel : unsigned long
Exam
+Employee()
+GetCurrentAge()
+EmployeeInfo()
-jobType : CString
-roomNr : unsigned long
-department : CString
-division : CString
-jobTitle : CString
-manager : unsigned long
-headsDept : CString
-headsDivision : CString
-mobileNr : CString
-birthDate : unsigned long
Employee
+registrationform()
RegistrationForm
-uses
*
*
Applicant
ApplicantList
PersonList
findApplicant()
Application
RegForm
Applicant()
findPerson()
addPerson()
addApplication()
Application()
MakeApplication()
ApplicationList
"from human
-
readable ……………………to computer
-
understandable"


a UML model
used to be
either


fancy pictures to decorate your room


a graphical syntax for C++/Java/C#/Eiffel...

The OMG 4 layers architecture

What we want

to transform

The OMG Vision: Mappings to
multiple and evolving platforms

COM+

DCOM

CORBA

C#

.Net

XML

SOAP

Java

EJB

HTTP

HTM
L


MOF
& UML as the
core


Organization assets
expressed as
models


Model
transformations to
map to technology
specific platforms

Platform neutral models based

on UML & MOF

How to go From PIM to PSM?


"just" weave the platform aspect !


How can I do that?


Through Model transformations








Model a

Model b

Metamodel B

instanceOf

Metamodel A

instanceOf

Definition of

transformation T: A
-
>B

An application of

transformation T(a) = b

instanceOf

Model transformation: from a source
model…

Command pattern

receiver

invoker



Instantiate command design pattern.



Implement persistency that stores the
command string to a given database.

…to a target model...

Persitency implementation

Command pattern implementation

How To: Automatic Model
Transformations

In some domains (e.g.; RT systems)

transformations can get more complex

than initial model!

=> Many organizations already have
accumulated huge piles of LOC of
transformations

Why complex transformations?


Example: Air Traffic Management


“business model” quite stable & not that complex


Various modeling languages used beyond UML


Deliver software for (many) variants of a platform


Reuse technical solutions across large product lines
(e.g. fault tolerance, security…)


Customize generic transformations


Compose reusable transformations


Evolve & maintain transformations for 15+ years!

Transformations are Assets

=> apply sound SE principles


Must be Modeled


with the UML, using the power of OO


Must be Designed


Design by Contract, using OCL


Must be Implemented


Made available through libraries of components, frameworks…


Must be Tested


test cases

»
input: a UML Model

»
output: a UML Model, + contract checking


Must be Evolved


Items of Configuration Management

The 3 ages of Transformations


Awk
-
like (inc.
sed, perl
…)




XSLT


W3C standard for transforming XML


Operates on tree structures


syntactical & inefficient


QVT
-
like


Now hot topic at OMG with RFP Q/V/T

»
Query/View/Transformation


Operates on graphs

BEGIN

{action)

pattern

#
1

{action

#
1
}



pattern

#n

{action

#n}

END

{action)

SE Limit: ~100 LOC

SE Limit: ~1000 LOC

SE Limit: ?

Standard?

Which/When?

Reflective MDE


How to express transformations independently from
a specific CASE tool?


Unacceptable risk to tie transformation assets to a
specific CASE tool + multiple tools among BUs anyway


The CASE tool is the platform for executing the
transformations


Apply MDA to transformations!


Platform Independent Transformation (PIT)

»
Expressed as a model


Platform Specific Transformation (PST)

»
Transformations to go from PIT to PST

Model the
Model
-
Transformations


with the UML


Class diagrams


A transformation rule is expressed as an operation

»
OCL for pre/post + navigation


A set of rules is a class (module+information hiding)


Variability builds on subclassing and dynamic binding
+DPs


Model management diagrams


Packages, components => reusable assets


Activity diagrams


Dependencies between subtasks


Deployment diagrams

Patterns of transformation

Platform

Description

Etc. …

MDA Guide, OMG

UML/OCL2

Meta
-
Programs

UML Model

UML Model

XML

XML

Java/Eiffel/C#

AST

Java/Eiffel/C#

Source Code

XSLT

Java/C#/etc.

executable

GUI

XMI

Parser

XMI

Generator

Interpreter

Compilers

Compiler

XMI

Generator

XMI

Parser

Tooling issues

MTL architecture

Read Write
models

Read only
models

Transfor
-
mation
model

MTL CASE

(Eclipse)

MTL Engine

Dedicated CASE

Tools

MTL Positioning

MTL engine

Repositories

Transformation


In OMG
-
QVT

Libraries

Framework

Transformation


In MTL

Interpreter/Compiler

OMG
-
QVT 2 MTL

In MTL

Transformation tools: requirements


Depends only on metamodels

(not on models)

=>


Manipulates models


Of any kind of metamodel


In any kind of repository


Transformation tools: requirements


Transformation must be composable

=>


Re
-
usable libraries of transformations


Interoperability


Can call other (transformation ?) tools

»
Native libraries


Can be called by other

(transformation ?) tools

Transformation tools: requirements


Can represent generic tasks, not depending on the
level of abstraction


Must be adaptable to slightly different problems

=>


OO genericity (multiple inheritance)


For classes


For libraries


Concept of view manipulation


Views are virtual models whose metamodel is described
by a MTL Library

Transformation tools: requirements


Must be maintainable

=>


Programming language with well
-
known concepts


Easy to learn


Existing maintenance solutions


Independency from the model repositories

From the programmer point of view
(1/2)


Typed language


Static typing for MTL


Implicit typing for model elements


Object
-
oriented language


Based on the OMG UML class diagrams

»
Packages

»
Classes

»
Associations (N
-
ary, class
-
associations, qualifiers…)

»
Visibility

»
Exception mechanism

»



Methods (behaviors) in imperative style

From the programmer point of view
(2/2)


Integrated model manipulation


MTL object and model elements are manipulated the same way


No constraint on the number of manipulated models


An abstract language


Based on MOF + OCL MM (+ QVT ?)


Many compatible concrete syntax may be defined

»
Full textual

»
Structure in UML class diagrams + methods in text

»
Structure in UML class diagrams + methods in an adapted activity graphs


Allows transformations of transformations

»
Adapt a transformation to a specific platform

Adding known techniques and specific
innovating solution

«

Old

» well
-
known
techniques

The MTL
specificity

MTL =


OCL


One of the best solution for model manipulation


Standard library


+ Side effects


Model modification


MTL objects modification


+ Structuration


UML class diagrams



+ MTL Libraries are “templated”


Models to be manipulated


found at runtime


Views as MTL “abstract” libraries


for generic manipulations

Independency from repository tools


Model manipulation implies model repositories !


Many of them are already available, with different techniques and
standards

»
OMG MDA / JMI
(Novosoft, CIM, MDR, EMF, Univers@lis,…)

»
UML CASE
(Rose, Objecteering, UMLAUT, Poseidon,…)

»
Object
-
Oriented Databases / OQL
(Poet, Jasmine,…)

»
Relational databases
(PostgreSQL, Oracle,…)

»
Distributed systems
(CORBA, EJB, .net,…)

»



Many others in the future


MTL engine must not depend on repository technology !

BasicMTL


Offers main characteristics of MTL


Strongly typed for itself, layzy typed for models


Object oriented (libraries, classes, attributes and operations, multi
inheritance for classes and libraries)


Model manipulation (repository access)

»
Transparent access to models : model elements are
manipulated in the same way as BasicMTL objects.


Action language independent from the platform


Predefined types and operations inspired from OCL


Views


Adapter mechanism


Exceptions


Connection from/to java


Partial Eclipse integration

Connection to a repository

model UMLrep : RepositoryModel;

model mdrdriver : MDRDriver;

main() : Standard::Void

{


// we initialize the MDR driver



mdrdriver := new MDRDriver::MDRModelManager();


mdrdriver.init();


// instanciate the model


UMLrep := mdrdriver.getModelFromXMI (


'metamodelFilename',


'UML', // name of the root package in the Uml1.4 metamodel


'UML1.4_model',


'inputModelFilename', 'outputModelFilename');


aTransformation := new PrivatizeAttributeTransformation();


aTransformation.run(UMLrep);


'That s all folks !'.toOut();

}



Basic operations


Set of primitive graph transform operators specified
with pre/post
à la

Action Semantics


Create, find or delete an instance of

»
a class (found with its qualified name)

»
an association (found either with its qualified name or its
association ends)



Field access (found with its name)

»
attributes, references, operation


if supported !

»
attribute modification


Optional parts (may be not supported


PST = Platform
Specific Transformation!):
qualified links, reflection, dedicated
methods…

Creation and Deletion


newOperation : UMLrep::Core::Operation;


// we create the new operation in repository


newOperation :=
new

UMLrep::Core::Operation ();


// an Exception is raised if Operation is unknown



// we delete the operation from repository


newOperation
.delete
();

Operation

name:String


Suppose the meta
-
model describing
what is in UMLrep contains the class
«

operation

»

Field access: read & write


anOperation : UMLrep::Core::Operation;



// we get the name of the operation and output it


anOperation.name.toOut();


// an Exception is raised if name is unknown


// in Operation



// we set the name of the operation



newOperation.name := ‘fancyNewName’ ;

Operation

name:String

Creating Associations

theFeature : UMLrep::Core::Feature;

theClassifier : UMLrep::Core::Classifier


// we put the feature into the classifier


associate (


feature := theFeature : UMLrep::Core::Feature,


owner := theClassifier : UMLrep::Core::Classifier


);


Feature

Classifier

* Feature owner 0..1

Deleting Associations

theFeature : UMLrep::Core::Feature;

theClassifier : UMLrep::Core::Classifier


// we put the feature into the classifier


dissociate (


feature := theFeature : UMLrep::Core::Feature,


owner := theClassifier : UMLrep::Core::Classifier


);


Feature

Classifier

* Feature owner 0..1

Meta
-
level operations


allInstances() called on a class of the meta
-
model,
e.g. Attribute:

attributeIterator : Standard::Iterator;



attributeIterator :=


!UMLRep::Core::Attribute!.allInstances().getNewIterator();

Control structures


Conditional


if
cond

{
thenpart
} else {
elsepart
}


Loop


while
cond

{
loopbody
}


Exception handling


As in Java

Iterations and iterators

attributeIterator.start();

while attributeIterator.isOn()


{


anAttribute := attributeIterator.item().oclAsType (




!source_model::Core::Attribute!);


anAttribute.name.toOut();


attributeIterator.next();


}


Encapsulation of transformations

using OO


Declaring methods and functions


Pre & Postconditions


Calling methods


Defining classes


Defining associations


Inheritance and dynamic binding


Grouping classes into models

Declaring methods

addFeatureToClassifier (


theFeature : UML::Core::Feature;


theClassifier : UML::Core::Classifier)

{

// we put the feature into the classifier


associate (


feature := theFeature : UML::Core::Feature,


owner := theClassifier : UML::Core::Classifier


);

}


Declaring functions

createMethod (


theLanguage : Standard::String;


theBody : Standard::String

) : UML::Core::Method

{


newMethod : UML::Core::Method;



newMethod := new UML::Core::Method();


newMethod.body := new UML::Data_Types::ProcedureExpression();


newMethod.body.body := theBody;


newMethod.body.language := theLanguage;




return

newMethod;

}


Calling methods

createAndLinkMethod (theLanguage: Standard::String; theBody:Standard::String;


specification : UML::Core::Operation) : UML::Core::Method

{


newMethod : UML::Core::Method;


owner : UML::Core::Classifier;



// we create a new method


newMethod :=
createMethod

(theLanguage, theBody);


// we retrieve the owner of the specification


owner := specification.owner;


// we add the method to the classifier


addFeatureToClassifier

(newMethod, owner);




// we associate the method with the operation


associate (specification := specification : UML::Core::Operation,


method := newMethod : UML::Core::Method);


return newMethod;
// we return the result

}


Defining classes

class PrivatizeAttributeTransformation

{


// Attribute definitions


UML : RepositoryModel;


// Method definition As in Java


run (UMLRep : RepositoryModel) {


// code of run, setting UML among others



}


Attribute_Process (theAttribute : source_model::Core::Attribute){}


Attribute_Privatize (theClass : source_model::Core::Class ;


theAttribute : source_model::Core::Attribute){}


Attribute_AddGetter (ownerClass : source_model::Core::Class ;


theAttribute : source_model::Core::Attribute){}


Attribute_AddSetter (ownerClass : source_model::Core::Class ;


theAttribute : source_model::Core::Attribute){}



}

Grouping classes into libraries and
models


Library goals


A kind of container


It declares elements available for all the classes defined
in it.

»
Models, functions.


Externalisable


As it represents a Metamodel
,

it may be put in a
repository

(and vice
-
versa, a MM from a repository may
be defined as a library)


May be used as a reuse mechanism at the model
level
(not only class)


Model integration


Everything is declared in a library which may be “templated” by a number of
models or views


Libraries are “instanciated”


Declared elements can access real models and real adaptors (library subclass of the
given view)

ModelRef
Library
NativeLibrary
RepositoryRef
TypedModelRef
LibParameter
Package
Classifier
Property
/extendedLibraries {redefines superClass}
*
*
library
parameters {redefines ownedAttributes}
1
*
type
*
1
How to use views ? (motivation)


Write transformations independent from
metamodels of the manipulated models

1.
Describe manipulated concepts (PI MM!) in a library (as
an example Class, Field…)

2.
Write in an inheriting library (PS MM!) how your
concepts are mapped into the real metamodels (UML
1.4, CWM RDB,…)


This is the MDA pattern !

An example of view

<<abtract>>
MM
manipulé
ou vue
MM UML
1.3 adapter
MM UML1.1
adapter
MM UML1.X
adapter
Model 1.X
MM UML2.0
adapter
Model 2.0
Privatize
Lib
-nom
Classe
+nom
+visibilité
Champ
Attribut
Operation
Parametre
type
type
+addGetter()
+addSetter()
+...()
Privatize
1
*
Conclusion


MTL is a transformation language close to a
classical OO language


Ease of learning


Apply well known design patterns & methodologies


MTL programs are


Models, at the same level as source and target models


Independent from model repositories

»
Use repository drivers

»
Any number of models open in read and/or write mode at any
moment


Uncoupled from source & target meta
-
models

»
Concept of view

Conclusion: Major Stakes


Stake 1
: Improve the software engineering productivity

»
Model Transformation actively contributes to automate and
industrialize the production of the software work products


The model transformation is at the core of the MDA

»
Define a suitable model process engineering


Stake 2
: Capitalize transformation expertise

»
Buy, produce and diffuse transformation expertise (COST)

»
Standardization to guarantee the portability and the durability


The OMG «

Query / Views / Transformation

» standard


Stake 3
: Apply these stakes to the model transformation
engineering itself

»
Improve model transformation productivity (dvp and maintenance)

»
Capitalize (composition and reuse) on model transformations