Presentation is loading. Please wait.

Presentation is loading. Please wait.

Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731) 6-1c. MOFScript - Model to Text Transformation,

Similar presentations


Presentation on theme: "Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731) 6-1c. MOFScript - Model to Text Transformation,"— Presentation transcript:

1 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) 6-1c. MOFScript - Model to Text Transformation,

2 2 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Outline Background Introducing the MOFScript language MOFScript and the MOF MOFScript and the relation to QVT Details of the MOFScript language Example1: From UML class diagram to Java MOFScript advanced features The MOFScript tool

3 3 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Background

4 4 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) The MOF model to text transformation RFP The Model to Text Transformations RFP (ad/ ) asks for proposals that define a language that provides capabilities for generating text output from MOF models, e.g. in order to support code generation, documentation, etc. Important in this regard, is capabilities to perform string manipulation. Proposals shall define a solution for generating text from MOF 2.0 models. Proposals shall reuse existing OMG language specifications (e.g. such as QVT capabilities) Proposals shall be able to support complex text transformation mappings.

5 5 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Consortium Submitters: (supporter) Also supported by the following MODELWARE partners:

6 6 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) MOFScript – Background Usability –Ease of use: Writing and understanding –Few constructs End user recognisability –Similar to programming and scripting languages Sequential execution semantics –Rules are called explicitly Might also support pattern matching execution –Contents of rules is executed sequentially Compatibility –Alignment with QVT

7 7 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Introducing the MOFScript language

8 8 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) What is MOFScript? The MOFScript tool is an implementation of the MOFScript model to text transformation language –http://umt-qvt.sourceforge.net/mofscript/updatehttp://umt-qvt.sourceforge.net/mofscript/update An Eclipse plug-in (Feature) Developed by SINTEF ICT in the EU-supported MODELWARE project Ongoing standardization process within OMG –OMG RFP MOF Model to Text Transformation process –MOFScript tool and language is part of this process –Competing proposal:...

9 9 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) MOFScript in action Documentation UML MOFScript Program code XML RDBMS BPMN MOF MODELS Lexical output

10 10 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) MOFScript language features (1) Rules –Rules are invoked explicitly. Output of text –Standard print mechanism (println) –Escaped output Files –Generation of named files Collections and Iterators –Collection types (List, Hashtable/Dictionary) –Iterators: Loops on collections (or Strings/Integers)

11 11 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) MOFScript language features (2) String handling –Functions for String manipulation Types –String, Boolean, Integer, Real, List, Dictionary/Hashtable Variables and constants –Global or local, explicitly or implicitly typed. Utility functions –Utility & system functions: time(), date(), getenv(), setenv(), indent(), tab(), space(), position(), count() Side effects –Variables can be modified –MOF Script has side effects, in the sense that variables can be declared and manipulated during the lifetime of a transformation. It does not, however affect the source models.

12 12 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Basic QVT extensions

13 13 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Text transformation

14 14 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Mapping body

15 15 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Variables and constants

16 16 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Output expressions OutputExpression –OutputExpression represents an expression that generates textual output to some device, typically an output file or standard output console. OutputDeviceExpression –concept that represents the declaration of an output device, such as a file. FileDeviceExpression –Device tailored for file output StdOutDeviceExpression –Device for std output EscapedOutputExpression –Escaped text output

17 17 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Iterator extensions QVT defines a range of iterators and block expressions QVT also defines block expressions which are blocks executed in sequence –E.g. while ForEachExp and If also as block statements self.ownedMembers->forEach (p:uml.Package | p.stereotype = “System”) { <% // the package declration package org.mofscript.%> p.name <% %> if (self.name = “Person”) { } else { }

18 18 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Function libraries String library –Various string manipulation functions, such as: Size, substring, subStringBefore|After, toLower, toUpper, indexOf, trim, endsWith, startsWith, replace, equals, equalsIgnoreCase,… Collection library –Standard collection operations… Hashtable: put, get, clear, size, isEmpty List: add, size, clear, isEmpty Utility library –Various utility functions, such as Time, date, Indent, unindent, newline(count: int), tab(count : int), position() {numbered position within an iterator}, … XML library –Functions to support XML manipulation

19 19 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Details of the MOFScript language

20 20 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Textual syntax Textmodule Rules Iterators Files Escaped output <% public class %> c.name <% extends Serializable { %> file f2 (c.name + “.java”) c.ownerPackage.name f2.println (“public class” + c.name); uml.Package::mapPackage () { self.ownedMember->forEach(c:uml.Class) <% c.name %> } textmodule UML2Java (in uml:uml2) access library variousJavaStuff ("uml2java_include.m2t")

21 21 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Textual syntax If expression Printing Collections, Vars stdout.println (“\t Printing to standard out…”) dclFile.println (”Print to file” + c.name) print (”\n\n print to declared context”) <% escaped output print … … %> c.name <% … %> if (self.name = “Person”) { } else { } var packageNames:List var packageIdList:Hashtable self.ownedMember->forEach(p:uml.Package) { packageNames.add (p.name) packageIdList.put (p.id, p.name) } if (packageIdList.size () > 0) { packageIdList->forEach (s:String | not(s.startsWith(“S”)) { s }

22 22 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Textual syntax Invoking rules Return results uml.TypedElement::getType () : String { if (self.type.name.equalsIgnoreCase("string")) result = "xsd:string" else result = self.type.name } uml.Package::interfacePackages () { if (self.getStereotype() = “Service”){ file (rootdir + self.name.toLower() + ".wsdl") self.wsdlHeader() self.wsdlTypes() self.ownedMember->forEach(i:uml.Interface) { i.wsdlMessages() i.wsdlPortType() i.wsdlBindings() i.wsdlService() } self.wsdlFooter() }

23 23 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) MOFScript extends QVT mappings Relations MappingsGraphical QVTMerge MOFScript imperative imperative procedural procedural side-effects side-effects uni-directional uni-directional object-oriented object-oriented OCL-based OCL-based lexical lexical

24 24 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) MOFScript a transformation language Language for writing model to text transformations Rules / Operations are called explicit (Procedural language) Partly based on the current QVT specification (keeps it within the family) Transforms input models to output text files –Input: UML, ecore or your own based on it Supports EMF meta-models and models as input –UML2, Ecore, etc..

25 25 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) General syntax of a mapping operation From the last QVTMerge-spec: The general syntax for the body of a mapping operation is: mapping X::mappingname ( p1:P1, p2:P2) : r1:R1, r2:R2 when { … } where { … } { init { … } population { … } end { … } }

26 26 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Example1: From UML class diagram to Java

27 27 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Example (1) textmodule UML2Java (in m1:UML) property package_name = "org.sintef.no" property package_dir = "org/sintef/no/" property ext = ".java" property author = "Jon Oldevik" /* * Entrypoint */ main () { m1.ownedMember->forEach(p:uml.Package) p.mapPackage () } /* * mapPackage */ void uml.Package::mapPackage () { p.ownedMember->forEach(c:uml.Class) c.mapClass() }

28 28 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Example (2) void uml.Class::mapClass () { file f1 (name=self.name, ext=”txt”, dir=package_dir, type=”text”) file f2 (“Test.dilldall”) use file f3 (package_dir + self.name + ext) self.standardClassImport () self.standarClassHeaderComment () <% public class %> c.name <% extends Serializable { %> self.ownedAttribute->forEach(p:uml.Property | p.association = "") p.classPrivateAttribute(self) newline(2) self.ownedAttribute->forEach(p:uml.Property | p.association <> "") p.classPrivateAssociations() newline(2) self.ownedAttribute->forEach(p:uml.Property | p.association = "") p.attributeGettersSetters() newline(2) <% } %> }

29 29 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Example (3) // classPrivateAttribute void uml.Property::classPrivateAttribute (uml.Class owner) { <% private String _%> self.name.toLower() self.visibility <% // Type :... %> self.type println(" // This was the private attributes \n\n") }

30 30 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) MOFScript advanced features

31 31 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Change management Proposed metamodel for handling: –Links from a model toward code blocks –Traces from a model to text blocks –Controlled by user unprotect { } –The resulting code will be generated with protected blocks Identifying the start and end the section Code is protected by user-defined tags E.g. comment tags

32 32 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Traceability model

33 33 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) The MOFScript tool

34 34 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) What is MOFScript? An Eclipse plug-in (feature) Developed at SINTEF ICT

35 35 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) MOFScript architecture

36 36 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) MOFScript a model to text tool Provides the means of: –Editing, compiling and executing the transformations Syntax high-lightning Content assist

37 37 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) GUI overview

38 38 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) Tool (continued) Editor –Syntax highlighting –Context sensitive / content assist Outline viewer –View the Preference pages –Setting global preferences File properties –Setting preferences for a single transformation file Actions –Compile, execute, convert to model,…

39 39 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) References

40 40 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) References OMG MOF Model to Text Transformation RFP. bin/apps/doc?ad/ pdf bin/apps/doc?ad/ pdf MOFScript submission. MOFScript tool.

41 41 Based on material developed in ATHENA (IST ) and MODELWARE (IST ) This course has been developed under the funding of the EC with the support of the EC ATHENA-IP Project. Disclaimer and Copyright Notice: Permission is granted without fee for personal or educational (non-profit) use, previous notification is needed. For notification purposes, please, address to the ATHENA Training Programme Chair at In other cases please, contact at the same address for use conditions. Some of the figures presented in this course are freely inspired by others reported in referenced works/sources. For such figures copyright and all rights therein are maintained by the original authors or by other copyright holders. It is understood that all persons copying these figures will adhere to the terms and constraints invoked by each copyright


Download ppt "Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731) 6-1c. MOFScript - Model to Text Transformation,"

Similar presentations


Ads by Google