model transformation techniquespeople.irisa.fr/jean-marc.jezequel/enseignement/modeltransfo.pdf ·...
TRANSCRIPT
1
Model Transformation TechniquesModel Transformation Techniques(or: (or: WhyWhy I'd I'd likelike writewrite programsprograms thatthat writewrite programsprograms
ratherrather thanthan writewrite programsprograms))
Prof. Jean-Marc Jézéquel(Univ. Rennes 1 & INRIA)
Triskell Team @ IRISACampus de Beaulieu
F-35042 Rennes CedexTel : +33 299 847 192 Fax : +33 299 847 171
e-mail : [email protected]://www.irisa.fr/prive/jezequel
© J.-M. Jézéquel, 2005 4
ModelingModeling andand WeavingWeaving
DesignModel
Use CaseModel
SecurityModel
QoSModel Business
Model
ObjectModel
TestModel
UIModel
PlateformeModel
CodeModel
tester
Challenges:-Automatic Weaving-Product Lines-Reuse design know-how reified as Model Transformations
Challenges:-Automatic Weaving-Product Lines-Reuse design know-how reified as Model Transformations
2
© J.-M. Jézéquel, 2005 5
ModelModel--toto--Text vs. ModelText vs. Model--toto--ModelModelModelModel--toto--Text TransformationsText Transformations–– For generating: code, xml, html, doc. For generating: code, xml, html, doc. –– Should be limited to syntactic level Should be limited to syntactic level transcodingtranscoding
ModelModel--toto--Model TransformationsModel Transformations–– PIM to PSM a la OMG MDAPIM to PSM a la OMG MDA–– Refining modelsRefining models–– Reverse engineering (code to models)Reverse engineering (code to models)–– Generating new viewsGenerating new views–– Applying design patternsApplying design patterns–– RefactoringRefactoring modelsmodels–– Deriving products in a product lineDeriving products in a product line–– … any model engineering activity that can be automated…… any model engineering activity that can be automated…
© J.-M. Jézéquel, 2005 6
ModelModel--toto--Text ApproachesText ApproachesFor generating: code, xml, html, doc. For generating: code, xml, html, doc. –– VisitorVisitor--Based Approaches: Based Approaches:
»» Some visitor mechanisms to traverse the internal representation Some visitor mechanisms to traverse the internal representation of a model and write code to a text streamof a model and write code to a text stream
»» IteratorsIterators, Write (), Write ()–– TemplateTemplate--Based ApproachesBased Approaches
»» A template consists of the target text containing slices of metaA template consists of the target text containing slices of meta--code to access information from the source and to perform text code to access information from the source and to perform text selection and iterative expansionselection and iterative expansion
»» The structure of a template resembles closely the text to be The structure of a template resembles closely the text to be generatedgenerated
»» Textual templates are independent of the target language and Textual templates are independent of the target language and simplify the generation of any textual simplify the generation of any textual artefactsartefacts
3
© J.-M. Jézéquel, 2005 7
Transformation ArchitectureTransformation Architecture
Transformation
Meta-model A
Model A
Conforms To
Meta-model B
Model B
Conforms To
Apply Transformation
Define Transformation
© J.-M. Jézéquel, 2005 8
ModelModel--toto--Model: Typical ExampleModel: Typical ExampleFrom UML to RDBMS
Transformation
4
© J.-M. Jézéquel, 2005 9
Element stereotype
Design pattern application(parametric collaboration)
Historycmd_executed : string
last_command() : string
<<persistent>>
ServiceProvider
<<com mand>> action_1()<<com mand>> action_2()<<com mand>> action_3()
Interpreter
execute()
0..*
1
0..*
11..*1..* 1..*
+invoker
1..*
…and alsoTagged values& Contracts
Command pattern
receiverinvoker
M2M: Reuse Engineering KnowM2M: Reuse Engineering Know--How (Design/Test/…)How (Design/Test/…)
© J.-M. Jézéquel, 2005 10
The resultThe result wewe wanwantt : : design patterns applicationdesign patterns application
Historycmd_executed : string
last_command() : string
<<persistent>>
History_StorageProxy
load_last_command() : stringstore_last_command(cmd : string)
action_1_cmd
do()
action_2_cmd
do()
action_3_cmd
do()
ServiceProvider
<<command>> action_1()<<command>> action_2()<<command>> action_3()
+proxy
Interpreter
execute()
0..*
1
0..*
1
ServiceProvider_Command
do() 10..*
+cmdTarget
10..*1..*0..* 1..*
+commands
0..*
5
© J.-M. Jézéquel, 2005 11
Why complex transformations?Why complex transformations?Example: Air Traffic ManagementExample: Air Traffic Management–– “business model” quite stable & not that complex“business model” quite stable & not that complex
Various modeling languages used beyond UMLVarious modeling languages used beyond UML–– As many points of views as stakeholdersAs many points of views as stakeholders
Deliver software for (many) variants of a platformDeliver software for (many) variants of a platform–– Heterogeneity is the ruleHeterogeneity is the rule
Reuse technical solutions across large product Reuse technical solutions across large product lines (e.g. fault tolerance, security…)lines (e.g. fault tolerance, security…)Customize generic transformationsCustomize generic transformationsCompose reusable transformationsCompose reusable transformationsEvolve & maintain transformations for 15+ years!Evolve & maintain transformations for 15+ years!
© J.-M. Jézéquel, 2005 12
Classification Classification ofofModel Transformation TechniquesModel Transformation Techniques
1.1. General purpose programming languagesGeneral purpose programming languages–– Java/C#...Java/C#...
2.2. Generic transformation toolsGeneric transformation tools–– Graph transformations, XSLT…Graph transformations, XSLT…
3.3. CASE tools scripting languagesCASE tools scripting languages–– ObjecteeringObjecteering, Rose…, Rose…
4.4. Dedicated model transformation toolsDedicated model transformation tools–– OMG QVT styleOMG QVT style
5.5. MetaMeta--modeling toolsmodeling tools–– MetacaseMetacase, , XactiumXactium, , KermetaKermeta……
6
© J.-M. Jézéquel, 2005 13
1. General purpose language approach1. General purpose language approachJava, VB, C++, C#,... Java, VB, C++, C#,... Your favorite Your favorite language!language!Currently available in the tools via APIsCurrently available in the tools via APIsRules and scheduling implemented Rules and scheduling implemented from scratch using the programming from scratch using the programming languagelanguageExample:Example:–– JMI (MOFJMI (MOF--compliant Java Interface)compliant Java Interface)
»» JSRJSR--000040 Java000040 Java™™ Metadata Interface Metadata Interface
© J.-M. Jézéquel, 2005 14
JMI examplesJMI examplespackage javax.jmi.model;
import javax.jmi.reflect.*;
public interface Attribute extends StructuralFeature {public boolean isDerived();public void setDerived(boolean newValue);
}
package javax.jmi.model;
import javax.jmi.reflect.*;
public interface Operation extends BehavioralFeature {public boolean isQuery();public void setQuery(boolean newValue);public java.util.List getExceptions();
}
Attributes
Operations
7
© J.-M. Jézéquel, 2005 15
General purpose language approach: General purpose language approach: ConclusionConclusion
No overhead to learn a new languageNo overhead to learn a new languageTool support to write the transformationsTool support to write the transformations
But wait:But wait:–– We resort to modeling (before programming) for mastering We resort to modeling (before programming) for mastering
complexity, right?complexity, right?–– Does it mean that transformations never get complex?Does it mean that transformations never get complex?
»» Or that the problem only appears for non toy applications…Or that the problem only appears for non toy applications…
=> Monsieur Jourdain’s approach
© J.-M. Jézéquel, 2005 16
2. Generic transformation tools2. Generic transformation toolsAwkAwk--like (inc. like (inc. sedsed, , perlperl…) …)
XSLTXSLT
Graph Transformation toolsGraph Transformation tools
8
© J.-M. Jézéquel, 2005 17
Intermediate transformation languageIntermediate transformation languageTypically XML basedTypically XML based–– But XML (XMI) is verboseBut XML (XMI) is verbose
XSLT can be used to transform XML trees into XSLT can be used to transform XML trees into other (XML) (trees)other (XML) (trees)–– More batch than interactiveMore batch than interactive–– Parameters are passed by valuesParameters are passed by values–– XSLT transformations are not really easy to maintainXSLT transformations are not really easy to maintain
Better for simple transformationsBetter for simple transformations
© J.-M. Jézéquel, 2005 18
Example of XSLT transformation
If isSynchronous
Else
Do this
Do that
9
© J.-M. Jézéquel, 2005 19
GraphGraph--TransformationTransformation--BasedBasedDeclarative, based on the theoretical work Declarative, based on the theoretical work on graph transformationson graph transformations–– Operates on typed, attributed, labeled graphsOperates on typed, attributed, labeled graphs–– Rule (LHS, RHS : Graph Pattern)Rule (LHS, RHS : Graph Pattern)–– Automated source element selection, nonAutomated source element selection, non--determinism in determinism in
scheduling and application strategyscheduling and application strategyWell known technology, albeit hard to masterWell known technology, albeit hard to master
»» M. M. AndriesAndries, G. , G. EngelsEngels, A. , A. HabelHabel, B. Hoffmann, H., B. Hoffmann, H.--J. J. KreowskiKreowski, S. , S. KuskeKuske, D. , D. KuskeKuske, D. Plump, A. , D. Plump, A. SchürrSchürr, and G. , and G. TaentzerTaentzer. Graph . Graph Transformation for Specification and Programming. Technical Transformation for Specification and Programming. Technical Report 7/96, Report 7/96, UniversitätUniversität Bremen, 1996, see Bremen, 1996, see http://citeseer.nj.nec.com/article/andries96graph.html http://citeseer.nj.nec.com/article/andries96graph.html
© J.-M. Jézéquel, 2005 20
Generic transformation tools: Generic transformation tools: ConclusionConclusion
AwkAwk--like (inc. like (inc. sedsed, , perlperl…) …)
XSLTXSLT–– Good for syntactic Good for syntactic transcodingtranscoding, ,
not for semantic manipulations not for semantic manipulations
Graph Transformation toolsGraph Transformation tools–– PowerfullPowerfull, but complex because of the non, but complex because of the non--determinism in determinism in
scheduling and application strategyscheduling and application strategy–– Require careful consideration of termination of the Require careful consideration of termination of the
transformation process and the rule application orderingtransformation process and the rule application ordering
SE Limit: ~100 LOC
SE Limit: ~1000 LOC
SE Limit: PhD needed!
10
© J.-M. Jézéquel, 2005 21
3. CASE tool scripting languages3. CASE tool scripting languagesArcstylerArcstyler fromfrom Interactive Interactive ObjectsObjects–– MDAMDA--CartridgeCartridge, , JPythonJPython (Python & Java)(Python & Java)ObjecteeringObjecteering fromfrom ObjecteeringObjecteering SoftwareSoftware–– J languageJ languageOptimalJOptimalJ fromfrom CompuwareCompuware–– TPL TPL languagelanguageFujabaFujaba ((FromFrom UML to Java UML to Java andand Back Back AgainAgain))–– Open Source Open Source ……
© J.-M. Jézéquel, 2005 22
CASE tools scripting languagesCASE tools scripting languagesProPro–– Good level of maturityGood level of maturity–– Excellent integration with their CASE toolExcellent integration with their CASE toolDrawbacksDrawbacks–– Proprietary languages and/or tight coupling with the CASEProprietary languages and/or tight coupling with the CASE–– Often developed as a second thought, not centralOften developed as a second thought, not central–– Many limitations when model transformation get complexMany limitations when model transformation get complex
»» StructurationStructuration, modularity, reuse problem, modularity, reuse problem»» Configuration management issue when they need to be evolved Configuration management issue when they need to be evolved
and maintained for long periodsand maintained for long periods
11
© J.-M. Jézéquel, 2005 23
4. Dedicated Transformation 4. Dedicated Transformation LanguageLanguage
OMG QVT styleOMG QVT style–– Kind of DSL for transformationKind of DSL for transformation
Simplify development and maintenance of Simplify development and maintenance of modelmodel--transformationstransformationsHigher expression powerHigher expression powerEnhanced Enhanced structurationstructuration–– Composition of rulesComposition of rules–– InteroperabilityInteroperability
© J.-M. Jézéquel, 2005 24
MOF 2.0 Queries/Views/Transformations RFP
Define a language for querying MOF modelsDefine a language for transformation definitionsAllow for the creation of views of a modelEnsure that the transformation language is declarative and expresses complete transformationsEnsure that incremental changes to source models can be immediately propagated to the target modelsExpress all new languages as MOF models
12
© J.-M. Jézéquel, 2005 25
QueryQueryAn expression evaluated over a modelAn expression evaluated over a model–– Returns one or more instances of types defined either in Returns one or more instances of types defined either in
the source model or by the query languagethe source model or by the query language
OCL is an example of a query languageOCL is an example of a query language
© J.-M. Jézéquel, 2005 26
ViewViewA view is a model that is completely derived A view is a model that is completely derived from another modelfrom another model–– The metaThe meta--model of the view is typically not the same as the model of the view is typically not the same as the
metameta--model of the sourcemodel of the source
Model ViewTransformation
Meta-Model A Meta-Model A’
13
© J.-M. Jézéquel, 2005 27
TransformationTransformationA transformation generates target models A transformation generates target models from source modelsfrom source models
Transformation TargetModel
SourceModel
May be bi-directional
© J.-M. Jézéquel, 2005 28
Q Q vsvs V V vsvs TTA query is a restricted kind of viewA query is a restricted kind of view
A view is a restricted kind of transformation A view is a restricted kind of transformation –– The target model cannot be modified independently of the The target model cannot be modified independently of the
source modelsource model
A transformation generates target models A transformation generates target models from source modelsfrom source models
14
© J.-M. Jézéquel, 2005 29
ClassificationClassificationSeveral approachesSeveral approaches–– GraphGraph--transformationtransformation--based Approachesbased Approaches–– Relational ApproachesRelational Approaches–– StructureStructure--Driven ApproachesDriven Approaches–– Hybrid ApproachesHybrid Approaches
CommercialCommercial–– MiaMia--TransformationTransformation ((MiaMia--SoftwareSoftware), ), PathMATEPathMATE ((PathfinderPathfinder Solutions)Solutions)
Many academic toolsMany academic tools–– ATL & MTL (INRIA), ATL & MTL (INRIA), AndroMDAAndroMDA, BOTL (, BOTL (BidirectionalBidirectional ObjectObject orientedoriented
Transformation Transformation LanguageLanguage),),CoralCoral ((ToolkitToolkit to to createcreate//editedit//transformtransform new new modelsmodels//modelingmodeling languageslanguages atat runrun--timetime), ), ModMod--TransfTransf (XML (XML andand ruledruled basedbasedtransformation transformation languagelanguage), ), QVTEclipseQVTEclipse ((preliminarypreliminary implementationimplementation ofof somesome ideasideasofof QVT in QVT in EclipseEclipse) ou encore UMT) ou encore UMT--QVT (UML Model Transformation QVT (UML Model Transformation ToolTool))
© J.-M. Jézéquel, 2005 30
DeclarativeDeclarativeDeclarative languages describe relationships Declarative languages describe relationships between variables in terms of functions or between variables in terms of functions or inference rules and the language executor inference rules and the language executor (interpreter or compiler) applies some fixed (interpreter or compiler) applies some fixed algorithm to these relations to produce a algorithm to these relations to produce a resultresult
15
© J.-M. Jézéquel, 2005 31
ImperativeImperativeAny programming language that specifies Any programming language that specifies explicit manipulation of the state of the explicit manipulation of the state of the computer system, not to be confused with a computer system, not to be confused with a procedural languageprocedural language
© J.-M. Jézéquel, 2005 32
Declarative vs. Imperative StyleDeclarative vs. Imperative Style
Declarative (what to do)Declarative (what to do)–– Invariant relations between source and target modelsInvariant relations between source and target models
Imperative (how to do it)Imperative (how to do it)–– How to derive a target from a sourceHow to derive a target from a source
May be combined via preMay be combined via pre-- and postand post--conditionsconditions
Imperative RuleDeclarative
Pre-ConditionDeclarative
Post-Condition
16
© J.-M. Jézéquel, 2005 33
Execution StrategyExecution StrategyInvocation of the transformation rulesInvocation of the transformation rules–– Explicit, via invocation operations (Java like)Explicit, via invocation operations (Java like)–– Implicit, based on context and rules’ signature (Prolog like)Implicit, based on context and rules’ signature (Prolog like)
© J.-M. Jézéquel, 2005 34
TraceTraceTrace associates one (or more) target Trace associates one (or more) target element with the source elements that lead element with the source elements that lead to its creationto its creation–– For RoundFor Round--trip developmenttrip development–– Incremental propagationIncremental propagation
Rules may be able to match elements based Rules may be able to match elements based on the trace without knowing the rules that on the trace without knowing the rules that created the trace created the trace
17
© J.-M. Jézéquel, 2005 35
RuleRuleRules are the units in which transformations Rules are the units in which transformations are definedare defined–– A rule is responsible for transforming a particular selection A rule is responsible for transforming a particular selection
of the source model to the corresponding target model of the source model to the corresponding target model elements.elements.
© J.-M. Jézéquel, 2005 36
DeclarationDeclarationA declaration is a specification of a relation A declaration is a specification of a relation between elements in the LHS and RHS between elements in the LHS and RHS modelsmodels
18
© J.-M. Jézéquel, 2005 37
ImplementationImplementationAn implementation is an imperative An implementation is an imperative specification of how to create target model specification of how to create target model elements from source model elementselements from source model elements–– An implementation explicitly constructs elements in the An implementation explicitly constructs elements in the
target modeltarget model–– Implementations are typically directedImplementations are typically directed
© J.-M. Jézéquel, 2005 38
MatchMatchA match occurs during the application of a A match occurs during the application of a transformation when elements from the LHS transformation when elements from the LHS and/or RHS model are identified as meeting and/or RHS model are identified as meeting the constraints defined by the declaration of the constraints defined by the declaration of a rulea rule–– A match triggers the creation (or update) of model A match triggers the creation (or update) of model
elements in the target modelelements in the target model
19
© J.-M. Jézéquel, 2005 39
IncrementalIncrementalA transformation is incremental if individual A transformation is incremental if individual changes in a source model can lead to changes in a source model can lead to execution of only those rules which match execution of only those rules which match the modified elementsthe modified elements
© J.-M. Jézéquel, 2005 40
M2M: Relational ApproachesM2M: Relational ApproachesDeclarative, based on mathematical relationsDeclarative, based on mathematical relations–– Good balance between flexibility and declarative expressionGood balance between flexibility and declarative expression
ImplementableImplementable with logic programmingwith logic programming–– Mercury, FMercury, F--Logic programming languagesLogic programming languages–– Predicate to describe the relationsPredicate to describe the relations–– Unification basedUnification based--matching, search and backtrackingmatching, search and backtracking
20
© J.-M. Jézéquel, 2005 41
Example of logic programmingExample of logic programmingExcerpt of Mercury codeExcerpt of Mercury code
© J.-M. Jézéquel, 2005 42
M2M : StructureM2M : Structure--Driven ApproachesDriven Approaches1st Phase1st Phase–– Creation of hierarchical structure of target modelCreation of hierarchical structure of target model2nd Phase2nd Phase–– Set the attributes and references in the targetSet the attributes and references in the target
Users provide the transformation rulesUsers provide the transformation rulesFramework determines the schedulingFramework determines the scheduling
21
© J.-M. Jézéquel, 2005 43
M2M : StructureM2M : Structure--Driven ApproachesDriven ApproachesPragmatic approaches developed in the Pragmatic approaches developed in the context of EJB and Databases schema context of EJB and Databases schema generation from UML modelsgeneration from UML modelsStrong support for 1Strong support for 1--toto--1 and 11 and 1--toto--n n correspondence between source and targetcorrespondence between source and targetUnclear how well these approaches can Unclear how well these approaches can support other kinds of applicationssupport other kinds of applications
© J.-M. Jézéquel, 2005 44
M2M : Hybrid Approaches M2M : Hybrid Approaches -- othersothersAny combination of different techniquesAny combination of different techniques
Practical approaches are very likely to have Practical approaches are very likely to have the hybrid characterthe hybrid character
22
© J.-M. Jézéquel, 2005 45
Dedicated model transformation Dedicated model transformation tools: Conclusiontools: Conclusion
How many developers are familiar with the How many developers are familiar with the prologprolog--like style of rules writing?like style of rules writing?
Where is the advantage of a dedicated Where is the advantage of a dedicated explicit language vs. a general purpose explicit language vs. a general purpose language?language?
Hybrid Languages or transformation libraries Hybrid Languages or transformation libraries for general purpose languages…for general purpose languages…
© J.-M. Jézéquel, 2005 46
5. Meta5. Meta--modeling toolsmodeling toolsBuildBuild (OO) (OO) ModelsModels ofof TransformationsTransformationsUse MDE to Use MDE to runrun themthem
Commercial Commercial toolstools::–– MetaEditMetaEdit++ fromfrom MetaCaseMetaCase–– XMFXMF--MosaicMosaic fromfrom XactiumXactium
OpenOpen--SourceSource–– KerMeta KerMeta fromfrom INRIA INRIA –– www.kermeta.orgwww.kermeta.org
23
© J.-M. Jézéquel, 2005 47
General schemeGeneral scheme
Design Decisions(OO patterns e.g.
template method…)
Pre-Design Decisions(OO frameworks)
Metamodels
ExecutableMeta-program
ModelMetamodels
MetamodelModel
Model
ModelModel
Model
© J.-M. Jézéquel, 2005 48
““Programming style” IssuesProgramming style” IssuesThe transformation is simply the model of an The transformation is simply the model of an objectobject--oriented program that manipulates oriented program that manipulates model elementsmodel elements–– Navigation through model is first class though (like in OCL)Navigation through model is first class though (like in OCL)OO techniquesOO techniques–– Customizability through inheritance/Customizability through inheritance/dyndyn. binding. binding–– Pervasive use of Pervasive use of GoFGoF like Design Patternslike Design Patterns
24
© J.-M. Jézéquel, 2005 49
Defining the metamodelsDefining the metamodels
name: EString
Classifier
name: EString
Association
is_primary: EBooleanname: EString
Attribute
is_persistent: EBoolean
Class
PrimitiveDataType
ClassModel
type
1
classifier
*
dest1 src1
association
*
parent
0..1 name: EString
Table
FKey
name: EStringtype: EString
Column
RDBMSModel
pkey
1..*cols
1..*
fkeys
*
table1..*
cols1..*references1
Input metamodel Output metamodel
© J.-M. Jézéquel, 2005 50
Visual / TextualVisual / Textual
package RDBMSMM;require kermetausing kermeta::standardclass Table{
attribute name : Stringattribute cols : Column[1..*]reference pkey : Column[1..*]attribute fkeys : FKey[0..*]
}class FKey{
reference references : Tablereference cols : Column[1..*]
}class Column{
attribute name : Stringattribute type : String
}class RDBMSModel{
attribute table : Table[1..*]}
25
© J.-M. Jézéquel, 2005 51
UML2RDBMS template methodUML2RDBMS template methodCreate tablesCreate tables–– Tables are created from classes marked as persistent in the inpuTables are created from classes marked as persistent in the input t
modelmodelCreate columnsCreate columns–– For each persistent class process all attributes and outgoing For each persistent class process all attributes and outgoing
associations to create corresponding columns. The foreign keys aassociations to create corresponding columns. The foreign keys are re created but the created but the cols cols property cannot be filled and the corresponding property cannot be filled and the corresponding columns cannot be created because primary keys of columns cannot be created because primary keys of referencesreferences table table cannot be known before it has been processed.cannot be known before it has been processed.
Update foreignUpdate foreign--keyskeys–– The foreignThe foreign--key columns are created in the table that contains the key columns are created in the table that contains the
foreignforeign--key and the property key and the property cols cols of foreignof foreign--keys is updated.keys is updated.
=> Handle details/variability into subclasses
© J.-M. Jézéquel, 2005 52
package Class2RDBMS;require kermeta // The kermerta standard libraryrequire "trace.kmt // The trace frameworkrequire "../metamodels/ClassMM.ecore" // Input metamodel in ecorerequire "../metamodels/RDBMSMM.kmt“ // Output metamodel in kermeta[...]class Class2RDBMS {
/** The trace of the transformation */reference class2table : Trace<Class, Table>
/** Set of keys of the output model */reference fkeys : Collection<FKey>
[…]
Writing the transformationWriting the transformation
Loading ECore andKermeta metamodels
26
© J.-M. Jézéquel, 2005 53
operation transform(inputModel : ClassModel) : RDBMSModel is do// Initialize the traceclass2table := Trace<Class, Table>.newclass2table.createfkeys := Set<FKey>.newresult := RDBMSModel.new// Create tablesgetAllClasses(inputModel).select{ c | c.is_persistent }.each{ c |
var table : Table init Table.newtable.name := c.nameclass2table.storeTrace(c, table)result.table.add(table)
}// Create columnsgetAllClasses(inputModel).select{ c | c.is_persistent }.each{ c |
createColumns(class2table.getTargetElem(c), c, "")}// Create foreign keysfkeys.each{ k | k.createFKeyColumns }
Create Tables
Create Columns
Update Foreign Keys
Trace Initialization
© J.-M. Jézéquel, 2005 54
Getting the input modelGetting the input model
27
© J.-M. Jézéquel, 2005 55
Executing the transformationExecuting the transformation
© J.-M. Jézéquel, 2005 56
Generated output modelGenerated output model
28
© J.-M. Jézéquel, 2005 57
ObjectObject--orientationorientationClasses and relations, multiple inheritance, Classes and relations, multiple inheritance, late binding, static typing, class late binding, static typing, class genericitygenericity, , exception, typed function objects exception, typed function objects OO techniques such as patterns, may be OO techniques such as patterns, may be applied to model transformationsapplied to model transformations–– Template method as aboveTemplate method as above–– Command, undoCommand, undo--redoredo
»» Refactorings exampleRefactorings exampleabstract class RefactoringCommand{
operation check() : Boolean is abstractoperation transform() : Void is abstractoperation revert() : Void is abstract
}
© J.-M. Jézéquel, 2005 58
CompositionComposition of transformationsof transformationsPackages, classes, operations and methods, Packages, classes, operations and methods, inheritance and late bindings inheritance and late bindings Rule Rule recursivityrecursivity is handled by function is handled by function recursivityrecursivity
29
© J.-M. Jézéquel, 2005 59
Robustness and error handlingRobustness and error handlingKermeta is statically typed, and the code can Kermeta is statically typed, and the code can be fully checked for correctness at be fully checked for correctness at compilation time. compilation time. For unexpected behavior at runtime, the For unexpected behavior at runtime, the language provides exception handling. language provides exception handling.
© J.-M. Jézéquel, 2005 60
Design variations, libraries vs. Design variations, libraries vs. DSLsDSLsA final design reflects a set of tradeoffs A final design reflects a set of tradeoffs made by the developermade by the developerThe variation of the designs may be more or The variation of the designs may be more or less constraint by the amount of preless constraint by the amount of pre--design design and reuse provided by the language and reuse provided by the language environmentenvironment
30
© J.-M. Jézéquel, 2005 61
Software Engineering ConcernsSoftware Engineering ConcernsModularity in the small and the large Modularity in the small and the large –– classes & packagesclasses & packagesReliabilityReliability–– static typing, typed function objects and exception handling static typing, typed function objects and exception handling Extensibility and reuse Extensibility and reuse –– inheritance, late binding and inheritance, late binding and genericitygenericityV & VV & V–– test casestest cases
© J.-M. Jézéquel, 2005 62
ConclusionConclusionTransformations are AssetsTransformations are Assets–– apply sound SE principles: apply sound SE principles: Modeling!Modeling!
»» from requirements, analysis, design, to implementation, V&V, from requirements, analysis, design, to implementation, V&V, and Configuration Managementand Configuration Management
Developing Model Transformations inDeveloping Model Transformations in--thethe--large is large is not different from developing softwarenot different from developing software–– Unclear Requirements, Bugs, Unclear Requirements, Bugs, –– Learning Curve (yet another language)Learning Curve (yet another language)
A specific language does not help much to A specific language does not help much to address these generic SE issuesaddress these generic SE issues–– Rely on proven techniques: OO languages, patterns, frameworksRely on proven techniques: OO languages, patterns, frameworks
Model-Driven Approach to Model Transformation