Jumping over abstract model elements of source [message #1061281] |
Thu, 30 May 2013 20:22  |
Eclipse User |
|
|
|
Hello again!
I need to be able to jump over the abstract model elements of the source model, which don't need to be transformed into the target. But their children should be. I will try to sketch it. Hope it helps to understand it easier. 
==> ... means inheritance
--> ... means composition
[..] ... means abstract
SOURCE:
Factory --has--> [AbstractVehicle] <== [SecondAbstractVehicle] <== Car / Boat
Here are the Car and Boat both different classes which inherits from SecondAbstractVehicle. And SecondAbstractVehicle inherits from AbstractVehicle. So the factory can have any number of cars or boats.
TARGET:
Something --references--> AnotherThing
And my mappings look like the following:
mapping Factory::toMap() : Something {
references := self.has -> map toMapAgain() -> any(true); // error
}
mapping Car::toMapAgain() : AnotherThing { ... }
And the error it gives is this: Cannot find operation (toMapAgain()) neither for the type (Set(AbstractVehicle)) nor for its element type (AbstractVehicle)
But, when I change the concrete model element Car (the input in toMapAgain()-mapping) into the abstract model element AbstractVehicle, which the factory actually has directly, the error goes away. But then of course, I can't access the properties or references of the model element Car.
Another thing is, don't know if it any differences make, but when I delete the any(true) at the end, I get a second error beside the above one, and that is: Mapping operation expected
Can't see what I am doing wrong. But i guess what I'm trying to do has to be possible. I would be very glad, if you could point me to the right direction and explain how and why it is done that way.
Thanks a lot!
P.S.: I find it very interesting, because with the elements of the target model, I don't get these kind of problems regarding the inherited model elements. I can jump to any target model element in any mapping definition. But it doesn't happen so freely with the source model elements.
|
|
|
Re: Jumping over abstract model elements of source [message #1061301 is a reply to message #1061281] |
Fri, 31 May 2013 01:53   |
Eclipse User |
|
|
|
Hi
Your question is too hard for me to understand quickly.
Why do you have to sketch it? What is wrong with an Ecore model that I
can look at?
You need to spend more time prepaaring your questions.
Regards
Ed Willink
On 31/05/2013 01:22, Emre Taspolatoglu wrote:
> Hello again!
>
> I need to be able to jump over the abstract model elements of the
> source model, which don't need to be transformed into the target. But
> their children should be. I will try to sketch it. Hope it helps to
> understand it easier. :)
>
> ==> ... means inheritance
> --> ... means composition
> [..] ... means abstract
>
> SOURCE:
> Factory --has--> [AbstractVehicle] <== [SecondAbstractVehicle] <== Car
> / Boat
>
> Here are the Car and Boat both different classes which inherits from
> SecondAbstractVehicle. And SecondAbstractVehicle inherits from
> AbstractVehicle. So the factory can have any number of cars or boats.
> TARGET:
> Something --references--> AnotherThing
>
> And my mappings look like the following:
>
> mapping Factory::toMap() : Something {
>
> references := self.has -> map toMapAgain() -> any(true); // error
>
> }
>
> mapping Car::toMapAgain() : AnotherThing { ... }
>
> And the error it gives is this: Cannot find operation (toMapAgain())
> neither for the type (Set(AbstractVehicle)) nor for its element type
> (AbstractVehicle)
>
> But, when I change the concrete model element Car (the input in
> toMapAgain()-mapping) into the abstract model element AbstractVehicle,
> which the factory actually has directly, the error goes away. But then
> of course, I can't access the properties or references of the model
> element Car.
>
> Another thing is, don't know if it any differences make, but when I
> delete the any(true) at the end, I get a second error beside the above
> one, and that is: Mapping operation expected
>
> Can't see what I am doing wrong. But i guess what I'm trying to do has
> to be possible. I would be very glad, if you could point me to the
> right direction and explain how and why it is done that way.
>
> Thanks a lot!
>
> P.S.: I find it very interesting, because with the elements of the
> target model, I don't get these kind of problems regarding the
> inherited model elements. I can jump to any target model element in
> any mapping definition. But it doesn't happen so freely with the
> source model elements.
>
>
>
>
>
|
|
|
|
|
|
|
|
Re: Jumping over abstract model elements of source [message #1061491 is a reply to message #1061330] |
Fri, 31 May 2013 20:23  |
Eclipse User |
|
|
|
Emre,
If I am understanding you correctly you want to map all elements within
the Factory's has reference that are Cars with another mapping (but not
any of the other classes?)?
If so should be able to do:
mapping Factory::toMap() : Something{
var cars := self.has->select(oclIsKindOf(Car)); // create a set of the
has elements that are of type Car
cars->forEach(c){ // iterate over them
if (c.oclIsKindOf(Car)) then{ // This should be true… but not harm in
being sure
c.oclAsType(Car).map toMapAgain(); // you have to cast the object to
Car as it will still consider it a Vehicle at this point. Now
toMapAgain will accept it
}endif;
};
}
You may get away with calling it on the set so replacing it all with a
single line (this may work I've not tested it…)
mapping Factory::toMap() : Something{
self.has->select(oclIsKindOf(Car)).oclAsType(Car).map toMapAgain()
}
Alan
On 2013-05-31 09:03:35 +0000, Emre Taspolatoglu said:
> Oh sorry, of course. You will find the Ecore's here.
>
> SOURCE: http://imageshack.us/photo/my-images/196/sourceu.png/
>
> TARGET: http://imageshack.us/photo/my-images/835/targetbo.png/
>
> Like before, the code snippet of the mappings is as follows:
>
> mapping Factory::toMap() : Something {
>
> references := self.has -> map toMapAgain() -> any(true); // error
>
> }
>
> mapping Car::toMapAgain() : AnotherThing { ... }
>
> And the error I get is: Cannot find operation (toMapAgain()) neither
> for the type (Set(AbstractVehicle)) nor for its element type
> (AbstractVehicle)
>
> My question hasn't changed so you can find it in the previous post,
> hope it will be better understandable this time. Please ask for further
> info, if I am still not clear.
>
> Thank you!
|
|
|
Powered by
FUDForum. Page generated in 0.08389 seconds