M2T with Xpand and Xtend Meta.ppt 1 TDT4250 - Model-driven - - PowerPoint PPT Presentation

m2t with xpand and xtend
SMART_READER_LITE
LIVE PREVIEW

M2T with Xpand and Xtend Meta.ppt 1 TDT4250 - Model-driven - - PowerPoint PPT Presentation

TDT4250 - Model-driven Development of Information Systems, Autumn 2009 M2T with Xpand and Xtend Meta.ppt 1 TDT4250 - Model-driven Development of Information Systems, Autumn 2009 M2T - model-to-text transformations Why so common?


slide-1
SLIDE 1

Meta.ppt 1

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

M2T with Xpand and Xtend

slide-2
SLIDE 2

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.

slide-3
SLIDE 3

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

slide-4
SLIDE 4

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)

slide-5
SLIDE 5

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

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

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”

slide-9
SLIDE 9

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

slide-10
SLIDE 10

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

slide-11
SLIDE 11

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

slide-12
SLIDE 12

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

slide-13
SLIDE 13

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

slide-14
SLIDE 14

14

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Sample output

structural view text view Remove whitespace by inserting – before >> e.g.