Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] Mapping 1 to many objects results in output object appearing as siblings(When transforming Input-object A to ouput objects B and B', B and B' appear at wrong position)
[QVTo] Mapping 1 to many objects results in output object appearing as siblings [message #538010] Fri, 04 June 2010 13:44 Go to next message
C. Kopf is currently offline C. KopfFriend
Messages: 37
Registered: November 2009
Member
Hello again everybody,

When trying to transform one input object to many (e.g. two) output objects i came along the following problem:

The output-objects are all placed as siblings to the first generated object.

For mappings of a single object to a set of output-object Pieter mentioned this problem already here: http:// www.eclipse.org/forums/index.php?t=msg&goto=517460&# msg_517460

I also tried the work-around wich Pieter used, but the rsults are still the same.

Here are more details:


//Entry-point
mapping AUTOSARGenIA::ARPackage::arpackage2module() : Module {
-- ...
	declarations += self.elements[SenderReceiverInterface]->forEach(SRInterface) {generateMessagePortTypes(SRInterface)->asOrderedSet()};
-- ...
}

// the one2many transformation:
query generateMessagePortTypes(in interface:AUTOSARSwcPorti::SenderReceiverInterface) : Set(MessagePortType){
	var resultPorts:Set(MessagePortType);
	resultPorts += interface.map senderReceiverInterface2messagePortType(true);
	resultPorts += interface.map senderReceiverInterface2messagePortType(false);
	return resultPorts;
}

mapping AUTOSARSwcPorti::SenderReceiverInterface::senderReceiverInterface2messagePortType(in isProvided:Boolean) : MessagePortType{
	var direction:String;
	if (isProvided)
		then direction := "OUT"
		else direction := "IN"
		endif;
	name := self.shortName+direction;
	comSpec := self.dataElements.map dataElementProtoType2messageAndStreamComSpec()->asOrderedSet();
}


in the resulting model all MessagePortTypes occure as siblings on top-level instead of beeing children to their parent module. Same problem occured, as Pieter already mentioned, when directly using a mapping with signature:

mapping AUTOSARSwcPorti::SenderReceiverInterface::senderReceiverInterface2messagePortTypes : Set(MessagePortType)


and also, when generating the MessagePorttypes directly inside the Query:

query generateMessagePortTypes(in interface:AUTOSARSwcPorti::SenderReceiverInterface) : Set(MessagePortType){
	var resultPorts:Set(MessagePortType);
	resultPorts += object MessagePortType{name:=interface.shortName+"IN"};
	resultPorts += object MessagePortType{name:=interface.shortName+"OUT"};
	return resultPorts;
}



Re: [QVTo] Mapping 1 to many objects results in output object appearing as siblings [message #538025 is a reply to message #538010] Fri, 04 June 2010 14:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dhendriksREMOVE_THIS.tueREMOVE.THIS.nl

Hello C. Kopf,

> //Entry-point
> mapping AUTOSARGenIA::ARPackage::arpackage2module() : Module {
> -- ...
> declarations +=
> self.elements[SenderReceiverInterface]->forEach(SRInterface)
> {generateMessagePortTypes(SRInterface)->asOrderedSet()};
> -- ...
> }

If you create new objects and don't contain them anywhere in other
objects, they end up as top-level (root) objects in the output. So,
somehow your objects are not contained. Maybe change the above to this:

mapping AUTOSARGenIA::ARPackage::arpackage2module() : Module {
-- ...
self.elements[SenderReceiverInterface]->forEach(SRInterface)
{
declarations += generateMessagePortTypes(SRInterface)->asOrderedSet()
};
-- ...


I not sure this helps, but you can try it...


Dennis





C. Kopf wrote:
> Hello again everybody,
>
> When trying to transform one input object to many (e.g. two) output
> objects i came along the following problem:
>
> The output-objects are all placed as siblings to the first generated
> object.
>
> For mappings of a single object to a set of output-object Pieter
> mentioned this problem already here:
> http://www.eclipse.org/forums/index.php?t=msg&goto=51746 0&#msg_517460
>
> I also tried the work-around wich Pieter used, but the rsults are still
> the same.
>
> Here are more details:
>
>
>
> //Entry-point
> mapping AUTOSARGenIA::ARPackage::arpackage2module() : Module {
> -- ...
> declarations +=
> self.elements[SenderReceiverInterface]->forEach(SRInterface)
> {generateMessagePortTypes(SRInterface)->asOrderedSet()};
> -- ...
> }
>
> // the one2many transformation:
> query generateMessagePortTypes(in
> interface:AUTOSARSwcPorti::SenderReceiverInterface) : Set(MessagePortType){
> var resultPorts:Set(MessagePortType);
> resultPorts += interface.map
> senderReceiverInterface2messagePortType(true);
> resultPorts += interface.map
> senderReceiverInterface2messagePortType(false);
> return resultPorts;
> }
>
> mapping
> AUTOSARSwcPorti::SenderReceiverInterface::senderReceiverInte rface2messagePortType(in
> isProvided:Boolean) : MessagePortType{
> var direction:String;
> if (isProvided)
> then direction := "OUT"
> else direction := "IN"
> endif;
> name := self.shortName+direction;
> comSpec := self.dataElements.map
> dataElementProtoType2messageAndStreamComSpec()->asOrderedSet();
> }
>
>
> in the resulting model all MessagePortTypes occure as siblings on
> top-level instead of beeing children to their parent module. Same
> problem occured, as Pieter already mentioned, when directly using a
> mapping with signature:
>
> mapping
> AUTOSARSwcPorti::SenderReceiverInterface::senderReceiverInte rface2messagePortTypes
> : Set(MessagePortType)
>
> and also, when generating the MessagePorttypes directly inside the Query:
>
>
> query generateMessagePortTypes(in
> interface:AUTOSARSwcPorti::SenderReceiverInterface) : Set(MessagePortType){
> var resultPorts:Set(MessagePortType);
> resultPorts += object MessagePortType{name:=interface.shortName+"IN"};
> resultPorts += object MessagePortType{name:=interface.shortName+"OUT"};
> return resultPorts;
> }
>
>
>
>
Re: [QVTo] Mapping 1 to many objects results in output object appearing as siblings [message #538221 is a reply to message #538025] Sun, 06 June 2010 16:36 Go to previous messageGo to next message
Sergey Boyko is currently offline Sergey BoykoFriend
Messages: 162
Registered: July 2009
Senior Member
Hi Dennis,

You're absolutely right, the problem is that 'forEach()' expression was
used incorrectly.

QVT specification in Section 8.2.2.6 "ForExp" states the following:

A _for expression_ is an imperative loop expression that iterates over
a source collection evaluating an expression for each
element of the collection that satisfies a given condition. It returns
the _null_ value.

So output result of construction like
someCollection->forEach(i) {someMapping(..)};
is always null.
All assignments should be done inside loop body.

Regards,
Sergey.


Dennis Hendriks wrote:
> Hello C. Kopf,
>
> > //Entry-point
> > mapping AUTOSARGenIA::ARPackage::arpackage2module() : Module {
> > -- ...
> > declarations +=
> > self.elements[SenderReceiverInterface]->forEach(SRInterface)
> > {generateMessagePortTypes(SRInterface)->asOrderedSet()};
> > -- ...
> > }
>
> If you create new objects and don't contain them anywhere in other
> objects, they end up as top-level (root) objects in the output. So,
> somehow your objects are not contained. Maybe change the above to this:
>
> mapping AUTOSARGenIA::ARPackage::arpackage2module() : Module {
> -- ...
> self.elements[SenderReceiverInterface]->forEach(SRInterface)
> {
> declarations += generateMessagePortTypes(SRInterface)->asOrderedSet()
> };
> -- ...
>
>
> I not sure this helps, but you can try it...
>
>
> Dennis
>
Re: [QVTo] Mapping 1 to many objects results in output object appearing as siblings [message #538662 is a reply to message #538010] Tue, 08 June 2010 11:30 Go to previous message
C. Kopf is currently offline C. KopfFriend
Messages: 37
Registered: November 2009
Member
Thanks alot for your explanations.

it works pretty fine now. and I got some more understanding of QVT.

Cheers,

Chris
Previous Topic:[ATL] How to execute many rules in the same atl file
Next Topic:Using M2M in C#
Goto Forum:
  


Current Time: Sun Dec 21 12:49:43 GMT 2014

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

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