Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTO]Clone Operation
[QVTO]Clone Operation [message #103052] Tue, 07 April 2009 19:33 Go to next message
Eclipse UserFriend
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 21:30 Go to previous message
Sergey Boyko is currently offline Sergey BoykoFriend
Messages: 171
Registered: July 2009
Senior Member
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.!!
>
>
>
>
Previous Topic:Collecting elements from called rule
Next Topic:Extract an ATL mode.ecorel to an ATL file.atl
Goto Forum:
  


Current Time: Fri Sep 20 19:18:48 GMT 2024

Powered by FUDForum. Page generated in 0.03546 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top