|
Re: Serialization of a relationship. [message #418379 is a reply to message #418375] |
Mon, 14 April 2008 23:23 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------060309050103030305020106
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Jason,
It sounds like you are trying to get cross resource containment to work
with an XSD-based model, but it's never been designed to work for an
XSD-based model. E.g., XMLSaveImpl is guarded like this:
protected boolean writeTopElements(EObject top)
{
if (!*useEncodedAttributeStyle*)
{
InternalEObject container =
((InternalEObject)top).eInternalContainer();
if (container != null)
{
EReference containmentReference = top.eContainmentFeature();
EReference containerReference =
containmentReference.getEOpposite();
if (containerReference != null &&
!containerReference.isTransient())
{
saveHref(container, containerReference);
return true;
}
}
}
return false;
}
A question that I wouldn't know how to answer is: how would the parent
serialized its cross resource contained reference to the child?
jason henriksen wrote:
> Hi All,
>
> I have this xsd to describe a simple bi-directional relationship.
>
> <xsd:schema
> xmlns:com.ibm.example.connection="http:///com/ibm/example/connection.ecore"
>
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> ecore:nsPrefix="com.ibm.example.connection"
> ecore:package="com.ibm.example.connection"
> targetNamespace="http:///com/ibm/example/connection.ecore">
>
> <xsd:complexType name="Parent">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @Table(name=PARENT)
> </xsd:appinfo></xsd:annotation>
> <xsd:sequence>
>
> <xsd:element type="xsd:int" name="id">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @Id @GeneratedValue(strategy=AUTO) @Column(name="ID" unique="true")
> </xsd:appinfo></xsd:annotation>
> </xsd:element>
>
> <xsd:element maxOccurs="1" minOccurs="0"
> name="OneChildKnowsParentYes"
> type="com.ibm.example.connection:OneChildKnowsParentYes"
> ecore:opposite="parent"
> >
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @OneToOne(fetch=LAZY)
> </xsd:appinfo></xsd:annotation>
> </xsd:element>
> </xsd:complexType>
>
>
> <xsd:complexType name="OneChildKnowsParentYes">
> <xsd:annotation><xsd:appinfo
> source="teneo.jpa">@Table(name="C1PY")</xsd:appinfo></xsd:annotation >
> <xsd:sequence>
>
> <xsd:element type="xsd:int" name="id">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @Id @GeneratedValue(strategy=AUTO) @Column(name="ID")
> </xsd:appinfo></xsd:annotation>
> </xsd:element>
>
> <xsd:element type="xsd:anyURI"
> name="parent"
> ecore:reference="com.ibm.example.connection:Parent"
> ecore:opposite="OneChildKnowsParentYes"
> >
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @OneToOne @JoinColumn(name="PARENT")
> </xsd:appinfo></xsd:annotation>
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
>
> </xsd:schema>
>
> It's intended to be a completely normal bi-directional relationship
> where the parent usually contains child. However, sometimes I
> serialize the child without the parent, so I need the child to output
> the <parent> tag with a URL in it. I just get:
>
> <com.ibm.example.connection:OneChildKnowsParentYes>
> <id>65536</id>
> <data>BBB</data>
> <!-- I need to have a 'parent' tag with a URI here -->
> </com.ibm.example.connection:OneChildKnowsParentYes>
>
> So far nothing I've tried will make the child print the parent. I can
> see that the child knows the parent by calling child.getParent() and
> getting the correct result before I serialize. I can also confirm
> that the relationship is stored correctly in the database. It's just
> the XML serialization that doesn't work.
>
> Am I missing some option to make it write the URL?
>
> Thanks for your help,
>
> Jason Henriksen
--------------060309050103030305020106
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jason,<br>
<br>
It sounds like you are trying to get cross resource containment to work
with an XSD-based model, but it's never been designed to work for an
XSD-based model. E.g., XMLSaveImpl is guarded like this:<small><br>
</small>
<blockquote><small> protected boolean writeTopElements(EObject top)</small><br>
<small> {</small><br>
<small> if (!<b>useEncodedAttributeStyle</b>)</small><br>
<small> {</small><br>
<small> InternalEObject container =
((InternalEObject)top).eInternalContainer();</small><br>
<small> if (container != null)</small><br>
<small> {</small><br>
<small> EReference containmentReference =
top.eContainmentFeature();</small><br>
<small> EReference containerReference =
containmentReference.getEOpposite();</small><br>
<small> if (containerReference != null &&
!containerReference.isTransient())</small><br>
<small> {</small><br>
<small> saveHref(container, containerReference);</small><br>
<small> return true;</small><br>
<small> }</small><br>
<small> }</small><br>
<small> }</small><br>
<small> return false;</small><br>
<small> }</small><br>
</blockquote>
A question that I wouldn't know how to answer is: how would the parent
serialized its cross resource contained reference to the child?<br>
<br>
<br>
jason henriksen wrote:
<blockquote cite="mid:fu0nul$tv9$1@build.eclipse.org" type="cite">Hi
All,
<br>
<br>
I have this xsd to describe a simple bi-directional relationship.
<br>
<br>
<xsd:schema
<br>
xmlns:com.ibm.example.connection=<a class="moz-txt-link-rfc2396E" href="http:///com/ibm/example/connection.ecore">"http:///com/ibm/example/connection.ecore"</a>
<br>
xmlns:ecore=<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/emf/2002/Ecore">"http://www.eclipse.org/emf/2002/Ecore"</a>
<br>
xmlns:xsd=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>
<br>
ecore:nsPrefix="com.ibm.example.connection"
<br>
ecore:package="com.ibm.example.connection"
<br>
targetNamespace=<a class="moz-txt-link-rfc2396E" href="http:///com/ibm/example/connection.ecore">"http:///com/ibm/example/connection.ecore"</a>>
<br>
<br>
<xsd:complexType name="Parent">
<br>
<xsd:annotation><xsd:appinfo source="teneo.jpa">
<br>
@Table(name=PARENT)
<br>
</xsd:appinfo></xsd:annotatio n>
<br>
<xsd:sequence>
<br>
<br>
<xsd:element type="xsd:int" name="id">
<br>
<xsd:annotation><xsd:appinfo source="teneo.jpa">
<br>
@Id @GeneratedValue(strategy=AUTO) @Column(name="ID" unique="true")
<br>
</xsd:appinfo></xsd:annotation>
<br>
</xsd:element>
<br>
<br>
<xsd:element maxOccurs="1" minOccurs="0"
<br>
name="OneChildKnowsParentYes"
<br>
type="com.ibm.example.connection:OneChildKnowsParentYes"
<br>
ecore:opposite="parent" <br>
>
<br>
<xsd:annotation><xsd:appinfo source="teneo.jpa">
<br>
@OneToOne(fetch=LAZY)
<br>
</xsd:appinfo></xsd:annotation>
<br>
</xsd:element>
<br>
</xsd:complexType>
<br>
<br>
<br>
<xsd:complexType name="OneChildKnowsParentYes">
<br>
<xsd:annotation><xsd:appinfo
source="teneo.jpa">@Table(name="C1PY" )</xsd:appinfo></xsd:annotation>
<br>
<xsd:sequence>
<br>
<br>
<xsd:element type="xsd:int" name="id">
<br>
<xsd:annotation><xsd:appinfo source="teneo.jpa">
<br>
@Id @GeneratedValue(strategy=AUTO) @Column(name="ID")
<br>
</xsd:appinfo></xsd:annotation>
<br>
</xsd:element>
<br>
<br>
<xsd:element type="xsd:anyURI"
<br>
name="parent"
<br>
ecore:reference="com.ibm.example.connection:Parent"
<br>
ecore:opposite="OneChildKnowsParentYes"
<br>
>
<br>
<xsd:annotation><xsd:appinfo source="teneo.jpa">
<br>
@OneToOne @JoinColumn(name="PARENT")
<br>
</xsd:appinfo></xsd:annotation>
<br>
</xsd:element>
<br>
</xsd:sequence>
<br>
</xsd:complexType>
<br>
<br>
</xsd:schema>
<br>
<br>
It's intended to be a completely normal bi-directional relationship
where the parent usually contains child. However, sometimes I
serialize the child without the parent, so I need the child to output
the <parent> tag with a URL in it. I just get:
<br>
<br>
<com.ibm.example.connection:OneChildKnowsParentYes&am p;gt;
<br>
<id>65536</id>
<br>
<data>BBB</data>
<br>
<!-- I need to have a 'parent' tag with a URI here -->
<br>
</com.ibm.example.connection:OneChildKnowsParentYes&a mp;gt;
<br>
<br>
So far nothing I've tried will make the child print the parent. I can
see that the child knows the parent by calling child.getParent() and
getting the correct result before I serialize. I can also confirm that
the relationship is stored correctly in the database. It's just the
XML serialization that doesn't work.
<br>
<br>
Am I missing some option to make it write the URL?
<br>
<br>
Thanks for your help,
<br>
<br>
Jason Henriksen
<br>
</blockquote>
<br>
</body>
</html>
--------------060309050103030305020106--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03470 seconds