m2t with xpand and xtend
play

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?


  1. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 M2T with Xpand and Xtend Meta.ppt 1

  2. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 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, Q post-processing, transformation chaining, etc. 2

  3. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 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 Q � � transform til Ecore model and serialize 3

  4. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 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 Q � � scripts occur in events, conditions and actions � � mostly support in SCXML (extension) 4

  5. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 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 Q 5

  6. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 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 Q 6

  7. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 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 Q 7

  8. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 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” Q 8

  9. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 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 Q 9

  10. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 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 Q 10

  11. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 From scxmlxtext to <scxml> � � The <transition> element � � targets, events and conditions are string attributes � � actions are inner elements Q 11

  12. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 From scxmlxtext to <scxml> � � The <cs:var> element � � apache-specific element, i.e. different namespace � � expands init-expression based on expression sub-type Q 12

  13. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 Sample output � � The <cs:var> element � � apache-specific element, i.e. different namespace � � expands init-expression based on expression sub-type Q 13

  14. TDT4250 - Model-driven Development of Information Systems, Autumn 2009 Sample output structural view text view Q Remove whitespace by inserting – before >> e.g. 14

Recommend


More recommend