I have three ECore classes A ,B and C.

Now I introduce two EReferences from A to B and from A to C. as follows:

A "ref1"--> 0..1 B

"ref2"--> 0..1 C

My Questions is now how can I express that if "ref1" is set (1 B) "ref2" should be unset (0 C) and vice versa? I.e. only one EReference at a time?

Do I need OCL or is there some standard way to do this in EMF/Ecore?

Thanks for all help

greetings

]]>

You may be able to to express this structurally by introducing a BorC

interface which B and C both implement.

Then you can have a required ref to a BorC and derived optional refs to

B and to C.

Regards

Ed Willink

On 05/06/2012 23:47, Roger Druback wrote:

> Hello,

>

> I have three ECore classes A ,B and C.

>

> Now I introduce two EReferences from A to B and from A to C. as follows:

>

> A "ref1"--> 0..1 B

> "ref2"--> 0..1 C

>

>

> My Questions is now how can I express that if "ref1" is set (1 B)

> "ref2" should be unset (0 C) and vice versa? I.e. only one EReference

> at a time?

>

> Do I need OCL or is there some standard way to do this in EMF/Ecore?

>

>

> Thanks for all help

> greetings

>]]>

thank you for your answer.

I have attaced a graph of my problem and of what I understood was your possible solution.

My problem is that the EClass A is in another metamodel than B and C and at runtime their will be instances of both B and C. So I guess both B and C need to implement the interface?

A should make the decision which instance to reference but only one at a time.

I am not so familiar with OCL but isn't there something like:

"IF ref1 set to B THAN ref2 = null ..."

But sure a good model without OCL would be better.

Regards]]>

OCL is the power solution; you asked for a simple solution.

Using the OCLinEcore editor you can open your *.ecore file and do

something like

class A

{

property ref1 : B[?];

property ref2 : C[?];

invariant ExactlyOneBorC: ref1->size() + ref2->size() = 1;

}

[There are many algorithms for implementing XOR; the above avoids 'if'

cases.]

If you're really clever/insane you do it all with EAnnotations in the

Ecore Diagram Properties View.

Regards

Ed Willink

On 06/06/2012 10:17, Roger Druback wrote:

> Hello,

>

> thank you for your answer.

>

> I have attaced a graph of my problem and of what I understood was your possible solution.

>

> My problem is that the EClass A is in another metamodel than B and C and at runtime their will be instances of both B and C. So I guess both B and C need to implement the interface?

>

> A should make the decision which instance to reference but only one at a time.

>

> I am not so familiar with OCL but isn't there something like:

>

> "IF ref1 set to B THAN ref2 = null ..."

>

> But sure a good model without OCL would be better.

>

>

> Regards]]>

I think I'll go with No.2 as I do not want to introduce new model elements.

Regards]]>