[QVTO] Problems with resolve and update [message #86392] |
Fri, 11 July 2008 10:16  |
Eclipse User |
|
|
|
Originally posted by: stenzel.informatik.uni-augsburg.de
Hi,
I seem to 'loose' elements if I modify them after I retrieved them with
resolve.
In the following program I would expect that mp.packagedElement contains a
class, but that is not the case.
Is this a bug or a feature?
Thanks for any help,
Kurt
modeltype UML uses 'http://www.eclipse.org/uml2/2.1.0/UML';
transformation updateTest();
mapping main() {
init {
this.runTest();
}}
query OclAny::runTest() : OclVoid {
var o := object UML::Class { name := 'myClass'; };
var p := object UML::Package { packagedElement += o; };
p.map copyPackage();
o.map copyClass();
var mp := p.updatePackage();
o.name := 'yourClass';
log('package', mp.packagedElement.name);
return null;
}
mapping UML::Package::copyPackage() : Package { }
mapping UML::Class::copyClass() : Class { }
query UML::Package::updatePackage() : Package {
var x := self.resolveone(Package);
x.packagedElement :=
self.packagedElement.resolveone(PackageableElement)->asSet();
return x;
}
|
|
|
|
|
Re: [QVTO] Problems with resolve and update [message #86857 is a reply to message #86712] |
Tue, 22 July 2008 08:43  |
Eclipse User |
|
|
|
Hi Kurt,
Just a tip for creating a copy of existing object with easy custom =
modifications.
mapping UML::Class::copyClass() : UML::Class {
init {
-- create a deep copy of the source object
-- and assign to the result explicitly
result :=3D self.deepclone().oclAsType(UML::Class);
}
-- decorate the original name
name :=3D result.name + '_aSuffix';
}
Also, I would recommend to you using the transformation signature and =
signatureless main(),
which is actually the standard way. It is our fault that the compiler do=
es =
not complain
(this is a legacy construct still supported).
Then you will get access to model parameters and can query then for =
objects, etc.
See the example bellow:
/*
* Two modeltypes are declared. The http NS URIs correspond to those us=
ed =
to register the
* Ecore models in the environment. Alternatively, a workspace metamode=
l =
may be used
* in conjunction with mappings defined in the project properties.
*/
modeltype UML uses =
' http://www.eclipse.org/qvt/1.0.0/Operational/examples/simple uml';
modeltype RDB uses =
'http://www.eclipse.org/qvt/1.0.0/Operational/examples/rdb';
/*
* The transformation signature declares that a UML modeltype is requir=
ed =
as input, while an RDB
* modeltype is produced as an output. The UML modeltype is referenced=
as =
'uml' throughout the
* transformation definition, while no name is needed for the output RD=
B =
modeltype. Note that OCL
* type and namespace notation are used in operational QVT (: and :: =
respectively).
*/
transformation Simpleuml_To_Rdb(in uml : UML, out rdb : RDB);
/*
* The main entry point of the transformation. The 'uml' reference to =
the =
input UML modeltype
* instance is used to collect all rootObjects() of type Model. The =
rootObjects() operation
* is available on all QVT Model objects (extents) and returns those =
objects found at the
* root of the input model. The [UML::Model] statement following the c=
all =
to rootObjects()
* is shorthand notation for the imperative select (xselect) construct =
=
where the condition is
* a type expression, which effectively performs a oclIsKindOf(UML::Mod=
el) =
with type recasting
* as a sequence.
*
* The invocation of the model2RDBModel() mapping is done using an -> =
operator, which is a
* shorthand notation for the imperative collect (xcollect) construct. =
=
Alternatively, it could
* be written as uml.rootObjects()[UML::Model]->xcollect(a | a.map =
model2RDBModel());
*/
main() {
uml.rootObjects()[UML::Model]->map model2RDBModel();
}
You can describe the desired behavior and I could try to help you.
Regards,
/Radek
On Fri, 18 Jul 2008 14:49:51 +0200, Kurt Stenzel =
<stenzel@informatik.uni-augsburg.de> wrote:
> Hi Sergey,
>
> sorry, my fault. My program does not create the effect I wanted.
>
> Still I have strange effects. I try to copy a UML model by creating
> the result objects, and then updating them with the help of resolve.
> It turns out that the order in which the elements are updated seems
> to be important: If I update all UML::Class objects before I update
> the UML::Properties, the properties are no longer contained in the
> Class objects, but appear on the toplevel as siblings of UML::Model.
> If I do it the other way round they are contained in the Class (I
> view the result with the EML model editor).
>
> But probably it's a bug in my copy transformation ...
>
> Thanks for your help,
>
> Kurt
>
>
-- =
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
|
|
|
Powered by
FUDForum. Page generated in 0.06986 seconds