based on material developed in athena (ist-507849) and modelware (ist-511731) 6-1c. mofscript -...

41
Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731) 6-1c. MOFScript - Model to Text Transformation <Presenter> <Company>, <Country> <E-mail>

Upload: kaylyn-hopes

Post on 15-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

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

Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

6-1c. MOFScript - Model to Text

Transformation

<Presenter>

<Company>, <Country><E-mail>

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

2Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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

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

3Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Background

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

4Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

The MOF model to text transformation RFP

• The Model to Text Transformations RFP (ad/2004-04-07) 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.

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

5Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Consortium

• Submitters: (supporter)

• Also supported by the following MODELWARE partners:

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

6Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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

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

7Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Introducing the MOFScript language

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

8Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

What is MOFScript?

• The MOFScript tool is an implementation of the MOFScript model to text transformation language– http://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: ...

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

9Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

MOFScript in action

Documentation

UML

MOFScript

Program code

XMLRDBMS

BPMN

MOF MODELSMOF MODELS Lexical outputLexical output

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

10Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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)

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

11Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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.

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

12Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Basic QVT extensions

MappingModule

(from QVT::MappingRules)

MT2Module M2TDescriptordescriptor+

M2TRule

0..1ownedM2TRules+

*

M2TRuleBody

0..1

ruleBody+ 0..1

Created with Poseidon for UML Community Edition. Not for Commercia l Use.

M2TRuleBody

MappingBody

(from QVT::MappingRules)

Section

(from QVT::MappingRules)0..1 populationSection+

*

M2TSection

Expression

(from QVT::Expression)0..1 content+

*

0..1 +populationSection+

*

{refinement}

Created with Poseidon for UML Community Edition. Not for Commercia l Use.

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

13Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Text transformation

MappingOperation

(from QVT::QVTMappingOperations)

OperationalTransformation

(from QVT::QVTMappingOperations )

owner+

operations+

*

MappingBody

(from QVT:: )body+

0..1

TextTransformation TextMappingRuleTextMappingBody

0..1 ownedTextMappings+

*

{refinment}

0..1 ruleBody+

0..1

{refinement}

Created with Poseidon for UML Community Edition. Not for Commercial Use.

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

14Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Mapping body

TextMappingBody

MappingBody

(from QVT::QVTMappingOperations)

MappingSection

(from QVT::QVTMappingOperations )0..1 populationSection+

*

TextMappingSection

OclExpression

(from QVT::QVTBase)

0..1 +populationSection+

*

{refinement}

0..1 content+

*

Created with Poseidon for UML Community Edition. Not for Commercial Use.

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

15Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Variables and constants

VariableDeclaration

(from QVT::QVTBase)VariableInitExp

(from QVT::QVTMappingOperations)

OclExpression

(from QVT::QVTBase)

TextTransformation

Property

(from MOF 2.0::EMOF)localProperty+

*

(from QVT::Queries::Module)

localVariables+

*/(from QVT::MappingRules)

VariableOwner

TextMappingRule

0..1 referredVariable+

Created with Poseidon for UML Community Edition. Not for Commercial Use.

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

16Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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

FileDeviceExpression

+directory:String[0..1]

+fileName:String

+fileExt:String

+fileType:String

EscapedOutputExpression

+escapedText:String

OclExpression

(from QVT::QVTBase)

OutputExpression

+outputCommand:String={'print', 'println'}0..1

outputBody+

outputContext+

0..1OutputDeviceExpression

+refName:String[0..1]

+properties:Property[*]

StdOutDeviceExpression

Created with Poseidon for UML Community Edition. Not for Commercial Use.

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

17Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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”) {

<% This is the person type %>

} else {

<% This is not a person type %>

}

BlockExp

(from QVT::QVTMappingOperations )

VariableDeclaration

(from QVT::QVTBase)

OclExpression

(from QVT::QVTBase)

blockOwner+

0..1

body+

*

IfExp

(from QVT::QVTBase)

ForEachExpiterators+

1..*0..1 condition+

0..1

Created with Poseidon for UML Community Edition. Not for Commercial Use.

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

18Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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

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

19Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Details of the MOFScript language

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

20Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Textual syntax

• Textmodule• Rules• Iterators• Files• Escaped output

<%public class %> c.name <% extends

Serializable {%>

file f2 (c.name + “.java”)<% package %> c.ownerPackage.name <%;%>f2.println (“public class” + c.name);

uml.Package::mapPackage () { self.ownedMember->forEach(c:uml.Class) <% <class name=”%> c.name <% “/> %>}

textmodule UML2Java (in uml:uml2)access library variousJavaStuff ("uml2java_include.m2t")

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

21Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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”) { <% This is the person type %>} else { <% This is not a person type %>}

var packageNames:Listvar packageIdList:Hashtableself.ownedMember->forEach(p:uml.Package) { packageNames.add (p.name) packageIdList.put (p.id, p.name)}

if (packageIdList.size () > 0) { <% Listing the package names that does not start with ‘S’ %> packageIdList->forEach (s:String | not(s.startsWith(“S”)) { <% Package: %> s }}

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

22Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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() }}

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

23Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

MOFScript extends QVT mappings

Relations Mappings Graphical

QVTMerge

MOFScript• imperativeimperative• proceduralprocedural• side-effectsside-effects• uni-directionaluni-directional• object-orientedobject-oriented• OCL-basedOCL-based• lexicallexical

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

24Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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..

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

25Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

General syntax of a mapping operation

From the last QVTMerge-spec:The general syntax for the body of a mapping operation is:

mapping <dirkind0> X::mappingname(<dirkind1> p1:P1, <dirkind2> p2:P2) : r1:R1, r2:R2

when { … }where { … }

{init { … }population { … }end { … }

}

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

26Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Example1: From UML class diagram to Java

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

27Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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() }

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

28Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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 {

%>

<% // Attributes %> 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)<%

}%>

}

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

29Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Example (3)

// classPrivateAttribute

void uml.Property::classPrivateAttribute (uml.Class owner) {

<%

private String _%> self.name.toLower() <% ; %> <% // Visibility:%>

self.visibility <%

// Type : ... %> self.type

println(" // This was the private attributes \n\n")

}

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

30Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

MOFScript advanced features

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

31Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Change management

• Proposed metamodel for handling: – Links from a model toward code blocks– Traces from a model to text blocks– Controlled by user

unprotect {

<% // User writes code here %>

}

– 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

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

32Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

Traceability model

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

33Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

The MOFScript tool

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

34Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

What is MOFScript?

• An Eclipse plug-in (feature)• Developed at SINTEF ICT

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

35Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

MOFScript architecture

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

36Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

MOFScript a model to text tool

• Provides the means of:– Editing, compiling and

executing the transformations

• Syntax high-lightning• Content assist

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

37Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

GUI overview

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

38Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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,…

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

39Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

References

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

40Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

References

• OMG MOF Model to Text Transformation RFP. http://www.omg.org/cgi-bin/apps/doc?ad/04-04-07.pdf

• MOFScript submission. http://www.omg.org/cgi-bin/apps/doc?ad/05-05-04.pdf • MOFScript tool. http://www.modelbased.net/mofscript

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

41Based on material developed in ATHENA (IST-507849) and MODELWARE (IST-511731)

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 [email protected]. In other cases please, contact at the same e-mail 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 holder.