Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Multiple source objects to single target object
Multiple source objects to single target object [message #1796628] Tue, 16 October 2018 15:21 Go to next message
Gururaj Maddodi is currently offline Gururaj MaddodiFriend
Messages: 7
Registered: October 2018
Junior Member
Hello,

I'm new to QVT. The problem I have is to map several source objects to one target object based on some criteria such as same attribute value. An example is as below,

Source and target meta-models are attached. Now when transforming, all objects of ClassB with same value for attribute name should be in one ClassE object. So, basically number of source objects for ClassB is greater than that of ClassE after transformation. However, the number of objects of ClassC should be same as that of ClassF after transformation.

I'm not sure how to achieve this. Any suggestion will be very helpful.
Re: Multiple source objects to single target object [message #1796687 is a reply to message #1796628] Wed, 17 October 2018 15:26 Go to previous message
Gururaj Maddodi is currently offline Gururaj MaddodiFriend
Messages: 7
Registered: October 2018
Junior Member
In order to make it clear I added another attribute to ClassB called type of datatype Estring in the source meta-model. I tried the following method as in the code below,

main() {
Source.rootObjects()[A] -> map AToD();
}

mapping A::AToD() : D{
classe := self.classb -> map toE();
}

mapping ClassB :: toE() : ClassE
when{self.name<> "BInst2"}
{
name := self.type;
self.container().allSubobjectsOfKind(MM::ClassB) -> forEach(Var){
if(self.toString() <> Var.toString()){
if(self.type = Var.type){
classf := Var.classc -> map tof();
}endif;
}endif;
};
classf := self.classc-> map tof();
}

mapping ClassC::tof() : ClassF {
name := self.name;
}

In my source model instance I have three ClassB objects, 1: name=BInst1, type=T1, 2: name=BInst2, type=T1, and 3: name=BInst3, type=T2. Each of those have one object of ClassC, 1: name=CInst1, 2: name=CInst2, and 3: name=CInst3 respectively.

When I execute this, in the target model I have two objects of ClassE as wanted. But in target object (ClassE) with two source objects (ClassB), the target child Class (ClassF) is just one (CInst1), whereas in source model there are two (CInst1 and CInst2). The other one is on same level as ClassD.

If I change the placement of "classf := self.classc-> map tof();" before the forEach, I get CInst2 as child under ClassE and CInst2 on same level as ClassD.

Is there any way to rectify this? I tried this method as I could not find any documentation about it. I'm aware if there is any better method. Please kindly help.
Previous Topic:Announce QVTo 3.9.0
Next Topic:Error while generating Diagram Editor Gen Model in Luna SR2
Goto Forum:
  


Current Time: Tue Dec 10 20:58:17 GMT 2019

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

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

Back to the top