MoScript a textual DSL for model manipulations
- 1. MoScript: A DSL for querying and
manipulating model repositories
Wolfgang Kling
Frédéric Jouault Marco Brambilla Dennis Wagelaar
Jordi Cabot
21/11/11 ©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
1
- 2. Context
Large numbers of modelling artefacts
– E.g. MDD phases consume and produce
models
Requirements
Use Case
Class Diagram
Java Project
Transfo
rma-on
s
Stored in model repositories
Strong interrelations
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
2
- 3. Context
Not only models (source code,
0110010
1010100
01100101
1010010
01010010
1010001
10010101
tools, libraries etc.) 0001101
Heterogeneous
Distributed
Constant evolution of the
repository
01100101
01010010
10010101
00011010
001
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
3
- 4. Motivation
Understand repository (updated view) 0100101
0100010
1010
Finding models
– By their content
– By a computed characteristic ?
– By their relation with other
models
Combining models
information
Perform common modelling 010010 010010
010010
101000
101010
tasks batch processing
101000 101000
101010 101010
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
4
- 5. MoScript
A textual DSL for querying and manipulating
model repositories
Retrieve models
– by structure and content
– by their relations with others
– by behaviour (after a simulation)
Manipulate models (transform, match,
compare etc.) right after finding them
Update repository view, persisting newly
created artefacts or discarding existing ones
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
5
- 6. MoScript
Based on the megamodel (repository view)
Uses OCL
Combines OCL with
– Operations without side effects
– Statements (update view and repository)
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
6
- 7. MoScript
and
the
Megamodel
MoScript
Megamodel
011 011 011
001 001 001
Model Repositories
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
7
- 8. Megamodel’s Metamodel
* target
Identified * source
Entity
Element
* linked
* * elements
* Model Relationship * relatedTo
conformsTo 1
*
Reference Terminal * sourceOf
* Directed
Model Model
Relationship
* targetOf
extends *
MetaMeta Weaving 1
Model Model Transformation
MetaModel
Model Mega Transformation
Transformation
Model Record
targetReferenceModel
srcReferenceModel
targetModel
srcModel
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
8
- 9. So far … (OCL and Megamodel)
Models conforming to the Java metamodel
Model::allInstances()−>select(m | m.conformsTo.kind = ’Java’)"
Collection{ Model1, Model2 …, Modeln }"
Transformations that transform models
conforming to the Java metamodel
Transformation::allInstances()"
"−>select(t | t.srcReferenceModels.exists(rm | rm.kind = ’Java’))"
Collection{ Transformation1, Transformation2 …, Transformationn }"
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
9
- 10. Strategy
t (x)=
y
Synchronize
x
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
10
- 11. MoScript Abstract Syntax
OCL MoScript MoScript
OclExpression
Unit
PropertyCallExp
Helper Library Program
OperationCallExp
ExpressionStat Statement
QueryOp ProjectionOp RegisterStat SaveStat ForStat
TransformOp StateCheckOp RemoveStat BindingStat IfStat
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
11
- 12. MoScript Concrete Syntax
program program_name"
uses library1"
uses …"
[ using {"
"variable1 : type = OclExpr;"
"variable2 …"
}]"
do {"
"variable <- OclExpr;"
"save(OclExpr, …);"
"remove(OclExpr, …);"
"register(…);"
"if …"
"for …"
}"
helper …"
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
12
- 13. Brief Examples
Query operations
Model::allInstances()−>any(m | m.indentifier = ’SimpsonFamily’)
" −>allContents()−>collect(el | el.name))"
Collection {’Bart’, ’Homer’, ’Lisa’, ’Maggie’, ’Marge’} "
Model to Model transformations (M2M)
1" let j2dNet : Transformation = Transformation::allInstances()"
2" "−>any(t | t.identifier = ’j2dNet’)"
3" in"
4"
5" Model::allInstances()"
6" "−>select(m | m.conformsTo.kind = ’Java’)) "
7" "−>collect (jModel | j2dNet.applyTo(jModel))"
TransformationRecord::allInstances()−>collect(tr | tr.run())"
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
13
- 14. Brief Examples
Projectors (inject & extract)
Model::allInstances()−>select(m | m.conformsTo.kind = ’JavaGrammar’)) "
"−>collect (jCode|jCode.inject())"
The save statement
1" ... for(dNetModel in dNetModels) {"
2" " "save( dNetModel, dNetModel.getIdentifier(),"
3" dNetModel . location + ’.xmi’);"
4" } "
5"
6" helper context Model def: getIdentifier(): ... ;"
The register statement"
register(MetaMetaModel, ’Ecore’, ’http://www.eclipse.org/emf/2002/Ecore’);"
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
14
- 15. MoScript
Operations Without Side Effects
Model :: allContents() : Collection(OclAny)"
Model :: allContentsRoots() : Collection(OclAny)"
Model :: allContentsInstancesOf(type_name : String) : Collection(OclAny)"
Model :: allContentsInstancesOf(type : OclAny) : Collection(OclAny)"
Transformation :: applyTo(inputModels : Sequence(Model)) : TransformationRecord"
Transformation :: applyTo(inputModels : Map(String, Model)) : TransformationRecord"
TransformationRecord :: run() : TransformationRecord"
Model :: inject() : Model"
Model :: extract() : Model"
Model :: available() : Boolean"
Model :: isDirty() : Boolean"
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
15
- 16. MoScript
Statements With Side Effects
save(m : Model, mgm : Megamodel, id : String, locator : String)"
remove(m : Model, mgm : Megamodel)"
register(elem : OclModelElement, id : String, locator : String)"
register(elem : OclModelElement, attrs : Map(String, OclAny))"
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
16
- 17. MoScript
Underlying
DSLs
Editors
Discoverers
1
Architecture
MoScript
2
3 6
Megamodel
5
Metadata
Engine
TransformaIon
Tools
4
011 011 011
001 001 001
Model Repositories
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
17
- 18. ImplementaIon
MoScript
ATL
VM
GMM / AM3
ATL
ATL VM
AM3
TCS
ANTLR
ATL Zoo WebML
011 011
011 001
001
001
Model Repositories
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
18
- 20. Experimentation
ATL Transformation Zoo model repository
http://www.eclipse.org/m2m/atl/atlTransformations/
– 205 metamodels, 275 models, 219 transformations and
400 other artefacts
Reverse engineering megamodel generation
Different kind of metrics
Execution of all the transformations and check results
Matching models
WebML model repository
– WebModel metamodel
– WebModel xml (.wr) injection to ecore
– Transformation to WebML models
– Count user interface fields
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
20
- 21. Conclusions
DSL for querying and manipulating model repositories
• Uses OCL
• Based on the Megamodel
• Model dereferencing
• Applies transformation to model similarly as working
with functions.
• Allows the use of multiple transformation tools
• Makes types checking at run time to ensure
consistency.
• Hides a lot of the complexity of handling large
amounts of modelling artefacts and relationships, to
the user
• Keeps synchronized the megamodel with the
repository to ensure integrity
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
21
- 22. END
Thank you
for
attending
21/11/11
©
AtlanMod
-‐
atlanmod-‐contact@mines-‐nantes.fr
22