The Art of Model Transformation with Operational QVT_第1頁
The Art of Model Transformation with Operational QVT_第2頁
The Art of Model Transformation with Operational QVT_第3頁
The Art of Model Transformation with Operational QVT_第4頁
The Art of Model Transformation with Operational QVT_第5頁
已閱讀5頁,還剩33頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 1 - the art of model transformation with operational qvt sergey boyko radomil dvorak alexander igdalov borland software corporation 23 march, 2009the art of model transformation with

2、 operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 2 - qvto key concepts operational qvt (qvto) operates with emf models uses ocl for model navigation main goal - model modification and transformation required an explicit and complete algorithm model-to-model mapping 23 march, 2009t

3、he art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 3 - qvto structure qvtoperational package general structuring elements and top-level constructions imperativeocl package extension to ocl expressions and type system standard library 23 march, 2009

4、the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 4 - qvtoperational package transformation declaration imperative operations (mappings, helpers, queries, constructors) intermediate data object creation and update mechanism trace resolution expre

5、ssions 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 5 - operational transformation 1 modeltype ecore uses /emf/2002/ecore; modeltype uml uses /uml2/2.0.0/uml; transformation ecore2uml(

6、in inmodel : ecore, out outmodel : uml); main() inmodel.rootobjects()epackage-map epackage2model(); mapping epackage:epackage2model() : model name := ; a simple transformation example entry point mappings, etc. transformation signature model parameters metamodels metamodel uri in the emf pa

7、ckage registry 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 6 - operational transformation 2 the content of the transformation definition may be placed within the transformation element: modeltype ecore uses http:/www.eclipse.o

8、rg/emf/2002/ecore; modeltype uml uses /uml2/2.0.0/uml; transformation ecore2uml(in inmodel : ecore, out outmodel : uml) main() inmodel.rootobjects()epackage-map epackage2model(); mapping epackage:epackage2model() : model name := ; 23 march, 2009the art of model transfor

9、mation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 7 - imperative operations define an imperative body enriched signature types of qvto imperative operations entry operation mappings helpers queries constructors 23 march, 2009the art of model transformation with operation

10、al qvt - sergey boyko, radomil dvorak, alexander igdalov- 8 - entry operation an entry operation is the entry point for the execution of a transformation. main() inmodel.rootobjects()epackage-map epackage2model(); typically refers to model parameters and invokes top-level mappings. 23 march, 2009the

11、 art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 9 - helpers and queries a helper is an operation that performs a computation on one or more source objects and provides a result. it is illegal to create or update object instances except for pre-def

12、ined types like sets, tuples, and for intermediate properties. helper epackage:somehelper1() : set(string) if ( = a) then return set b; endif; return set ; a query is a “read-only” helper which is not allowed to create or update any objects. query epackage:getnameatob() : string if

13、 ( = a) then return b; endif; return ; helper epackage:somehelper2() : set(string) = s; query epackage:getname() : string = ; 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 10 - constructors

14、a constructor is an operation that defines how to create and populate the properties of an instance of a given class. constructor eclass:eclass(s : string, op : eoperation) name := s; eoperations += op; calling the constructor: new eclass(“aclass, new eoperation(); 23 march, 2009the art of model tra

15、nsformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 11 - mappings a mapping between one or more source model elements into one or more target model elements. := * mapping ? (:)? ( ? ) (: param_list)? * ? most typical case: mapping : ( ) : mapping ecore:epackage:epacka

16、ge2package() : uml:package name := ; epackage.map epackage2package(); / calling a mapping for a single context epackages-map epackage2package(); / calling a mapping consequently for a collection of contexts 23 march, 2009the art of model transformation with operational qvt - sergey boyko, r

17、adomil dvorak, alexander igdalov- 12 - mapping parameters direction kind mapping epackage:somemapping(in a : eclass) : package name := ; mapping epackage:somemapping(in a : eclass, inout b : eattribute) : model name := + ; := + 123; mapping inout epackage:epack

18、age2package() : package name := + 123; := + 456; mapping parameter direction kind in object passed for read-only access, the default direction inout object passed for update, retains its value out parameter receives new value (not necessarily newly created object) 23

19、march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 13 - mappings when clause mapping epackage:epackage2package() : package when null name := ; = null (condition not satisfied) mapping not executed null retur

20、ned mapping not executed exception thrown when-clause contains a boolean condition invocation: - in standard mode when-clause acts as a guard which filters input parameters a.map epackage2package(); - in strict mode when-clause acts as a pre-condition which must always hold a.xmap epackage2package()

21、; 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 14 - mapping body general form mapping epackage:mymapping() : package init var tmp := self.map othermapping(); if ( = aaa) then result := object package ; endif; populatio

22、n object result : package name := ; end assert ( null); init section computation prior to the instantiation of the outputs population section population of the outputs end (termination) section computations before exiting the body implicit instantiation section instantiation of o

23、ut parameters (results) that still have a null value predefined variables in mappings: self refers to the context result refers to the result 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 15 - mapping body population keyword omi

24、tted mapping epackage:mymapping() : package init var tmp := self.map othermapping(); if ( = aaa) then result := object package ; endif; name := ; end assert ( null); direct access to properties of the result within the population section without the population keyword! o

25、mitted population keyword is the most typical case! 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 16 - overriding mappings simple overriding: mapping enamedelement:makeclass(): eclass name := ne: + ; mapping eclassifier

26、:makeclass(): eclass name := classifier: + ; mapping eclass:makeclass(): eclass name := class: + ; mapping edatatype:makeclass(): eclass name := dt: + ; - overrides override s override s override s 23 march, 2009the art of model transformation with operational qvt - sergey

27、 boyko, radomil dvorak, alexander igdalov- 17 - mapping extension - inherits abstract mapping eclassifier:makeclassifier(): eclassifier name := + 1; mapping eclass:makeclass(): eclass inherits eclassifier:makeclassifier init var tmp := 2; name := name + tmp; evaluation result:

28、= + 12 execution flow: init section (of eclass:makeclass) instantiation section (of eclass:makeclass) inherited mapping(s) (eclassifier:makeclassifier) mapping population and termination sections (of eclass:makeclass) implicit instantiation 23 march, 2009the art of model transformation wit

29、h operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 18 - mapping extension - merges abstract mapping eclassifier:makeclassifier(): eclassifier name := name + 1; mapping eclass:makeclass(): eclass merges eclassifier:makeclassifier init var tmp := 2; name := + tmp; evaluatio

30、n result: = + 21 execution flow: merging mapping (eclass:makeclassifier) merged mapping(s) (eclassifier:makeclassifier) 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 19 - mapping extension - disjuncts mappi

31、ng eclass:makeaclass(): eclass when null and .startswith(a) name := + a; mapping eclass:makebclass(): eclass when null and .startswith(b) name := + b; mapping eclass:makeclass(): eclass disjuncts eclass:makeaclass, eclass:makebclass evaluatio

32、n results: object eclass name := cclass.map makeclass() = null; object eclass name := aclass.map makeclass().name = aclassa; object eclass name := bclass.map makeclass().name = bclassb; execution flow: when-clauses of the disjuncted mappings are evaluated (- of eclass:makeaclass - of eclass:makebcla

33、ss) 2. if all when-clauses are not satisfied null is returned 3. otherwise, the first mapping with a true when-clause is executed 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 20 - traceability concept trace contains information

34、 about mapped objects trace consists of trace records a trace record is created when a mapping is executed trace records keep reference to the executed mapping and the mapping parameter values a trace record is created after the implicit instantiation section of the mapping is finished mapping epack

35、age:mymapping() : package init population end usage: prohibit duplicate execution with the same parameters used in resolve expressions may be serialized after the transformation execution implicit instantiation section a trace record is created here! mappingparam1 param2. mappingparam1 param2. mappi

36、ngparam1 param2. mappingparam1 param2. trace 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 21 - resolve expressions 1 a resolve expression is an expression that inspects trace records to retrieve source or target objects which p

37、articipated in the previous mapping executions. resolve resolves target objects for a given source object inv (invresolve) resolves source objects for a given target object one (resolveone) finds the first matching object in (resolvein) inspects trace records for a given mapping only late (late reso

38、lve) performs resolution and assignment to some model object property after the transformation execution mapping epackage:mymapping() : package 24=16 combinations, e.g. invresolveone or late invresolveonein source objects target objects epackage.resolve(package) 23 march, 2009the art of model transf

39、ormation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 22 - resolve expressions 2 mapping eclassifier:c2c() : eclass name := mapped + ; / somewhere in the code var orig := object eclass name := original ; var mapped := orig.map c2c(); / in some other place var res1

40、 := orig.resolve(eclass); var res2 := resolveonein(eclassifier:c2c, t : eclass | .startswith(mapped ); var res3 := mapped.invresolvein(eclassifier:c2c, eclass); resolve expressions are a useful instrument of retrieving trace information! filtering condition type boolean expression 23 march, 20

41、09the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 23 - object expression an object expression is an inline instantiation facility. object x:x / an explicit variable here object y / no referred variable here object x: / the type of x is skipped

42、here when already known if x exists then it is updated, otherwise created and updated object epackage name := pack; nsuri := ; eclassifiers += object eclass name := clazz; 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igda

43、lov- 24 - model extents a model extent is a container for model objects. for each model parameter there is a model extent. modeltype ecore uses /emf/2002/ecore; transformation transf(in m : ecore, out x : ecore, out y : ecore); main() var a:= object epackagex name := a ; var b:=

44、 object epackagey name := b; ; mapping eclass:toclass() : eclassy name := ; refer to model extents with model_parameter_name 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 25 - intermediate properties an intermediate pro

45、perty is a property defined as an extension of the type referred by the context. typically defined as class extensions of model metaclasses created temporarily by a transformation not a part of the output used for intermediate calculations associated with the instances of the extended class intermed

46、iate property eclass:intermprop : string; main() object eclass name := original; intermprop := abc ; 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 26 - intermediate classes an intermediate class is a class created temporarily by

47、 a transformation to perform some needed calculation but which is not part of the expected output. intermediate class myepackage extends epackage myname : string; mapping eclassifier:c2c() : eclass object myepackage name := name; myname := somethoughtfulname; 23 march, 2009the art of model transform

48、ation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 27 - imperativeocl package assignments variables loops (while, foreach) loop interrupt constructs (break, continue) conditional execution workflow convenient shorthand notation mutable collections 23 march, 2009the art of

49、model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 28 - assignments assignment to variables assignment to properties (including complex nested constructions) mapping eclassifier:c2c() : eclass name := ; mapping epackage:p2p() : epackage name := nspr

50、efix := nsuri := aaa; eclassifiers += self.eclassifiers-map c2c(); eclassifiers += object eclass name := a ; esuperpackage.esuperpackage.esubpackages-any(true).name := a; 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 29 - variab

51、les in qvto ocl variables in let expression: let a : string = aa in /*some expression with a*/; qvto extends ocl with variable initialization expressions and assignments to variables: var a : string := a; / full notation var b := b; / type deduced from the initialization expression var c : string; /

52、 default value assigned mapping epackage:p2p() : epackage var tmp := a + ; / variable declaration and initialization name := tmp; / variable read access tmp := tmp + b / variable modification eclassifiers += self.eclassifiers-map c2c(); eclassifiers += object eclass name := tmp; / another a

53、ccess 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 30 - while loop ocl iterator expressions iterate through collections and cannot be interrupted by break, continue or return statements. they are rather specific, e.g.: collecti

54、on-collect( v : type | expression-with-v ) while loop is a java-like imperative cycle that can be interrupted by break, continue and return. mapping epackage:p2p() : epackage while (i := 0; i 10) eclassifiers += object eclass ; i := i + 1; ; mapping epackage:p2p() : epackage var i : integer := 0; wh

55、ile (i foreach(i) res := res + i; ; abc-foreach(i | i = b) / foreach with a condition res := res + i; ; forone equivalent to foreach with a break statement: abc-foreach(i | i = b) res := res + i; break; ; abc-forone(i | i = b) res := res + i; ; 23 march, 2009the art of model transformation with oper

56、ational qvt - sergey boyko, radomil dvorak, alexander igdalov- 32 - loop interruption break and continue break and continue used within while, foreach loops and imperative iterators var i : integer := 0; while (i 10) if (i = 3) then i := i + 2; continue; endif; if (i = 8) then break; endif; object e

57、class ; i := i + 1; ; 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 33 - operation interruption - return return used to interrupt imperative operations query epackage:getname() : string if ( = a) then return b; endif; i

58、f ( = b) then return c; endif; return ; 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander igdalov- 34 - conditional execution if then ; else ; endif; if then else endif; switch-expression if-expression switch case (cond1) case (cond2) ; else ; ; var a : collection(sometype) := coll-switch(i) case (cond_with_i_1) case (cond_with_i_2) ; else ; ; 23 march, 2009the art of model transformation with operational qvt - sergey boyko, radomil dvorak, alexander

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論