Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] Created Objects don't appear in their right position
[QVTo] Created Objects don't appear in their right position [message #516575] Wed, 24 February 2010 12:49 Go to next message
PBarendrecht is currently offline PBarendrechtFriend
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:
http://www.redpanda.nl/Update1.png

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:
http://www.redpanda.nl/Update2.png

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 Smile
Re: [QVTo] Created Objects don't appear in their right position [message #516756 is a reply to message #516575] Thu, 25 February 2010 00:26 Go to previous messageGo to next message
Alex Mising name is currently offline Alex Mising nameFriend
Messages: 51
Registered: August 2009
Member
Try
Updates += self.Updates.map toUpdates2()
Re: [QVTo] Created Objects don't appear in their right position [message #516823 is a reply to message #516575] Thu, 25 February 2010 09:55 Go to previous messageGo to next message
PBarendrecht is currently offline PBarendrechtFriend
Messages: 36
Registered: November 2009
Location: Eindhoven, Netherlands
Member
Hi Alex,

Thanks for your suggestion, however it doesn't matter. With the "+=" operator one adds something to a set (preserving existing values), with ":=" one assigns something entirely new to a set, therefore replacing the existing values.

In this case, the set is empty so it doesn't matter wheter I use += or :=.
Re: [QVTo] Created Objects don't appear in their right position [message #517019 is a reply to message #516823] Thu, 25 February 2010 18:38 Go to previous messageGo to next message
Alex Mising name is currently offline Alex Mising nameFriend
Messages: 51
Registered: August 2009
Member
Right. What I had in mind is flattening. How about
Updates := self.Updates.map toUpdates2() -> flatten();

Without flatten() the type of the expression on the right is
Sequence(OrderedSet(Update2))
Re: [QVTo] Created Objects don't appear in their right position [message #517048 is a reply to message #516575] Thu, 25 February 2010 21:48 Go to previous messageGo to next message
PBarendrecht is currently offline PBarendrechtFriend
Messages: 36
Registered: November 2009
Location: Eindhoven, Netherlands
Member
Thanks again for your help, but the type on the right is just "OrderedSet(Update2)".
If I had used "self.Updates->map" (please notice the arrow instead of a dot), you would be right.
However, it would not be logical to use an arrow since there can only be 1 update object in the source model (or 0), so the result won't be a set.

Moreover, I assume the QVTo compiler would not accept these conflicting types.

I didn't mention it explicitly in my first post, but there is no warning or error whatsoever. The Update2 objects just appear in a wrong position Smile
Re: [QVTo] Created Objects don't appear in their right position [message #517460 is a reply to message #516575] Sun, 28 February 2010 11:23 Go to previous messageGo to next message
PBarendrecht is currently offline PBarendrechtFriend
Messages: 36
Registered: November 2009
Location: Eindhoven, Netherlands
Member
Ok, to simplify the problem I created two very small metamodels, MMA and MMB (they are not very logical, but illustrate the problem):

A:
http://www.redpanda.nl/MMA.png

B:
http://www.redpanda.nl/MMB.png

My inputmodel contains 4 persons:
http://www.redpanda.nl/InstA.png

My Transformation:

modeltype MMA uses "...";
modeltype MMB uses "...";

transformation NewTransformation(in A:MMA, out B:MMB);

main() {
	log("#RootObjects:" + A.rootObjects()[Fam]->size().toString());
	A.rootObjects()[Fam]->map StartTrans();
}

mapping MMA::Fam::StartTrans() : MMB::Family {
  Member := self.ConsistsOf.map toMembers();
}

mapping MMA::Members::toMembers() : OrderedSet(MMB::Person) {

  self.Contain->forEach(Exp) {
  	result += object MMB::Person { Naam := Exp.Name };
    log("Name = " + Exp.Name);
  }
  	
}


This should work (?), but the Persons in the target model don't appear as children of Family (i.e. as a member), but on the same level as Family:

http://www.redpanda.nl/InstB.png

[Updated on: Thu, 18 March 2010 19:59]

Report message to a moderator

Re: [QVTo] Created Objects don't appear in their right position [message #517688 is a reply to message #517460] Mon, 01 March 2010 17:32 Go to previous messageGo to next message
Siegfried Nolte is currently offline Siegfried NolteFriend
Messages: 48
Registered: August 2009
Member
Hi Pieter,

your solution doesn't look that bad. I don't know exactly, where the error is. But I choosed a solution using the iterate instead your forEach-construct and that works.

modeltype MMA uses "http:///MMA.ecore";
modeltype MMB uses "http:///MMB.ecore";

transformation family(in A:MMA, out B:MMB);

main() 
{
   A.objects()[MMA::Family]->mapFamily();
}

mapping MMA::Family::mapFamily() : MMB::Family
{
	consistsOf := getElements (self.consistsOf.contain);
}

query getElements( el : Set(MMA::Person) ) : Set (MMB::Person) 
{
    var bset : Set (MMB::Person) := null;
    bset := el->iterate ( i : MMA::Person; r : Set(MMB::Person) = OrderedSet{} |  
                          r->including(object MMB::Person { name := i.name; }) );
	return bset;
}


Mind, that my metamodels are a bit different concernig to the names. I hope, it works with you as well. My platform ist Eclipse Modeling Workbench 3.4. with QVTO 1.0.0.

Siegfried
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 Go to previous message
PBarendrecht is currently offline PBarendrechtFriend
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:
http://www.redpanda.nl/InstB2.png

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

Previous Topic:not
Next Topic:ATL
Goto Forum:
  


Current Time: Thu Apr 25 00:47:24 GMT 2024

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

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

Back to the top