m2t with xpand and xtend - · pdf filem2t with xpand and xtend . 2 ... example: xtext-based...
TRANSCRIPT
Meta.ppt 1
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
M2T with Xpand and Xtend
2
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
M2T - model-to-text transformations
Why so common?
text is a ubiquitous format
many tools uses text as source, intermediary and target format
although text languages are formal, there may not be an
explicit meta-model available
Problems
confusing to mix source and target languages,
i.e. text as output and text as code
encoding issues
less control of the transformation process, e.g. back-patching,
post-processing, transformation chaining, etc.
3
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
Example: Xtext-based state lang. to SCXML
Source language
defined using Ecore
concrete syntax defined with Xtext grammar
Target language
SCXML, an XML-based language defined by W3C:
http://www.w3.org/TR/2009/WD-scxml-20091029/
text-based, but has an XML Schema, so we can effectively
derive an Ecore model
Two possibilities
transform directly to text
transform til Ecore model and serialize
4
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
Example: Xtext-based state lang. to SCXML
Transformation
source and target models have similar concepts
states, transitions, events, conditions, actions
some differences
internal transitions correspond to transitions without a target
enter and exit actions are modeled as internal transitions
what about and-decomposition?
implicit in the source language
explicit in SCXML: <parallel> ... </parallel>
scripting
scripts occur in events, conditions and actions
mostly support in SCXML (extension)
5
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
Main elements of Xpand/Xtend transformation
Import of model
So-called
extension functions
written using the Xtend sub-language
side-effect-free helper methods that are used by the template
Template methods
text fragments that are copied to the output
everything that are not enclosed in french quotes << >>
expressions that are evaluated and written to output
control structures
6
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
Extension functions
Highly inspired by OCL
based on expressions, not imperative code
side-effect-free, but can can change collection values
Matches methods based on types
7
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
Xpand control structures
if else endif
conditional execution
let as
bind local variables
foreach
part of call to template method, for iterating over collection
expression sequence
the -> operator sequences expressions
allows for more procedural code
8
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
From scxmlxtext to <scxml>
Import model and
reference Xtend file
Define main entry point
defines the output file
generates the outer <scxml> element
expands the content as a state named “root”
9
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
From scxmlxtext to <scxml>
A state is tranformed to a <state> element
Expand
all variables
an initial state
allow only 1
all (sub-)states
all transitions
10
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
From scxmlxtext to <scxml>
The initial transitions is tranformed to an <initial>
element with a inner <transition> element
The transition element may have an action
expand if non-null
11
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
From scxmlxtext to <scxml>
The <transition> element
targets, events and conditions are string attributes
actions are inner elements
12
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
From scxmlxtext to <scxml>
The <cs:var> element
apache-specific element, i.e. different namespace
expands init-expression based on expression sub-type
13
TDT4250 - Model-driven Development of Information Systems, Autumn 2009
Q
Sample output
The <cs:var> element
apache-specific element, i.e. different namespace
expands init-expression based on expression sub-type