Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Trying to build containment vs references example
Trying to build containment vs references example [message #428849] Tue, 31 March 2009 17:41 Go to next message
Jason Henriksen is currently offline Jason HenriksenFriend
Messages: 231
Registered: July 2009
Senior Member
Hi All,

I'm trying to write a minimum possible example to illustrate the
differences between containment and reference. I thought I understood
how to do all this in XSD, but I'm tripping it up.

I'm getting the error from my genModel:
"The opposite of the opposite may not be a reference different from this
one".

How do I provide a parent linkage on the child's interface?
If I remove all references to the 'parent' item it seems ok.

My goal is to write sample code like this:

//=== intended sample code:

ContainerAndReferenceExample a= new ContainerAndReferenceExample();
ContainerAndReferenceExample b= new ContainerAndReferenceExample();
ContainerAndReferenceExample c= new ContainerAndReferenceExample();

//=== show that containment can make things 'disappear'
a.getContainmentListA().add(c);
assert(c.getParent()==a); // c knows its in a

a.getContainmentListB().add(c);
assert(c.getParent()==a); // c knows its in a
assert(a.getContainmentListA().size()==0); // but in a new list!

b.getContainmentListA().add(c);
assert(c.getParent()==b); // c knows its in b
assert(a.getContainmentListA().size()==0); // gone from a.cA
assert(a.getContainmentListB().size()==0); // gone from a.cB
assert(b.getContainmentListA().size()==1); // now in b.cA

//=== now do the same test with references
a.getReferenceListA().add(c); // put the item in a ref list
a.getReferenceListB().add(c); // and another one
assert(a.getReferenceListA().size()==1); // it stayed in a.rA
assert(a.getReferenceListB().size()==1); // it stayed in a.rB
assert(b.getContainmentListB().size()==1);// it stayed in b.cB
assert(c.getParent()==b); // still knows it right parent.

b.getContainmentListB().add(c);
assert(a.getReferenceListA().size()==1); // it stayed in ref
assert(a.getReferenceListB().size()==1); // it stayed in ref
assert(b.getContainmentListA().size()==0); // it moved in contain
assert(b.getContainmentListB().size()==1); // now in new home.
assert(c.getParent()==b);


//===

Thanks for any suggestions,

Jason Henriksen

--------------- Here's my XSD: ---------

<xsd:complexType name="ContainerAndReferenceExample">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Transient</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>

<!-- list that will change based on containment -->
<xsd:element name="containmentListA"
type="ns:ContainerAndReferenceExample"
minOccurs="0"
maxOccurs="unbounded"
ecore:opposite="parent"
/>

<!-- list that will change based on containment -->
<xsd:element name="containmentListB"
type="ns:ContainerAndReferenceExample"
minOccurs="0"
maxOccurs="unbounded"
ecore:opposite="parent"
/>

<!-- single item that will change based on containment -->
<xsd:element name="containedItem"
type="ns:ContainerAndReferenceExample"
ecore:opposite="parent"
/>

<!-- interface access to whatever is currently holding this item -->
<xsd:element name="parent"
type="xsd:IDREF"
ecore:reference="ns:ContainerAndReferenceExample"
/>


<!-- list of items that wont change based on an object's usage -->
<xsd:element name="referenceListA"
type="xsd:IDREF"
ecore:reference="ns:ContainerAndReferenceExample"
minOccurs="0"
maxOccurs="unbounded"
/>

<!-- other list of items that wont change -->
<xsd:element name="referenceListB"
type="xsd:IDREF"
ecore:reference="ns:ContainerAndReferenceExample"
minOccurs="0"
maxOccurs="unbounded"
/>

</xsd:sequence>
<!-- Primitive Data Fields -->
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
Re: Trying to build containment vs references example [message #428852 is a reply to message #428849] Tue, 31 March 2009 18:26 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Jason,

Comments below.

EAnnotation

jason henriksen wrote:
> Hi All,
>
> I'm trying to write a minimum possible example to illustrate the
> differences between containment and reference. I thought I understood
> how to do all this in XSD, but I'm tripping it up.
>
> I'm getting the error from my genModel:
> "The opposite of the opposite may not be a reference different from
> this one".
Yes, they must be paired.
>
> How do I provide a parent linkage on the child's interface?
> If I remove all references to the 'parent' item it seems ok.
If you put an ecore:opposite on an element, it will create the opposite
feature for you. No need to declare anything at the other end.
>
> My goal is to write sample code like this:
>
> //=== intended sample code:
>
> ContainerAndReferenceExample a= new ContainerAndReferenceExample();
> ContainerAndReferenceExample b= new ContainerAndReferenceExample();
> ContainerAndReferenceExample c= new ContainerAndReferenceExample();
>
> //=== show that containment can make things 'disappear'
> a.getContainmentListA().add(c);
> assert(c.getParent()==a); // c knows its in a
>
> a.getContainmentListB().add(c);
> assert(c.getParent()==a); // c knows its in a
> assert(a.getContainmentListA().size()==0); // but in a new list!
>
> b.getContainmentListA().add(c);
> assert(c.getParent()==b); // c knows its in b
> assert(a.getContainmentListA().size()==0); // gone from a.cA
> assert(a.getContainmentListB().size()==0); // gone from a.cB
> assert(b.getContainmentListA().size()==1); // now in b.cA
>
> //=== now do the same test with references
> a.getReferenceListA().add(c); // put the item in a ref list
> a.getReferenceListB().add(c); // and another one
> assert(a.getReferenceListA().size()==1); // it stayed in a.rA
> assert(a.getReferenceListB().size()==1); // it stayed in a.rB
> assert(b.getContainmentListB().size()==1);// it stayed in b.cB
> assert(c.getParent()==b); // still knows it right parent.
>
> b.getContainmentListB().add(c);
> assert(a.getReferenceListA().size()==1); // it stayed in ref
> assert(a.getReferenceListB().size()==1); // it stayed in ref
> assert(b.getContainmentListA().size()==0); // it moved in contain
> assert(b.getContainmentListB().size()==1); // now in new home.
> assert(c.getParent()==b);
>
You could do all that with EAnnotation. It has getContents and
getReferences.
>
> //===
>
> Thanks for any suggestions,
>
> Jason Henriksen
>
> --------------- Here's my XSD: ---------
>
> <xsd:complexType name="ContainerAndReferenceExample">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">@Transient</xsd:appinfo>
> </xsd:annotation>
> <xsd:sequence>
>
> <!-- list that will change based on containment -->
> <xsd:element name="containmentListA"
> type="ns:ContainerAndReferenceExample"
> minOccurs="0"
> maxOccurs="unbounded"
> ecore:opposite="parent"
> />
>
> <!-- list that will change based on containment -->
> <xsd:element name="containmentListB"
> type="ns:ContainerAndReferenceExample"
> minOccurs="0"
> maxOccurs="unbounded"
> ecore:opposite="parent"
No, you can't have the same parent feature be the opposite of more than
one thing. EObject.eContainer is the implicit opposite. You'll have to
pick a different name per feature..
> />
>
> <!-- single item that will change based on containment -->
> <xsd:element name="containedItem"
> type="ns:ContainerAndReferenceExample"
> ecore:opposite="parent"
> />
>
> <!-- interface access to whatever is currently holding this item -->
> <xsd:element name="parent"
> type="xsd:IDREF"
> ecore:reference="ns:ContainerAndReferenceExample"
> />
>
>
> <!-- list of items that wont change based on an object's usage -->
> <xsd:element name="referenceListA"
> type="xsd:IDREF"
> ecore:reference="ns:ContainerAndReferenceExample"
> minOccurs="0"
> maxOccurs="unbounded"
> />
>
> <!-- other list of items that wont change -->
> <xsd:element name="referenceListB"
> type="xsd:IDREF"
> ecore:reference="ns:ContainerAndReferenceExample"
> minOccurs="0"
> maxOccurs="unbounded"
> />
>
> </xsd:sequence>
> <!-- Primitive Data Fields -->
> <xsd:attribute name="name" type="xsd:string" />
> </xsd:complexType>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:.edit(or) and .test projects don't find their base project
Next Topic:[Teneo Bug Fix] Problems with ehcache
Goto Forum:
  


Current Time: Fri Apr 26 20:00:54 GMT 2024

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

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

Back to the top