Home » Archived » M2M (model-to-model transformation) » [QVTO] Help for explaining a mapping behavior.
[QVTO] Help for explaining a mapping behavior. [message #482235] |
Tue, 25 August 2009 19:08 |
Toñi Reina Messages: 209 Registered: July 2009 |
Senior Member |
|
|
Hi all,
I'm trying to understand what's happening when executing a mapping.
The piece of code I'm executing is the following one:
mapping siteMap::Node::toDivMainNavigation(): xhtml::DivType{
init{
log('3..divMainNav..1',self.name);
log('4..divMainNav..2',inModel.nodesMainNav->size());
}
id:='mainNavigation';
ul:= object xhtml::UlType{
id:='main_navigation';
li:= inModel.nodesMainNav->map toLiNavigationLink();
};
end{
log('5..ul size..3',result.ul->size());
log('6..li size..3',result.ul->first().li->size());
}
}
The aim of the mapping is to obtain something similar to this:
<div id="mainNavigation">
<ul id="main_navigation">
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>
The mapping is executed a number of times, depending on the Nodes of the
input model. The problem is that it seems that the mapping named
toLiNavigationLink(), which is invoked by toDivMainNavigation() only is
called once, the first time that toDivMainNavigation is invoked.
An example of the output shown in the console as a consequence of the
log messages is the following one:
3..divMainNav..1, data: Leisure
4..divMainNav..2, data: 8
toLiNavigation, data: News
toLiNavigation, data: Contact
toLiNavigation, data: Teaching
toLiNavigation, data: Research
toLiNavigation, data: Publications
toLiNavigation, data: Leisure
toLiNavigation, data: News
toLiNavigation, data: Contact
5..ul size..3, data: 1
6..li size..3, data: 8
3..divMainNav..1, data: Consulting Hours
4..divMainNav..2, data: 8
5..ul size..3, data: 1
6..li size..3, data: 8
3..divMainNav..1, data: Courses
4..divMainNav..2, data: 8
5..ul size..3, data: 1
6..li size..3, data: 8
As it can be seen toLiNavigation is executed only during the first
execution of toDivMainNavigation.
My question is: Why the line of code li:= inModel.nodesMainNav->map
toLiNavigationLink(); is only executed once?
Thanks in advance and regards,
Toñi
|
|
|
Re: [QVTO] Help for explaining a mapping behavior. [message #482238 is a reply to message #482235] |
Tue, 25 August 2009 19:32 |
Sergey Boyko Messages: 171 Registered: July 2009 |
Senior Member |
|
|
Hi Toñi ,
It's expected behavior.
For the same source given mapping is executed only only. On subsequent
calls it fetches already created result from implicit trace and return
it (see QVT Spec, Section 8.2.1.15 MappingOperation: Execution Semantics).
You might take a look at similar discussion:
http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.modeli ng.m2m/msg04380.html
Regards,
Sergey
Toñi Reina Quintero wrote:
> Hi all,
>
> I'm trying to understand what's happening when executing a mapping. The
> piece of code I'm executing is the following one:
>
> mapping siteMap::Node::toDivMainNavigation(): xhtml::DivType{
> init{
> log('3..divMainNav..1',self.name);
> log('4..divMainNav..2',inModel.nodesMainNav->size());
> }
> id:='mainNavigation';
> ul:= object xhtml::UlType{
> id:='main_navigation';
>
> li:= inModel.nodesMainNav->map toLiNavigationLink();
>
> };
> end{
> log('5..ul size..3',result.ul->size());
> log('6..li size..3',result.ul->first().li->size());
> }
> }
>
> The aim of the mapping is to obtain something similar to this:
> <div id="mainNavigation">
> <ul id="main_navigation">
> <li>Item 1</li>
> <li>Item 2</li>
> </ul>
> </div>
>
> The mapping is executed a number of times, depending on the Nodes of the
> input model. The problem is that it seems that the mapping named
> toLiNavigationLink(), which is invoked by toDivMainNavigation() only is
> called once, the first time that toDivMainNavigation is invoked.
>
> An example of the output shown in the console as a consequence of the
> log messages is the following one:
>
> 3..divMainNav..1, data: Leisure
> 4..divMainNav..2, data: 8
> toLiNavigation, data: News
> toLiNavigation, data: Contact
> toLiNavigation, data: Teaching
> toLiNavigation, data: Research
> toLiNavigation, data: Publications
> toLiNavigation, data: Leisure
> toLiNavigation, data: News
> toLiNavigation, data: Contact
> 5..ul size..3, data: 1
> 6..li size..3, data: 8
> 3..divMainNav..1, data: Consulting Hours
> 4..divMainNav..2, data: 8
> 5..ul size..3, data: 1
> 6..li size..3, data: 8
> 3..divMainNav..1, data: Courses
> 4..divMainNav..2, data: 8
> 5..ul size..3, data: 1
> 6..li size..3, data: 8
>
>
> As it can be seen toLiNavigation is executed only during the first
> execution of toDivMainNavigation.
>
> My question is: Why the line of code li:= inModel.nodesMainNav->map
> toLiNavigationLink(); is only executed once?
>
> Thanks in advance and regards,
> Toñi
|
|
|
Re: [QVTO] Help for explaining a mapping behavior. [message #482260 is a reply to message #482238] |
Tue, 25 August 2009 21:31 |
Toñi Reina Messages: 209 Registered: July 2009 |
Senior Member |
|
|
Thanks, Sergey, now I understand what's happening, and thanks to the
discussion you have suggested I have fixed the problem with an explicit
constructor (that now works with my 2.0.0 release :-))
Sergey Boyko escribió:
> Hi Toñi ,
>
> It's expected behavior.
> For the same source given mapping is executed only only. On subsequent
> calls it fetches already created result from implicit trace and return
> it (see QVT Spec, Section 8.2.1.15 MappingOperation: Execution Semantics).
>
> You might take a look at similar discussion:
> http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.modeli ng.m2m/msg04380.html
>
>
> Regards,
> Sergey
>
> Toñi Reina Quintero wrote:
>> Hi all,
>>
>> I'm trying to understand what's happening when executing a mapping.
>> The piece of code I'm executing is the following one:
>>
>> mapping siteMap::Node::toDivMainNavigation(): xhtml::DivType{
>> init{
>> log('3..divMainNav..1',self.name);
>> log('4..divMainNav..2',inModel.nodesMainNav->size());
>> }
>> id:='mainNavigation';
>> ul:= object xhtml::UlType{
>> id:='main_navigation';
>> li:= inModel.nodesMainNav->map toLiNavigationLink();
>> };
>> end{
>> log('5..ul size..3',result.ul->size());
>> log('6..li size..3',result.ul->first().li->size());
>> }
>> }
>>
>> The aim of the mapping is to obtain something similar to this:
>> <div id="mainNavigation">
>> <ul id="main_navigation">
>> <li>Item 1</li> <li>Item 2</li>
>> </ul>
>> </div>
>>
>> The mapping is executed a number of times, depending on the Nodes of
>> the input model. The problem is that it seems that the mapping named
>> toLiNavigationLink(), which is invoked by toDivMainNavigation() only
>> is called once, the first time that toDivMainNavigation is invoked.
>>
>> An example of the output shown in the console as a consequence of the
>> log messages is the following one:
>>
>> 3..divMainNav..1, data: Leisure
>> 4..divMainNav..2, data: 8
>> toLiNavigation, data: News
>> toLiNavigation, data: Contact
>> toLiNavigation, data: Teaching
>> toLiNavigation, data: Research
>> toLiNavigation, data: Publications
>> toLiNavigation, data: Leisure
>> toLiNavigation, data: News
>> toLiNavigation, data: Contact
>> 5..ul size..3, data: 1
>> 6..li size..3, data: 8
>> 3..divMainNav..1, data: Consulting Hours
>> 4..divMainNav..2, data: 8
>> 5..ul size..3, data: 1
>> 6..li size..3, data: 8
>> 3..divMainNav..1, data: Courses
>> 4..divMainNav..2, data: 8
>> 5..ul size..3, data: 1
>> 6..li size..3, data: 8
>>
>>
>> As it can be seen toLiNavigation is executed only during the first
>> execution of toDivMainNavigation.
>>
>> My question is: Why the line of code li:= inModel.nodesMainNav->map
>> toLiNavigationLink(); is only executed once?
>>
>> Thanks in advance and regards,
>> Toñi
|
|
|
Goto Forum:
Current Time: Wed Feb 05 09:50:18 GMT 2025
Powered by FUDForum. Page generated in 0.02608 seconds
|