|
Re: Trying to build containment vs references example [message #428852 is a reply to message #428849] |
Tue, 31 March 2009 18:26 |
Ed Merks 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/
|
|
|
Powered by
FUDForum. Page generated in 0.02850 seconds