resolveTemp over several associations [message #990544] |
Thu, 13 December 2012 00:32 |
Andreas Grünwald Messages: 2 Registered: December 2012 |
Junior Member |
|
|
Hello, I just started working with ATL and wonder if/how it is possible to do the following transformation:
Source Model:
System --> Car --> Seat, where "-->" stands for "contains multiple".
Target Model:
CarSystem --> CarSeat where Filesystem corresponds to Sytem, but CarSeat has an attribute which combines the name of Car and Seat, e.g. if car="Mercedes" and "Seat"="BlackSeat", then CarSeat.name should be "Mercedes-BlackSeat".
I found some tutorials which used resolveTemp to generate the required link, but the problem here is that there are multiple associations over 2 levels and furthermore one target class combines two source classes.
Please help me to solve the problem! Please take especially a loop at the nested collect-resolve-temp line. If there is only one level it works for me, but if I want to collect all the seats, which is at level 2, it doesn't work. Why? How to solve that in ATL (if possible without DO-constructs).
This is my current solution which doesn't work (simplified):
rule System2Carsystem {
from
s1: in:System
to
s2: out!CarSystem(
containsCars <- s1.containsCars->collect(c|
c.containsSeats->collect(g| thisModule.resolveTemp(g, 'cs'))
)
)
}
rule SeatToCarSeat {
from
car: in!Car,
seat: in!Seat
to
cs: out!CarSeat(
name <- car.name + '-' + seat.name
)
}
|
|
|
Re: resolveTemp over several associations [message #990572 is a reply to message #990544] |
Thu, 13 December 2012 08:52 |
Sylvain EVEILLARD Messages: 556 Registered: July 2009 |
Senior Member |
|
|
I would simply transform a Seat to a CarSeat.
When you have :
from
car: in!Car,
seat: in!Seat
nothing says that the seat is linked to the car.
This means that you can enter this rule with a seat and a car without having the seat belonging to the car.
Simply transform a Seat to a CarSeat and from the seat I assume you can easily get the corresponding car (if there's no direct eReference you can probably use refImmediateComposite() which returns the owner of an element).
If you do it that way then in your System rule you just have to collect all the seats. No need to use resolveTemp :
containsCars <- s1.containsCars->collect(c|
c.containsSeats)->flatten()
[Updated on: Thu, 13 December 2012 08:53] Report message to a moderator
|
|
|
Re: resolveTemp over several associations [message #990652 is a reply to message #990572] |
Thu, 13 December 2012 15:21 |
Andreas Grünwald Messages: 2 Registered: December 2012 |
Junior Member |
|
|
Thank you for the message. I wasn't aware of the "refImmediateComposite()" operator, but it seems to be a promising operation. However, how can I then cast the parent element (I am not sure if ATL supports it)?
I wanted to do it the following way, which seemed intuitive, but didn't work out.
name <- seat.refImmediateComposite().oclAsType(System!Car).name + '-' +seat.name
EDIT:
Ok, meanwhile I think I found it out:
name <- seat.refImmediateComposite().refGetValue('name') + '-' +seat.name
ATL isn't very intuitive, isn't it?
Thank you very much for your help!!!
[Updated on: Thu, 13 December 2012 15:26] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03928 seconds