Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Jumping over abstract model elements of source
Jumping over abstract model elements of source [message #1061281] Fri, 31 May 2013 00:22 Go to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
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. Smile

==> ... 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 05:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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 #1061330 is a reply to message #1061301] Fri, 31 May 2013 09:03 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
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!

Re: Jumping over abstract model elements of source [message #1061411 is a reply to message #1061330] Fri, 31 May 2013 14:03 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

As I wrote before, you need to be much more thoughtful.

I must be very stupid, because I have not seen the EMF Model Recognition
project that can load a model from a *.png.

Regards

Ed Willink



On 31/05/2013 10:03, Emre Taspolatoglu wrote:
> 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!
>
>
Re: Jumping over abstract model elements of source [message #1061418 is a reply to message #1061411] Fri, 31 May 2013 14:22 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Again, sorry, I didn't think that you might want to load the models and try them.

It might sound pretty stupid, but I can't find any function here which allows me to upload any files. There is this section "File Attachments".

Anyway: Guess you could download them from a Dropbox link.

https://www.dropbox.com/sh/10guhgqhrwr2d6n/ymEsYl3UYG

Thank you!
Re: Jumping over abstract model elements of source [message #1061435 is a reply to message #1061418] Fri, 31 May 2013 15:34 Go to previous messageGo to next message
Adolfo Sanchez-Barbudo Herrera is currently offline Adolfo Sanchez-Barbudo HerreraFriend
Messages: 260
Registered: July 2009
Senior Member
By some reasons, replying via newsgroup didn't update the forum.... I should have done something wrong

Replying via Web browser:

Cheers,
Adolfo.
-----
Hi Emre,

A couple of comments:

> mapping Factory::toMap() : Something {
>
> references := self.has -> map toMapAgain() -> any(true); // error
>
> }

Because of the fact that Factory::has is a mono-valued reference, you should rather call the mapping as follows:

references := self.has.map toMapAgain()

avoiding the implicit collection creation (self.has->) and hence avoiding use the additional -> any(true):

> And the error I get is: Cannot find operation (toMapAgain()) neither for
> the type (Set(AbstractVehicle)) nor for its element type (AbstractVehicle)


As the error says your toMapAgain() is not defined on the AbstractVehicle class, so a mapping defined over your car can't be invoked. A typical way to resolve that is taking advantage of the virtual mapping calling capability of QVTo. So, creating an abstract mapping over the AbstractVehicle like the following one should work for you:

abstract mapping AbstractVehicle::toMapAgain() : AnotherThing;

mapping Car::toMapAgain() : AnotherThing { ... }

mapping Boat::toMapAgain() : AnotherThing { ... }

Using disjunct mappings is also another alternative (See the QVTo Specification or the slides in the Eclipse Help -> QVT Operational Developer Guide -> Overview)


Cheers,
Adolfo.

[Updated on: Fri, 31 May 2013 15:35]

Report message to a moderator

Re: Jumping over abstract model elements of source [message #1061461 is a reply to message #1061435] Fri, 31 May 2013 18:49 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello,

great, I see now where I was wrong. Even though that I always followed same pattern for similar model element relations, I really haven't noticed, that the different cardinalities need to be handled differently.

Thank you very much!
Re: Jumping over abstract model elements of source [message #1061491 is a reply to message #1061330] Sat, 01 June 2013 00:23 Go to previous message
Alan McMorran is currently offline Alan McMorranFriend
Messages: 55
Registered: July 2009
Member
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!
Previous Topic:A case scenario regarding the selection of mappings based on composed model elements
Next Topic:Manual transformation vs. programmatic transformation
Goto Forum:
  


Current Time: Thu Apr 18 18:16:46 GMT 2024

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

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

Back to the top