[QVTo] Created Objects don't appear in their right position [message #516575] |
Wed, 24 February 2010 12:49 |
PBarendrecht Messages: 36 Registered: November 2009 Location: Eindhoven, Netherlands |
Member |
|
|
Hi all,
I am trying to transform a metamodel M1 in an other one, M2.
To simplify the metamodel, let's just say that a class C1 in M1 can be updated. It contains 0..1 updates.
This update class Update1 contains 1..* variables (to be updated) and 1..* expressions.
C1:
The class C2 (which will be transformed from C1) can be updated as well, but contains 0..* updates. This update class, Update2, just contains 1 variable and 1 expression.
C2:
In my transformation, I transform the Update1 Class which returns a set of Update2 classes (remember, the Update1 class contains ALL updates while Update2 just updates a single variable).
Updates := self.Updates.map toUpdates2();
--
mapping Update1::toUpdates2() : OrderedSet(Update2) {
--Count the VariableExpressions. For each one, create an object and add it to result.
var NewUpdate: Update2;
NewUpdate := object Update2 {
--Some Attributes that I didn't show. These need to be mapped too.
};
result += NewUpdate;
}
The above code actually generates objects, but puts them not in the right place (i.e. as child of the C2 Class), but on the same level als the C2 class (so, as siblings).
Why does this happen?
---
Another question just came to my mind, can somebody give an example of a post-condition for a mapping? I mean the "where" clausule. In the official MOF QVT document it is mentioned, but there are no examples.
Two more yes/no questions:
- Is the exception bug (from xmap) already fixed? http:// www.eclipse.org/forums/index.php?t=msg&th=161599&sta rt=0&
- I came accross a topic about a function like allSubobjectsOfType. Somebody stated that when using this function, the order of the objects (as in the model) is not maintained, is this already solved? I cannot find the topic at the moment...
Thanks a lot
|
|
|
|
|
|
|
|
|
Re: [QVTo] Created Objects don't appear in their right position [message #517993 is a reply to message #516575] |
Tue, 02 March 2010 16:56 |
PBarendrecht Messages: 36 Registered: November 2009 Location: Eindhoven, Netherlands |
Member |
|
|
Hi Siegfried,
Thanks for your reply! I replaced my mapping with a query like you did, it works like a charm.
This is the updated code:
...
mapping MMA::Fam::StartTrans() : MMB::Family {
--Member := self.ConsistsOf.map toMembers();
Member := QueryToMembers( self.ConsistsOf );
}
query QueryToMembers ( Parameter: Members ) : OrderedSet(MMB::Person) {
var Persons: OrderedSet(MMB::Person);
Parameter.Contain->forEach(Exp) {
Persons += object MMB::Person { Naam := Exp.Name };
};
return Persons;
}
Result:
I don't have much experience with queries yet, can you map properties of objects within your query?
For instance, a person could have hobbies (hobby objects contained in the Person class, this would be an expansion of my model). Is it possible to map these hobby-objects from within the query?
[Edit]Hmm, I just tried to map a property (Pastime to Hobbies) within a query, it is possible:
Persons += object MMB::Person { Naam := Exp.Name; Hobbies := Exp.Pastime->map toHobbies(); };
[Updated on: Tue, 02 March 2010 19:13] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.05317 seconds