Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Xcore - single container, multiple opposite
Xcore - single container, multiple opposite [message #1008179] Mon, 11 February 2013 09:45 Go to next message
David Michonneau is currently offline David MichonneauFriend
Messages: 85
Registered: July 2009
Member
Hi,

I'm trying to implement a model similar to this:

package test
class Car {
contains Tire leftTire
contains Tire rightTire
}

class Tire {
container Car car // not allowed by Xcore editor
}

Unfortunately, it is not possible because container requires an opposite. I found the only way to make it work is as follows:

class Car {
contains Tire leftTire opposite carForLeftTire
contains Tire rightTire opposite carForRightTire
}

class Tire {
container Car carForLeftTire opposite leftTire
container Car carForRightTire opposite rightTire
}

However in this case, this just makes the generated code not really convenient to use to find the car of a given tire. I found I could do an operation like:

class Tire {
op Car getCar() {
return this.eContainer() as Car
}

but shouldn't the generation supports this use case? Why is the container keyword constrained to specify an opposite?

Thanks,

David
Re: Xcore - single container, multiple opposite [message #1008280 is a reply to message #1008179] Mon, 11 February 2013 12:50 Go to previous messageGo to next message
Roland Tepp is currently offline Roland TeppFriend
Messages: 36
Registered: July 2009
Member
Can't you solve this with feature maps?

11.02.2013 11:45, David Michonneau kirjutas:
> Hi,
>
> I'm trying to implement a model similar to this:
>
> package test
> class Car {
> contains Tire leftTire contains Tire rightTire }
>
> class Tire {
> container Car car // not allowed by Xcore editor
> }
>
> Unfortunately, it is not possible because container requires an
> opposite. I found the only way to make it work is as follows:
>
> class Car {
> contains Tire leftTire opposite carForLeftTire contains Tire
> rightTire opposite carForRightTire
> }
>
> class Tire {
> container Car carForLeftTire opposite leftTire
> container Car carForRightTire opposite rightTire
> }
>
> However in this case, this just makes the generated code not really
> convenient to use to find the car of a given tire. I found I could do an
> operation like:
>
> class Tire {
> op Car getCar() {
> return this.eContainer() as Car
> }
>
> but shouldn't the generation supports this use case? Why is the
> container keyword constrained to specify an opposite?
>
> Thanks,
>
> David
>
Re: Xcore - single container, multiple opposite [message #1008344 is a reply to message #1008179] Tue, 12 February 2013 05:29 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
David,

Comments below.

On 11/02/2013 10:45 AM, David Michonneau wrote:
> Hi,
>
> I'm trying to implement a model similar to this:
>
> package test
> class Car {
> contains Tire leftTire contains Tire rightTire }
>
> class Tire {
> container Car car // not allowed by Xcore editor
> }
You must specify exactly one containment reference as the opposite.
>
> Unfortunately, it is not possible because container requires an
> opposite. I found the only way to make it work is as follows:
>
> class Car {
> contains Tire leftTire opposite carForLeftTire contains Tire
> rightTire opposite carForRightTire
> }
>
> class Tire {
> container Car carForLeftTire opposite leftTire
> container Car carForRightTire opposite rightTire
> }
>
> However in this case, this just makes the generated code not really
> convenient to use to find the car of a given tire. I found I could do
> an operation like:
>
> class Tire {
> op Car getCar() {
> return this.eContainer() as Car
> }
>
> but shouldn't the generation supports this use case?
You'd have to be more careful (an instanceof check) because the
container could be something else as well.
> Why is the container keyword constrained to specify an opposite?
It's this way in Ecore as well. A reference is a container reference by
virtue of being the opposite of a containment reference; it's not a bit
you can set independently.

Note that in your second approach, it's less convenient to get the car,
but more importantly the tire.setCarForLeftTire and
tire.setCarForRightTire do the right thing (adds it to the proper
containment reference of the car), whereas tire.setCar can't possibly do
the right thing.
>
> Thanks,
>
> David
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[EMF] Loading XML file with no namespace information
Next Topic:Nested Properties in EMF
Goto Forum:
  


Current Time: Thu Apr 25 02:09:47 GMT 2024

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

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

Back to the top