[QVTO]Clone Operation [message #103052] |
Tue, 07 April 2009 15:33  |
Eclipse User |
|
|
|
Originally posted by: mariam.xxxxx.xxx
Hi,
I am starting to learn how to use qvto to write some transformations. I
want to use the clone and deepclone methods to copy an existing model
(source)to another model (target) without overwriting the target model.
I tried using the deepclone method and it works just fine, but the problem
i am facing is that it erases the target model and overwrite it completly.
here is how my transformation look like:
============================================================ =
transformation m2m(in source:UML,inout target:UML);
main(){
--here I specify where exactly I want the model to be copied.
-- which is inside package pack1 in target model
target.objectsOfType(Package)[name='Pack1']->map addModel();
}
mapping inout Package::addModel()
{
init{
--here I specify which package in the source model I want to copy
-- which is pack2.
var a:=source.objectsOfType(Package)![name='pack2'];
a.deepclone().oclAsType(Class);
}
}
============================================================
when I run this transformation the target model is overwritten with the
source model. What am I doing wrong!! how can i modify this to make the
source model appended to the target model.!!
|
|
|
Re: [QVTO]Clone Operation [message #103064 is a reply to message #103052] |
Tue, 07 April 2009 17:30  |
Eclipse User |
|
|
|
Hi mariam,
Newly created (deepcloned) package is added to the target resource as
yet another root object. And it appears as the first element in
appropriate uml file, all root elements existed before the
transformation's execution are just stayed as is but get +1 position
shifted.
In order to add copied package to the existed model you can modify
init{} section of the mapping as follows:
var a:=source.objectsOfType(Package)![name='pack2'];
self.nestedPackage += a.deepclone().oclAsType(Package);
Regards,
Sergey.
> Hi,
> I am starting to learn how to use qvto to write some transformations. I
> want to use the clone and deepclone methods to copy an existing model
> (source)to another model (target) without overwriting the target model.
> I tried using the deepclone method and it works just fine, but the
> problem i am facing is that it erases the target model and overwrite it
> completly. here is how my transformation look like:
> ============================================================ =
> transformation m2m(in source:UML,inout target:UML);
> main(){
> --here I specify where exactly I want the model to be copied.
> -- which is inside package pack1 in target model
> target.objectsOfType(Package)[name='Pack1']->map addModel();
> }
> mapping inout Package::addModel()
> {
> init{
> --here I specify which package in the source model I want to copy
> -- which is pack2.
> var a:=source.objectsOfType(Package)![name='pack2'];
> a.deepclone().oclAsType(Class);
> }
> }
>
> ============================================================
> when I run this transformation the target model is overwritten with the
> source model. What am I doing wrong!! how can i modify this to make the
> source model appended to the target model.!!
>
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.13400 seconds