[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] [MOXy] default namespace + inheritance + default root element doesn't work?
|
Hi Polly,
This behaviour looks incorrect. I have entered the following bug for
this issue:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=253934
-Blaise
amphoras wrote:
Hi,
I have successfully unmarshalled classes using the default namespace +
inheritance or default namespace + default root element. However, this is
the first time that I'm trying to combine default namespace + inheritance +
default root element. This combination does not seem to work. Please let
me know if I'm doing something wrong.
I have a class named Description that extends from Text. I am using a
default namespace and making Description the default root element. The
mapping looks like this:
<class-mapping-descriptor xsi:type="xml-class-mapping-descriptor">
<class>com.foo.Description</class>
<alias>Description</alias>
<inheritance xsi:type="qname-inheritance-policy">
<parent-class>com.foo.Text</parent-class>
</inheritance>
<events xsi:type="event-policy"/>
<querying xsi:type="query-policy"/>
<attribute-mappings>
<attribute-mapping xsi:type="xml-direct-mapping">
<attribute-name>type</attribute-name>
<field name="@type" xsi:type="node"/>
</attribute-mapping>
</attribute-mappings>
<descriptor-type>aggregate</descriptor-type>
<instantiation/>
<copying xsi:type="instantiation-copy-policy"/>
<default-root-element>Description</default-root-element>
<default-root-element-field name="Description" xsi:type="node">
<leaf-element-type>DescriptionType</leaf-element-type>
</default-root-element-field>
<namespace-resolver>
<namespaces/>
<default-namespace-uri>http://www.foo.com/bar/baz</default-namespace-uri>
</namespace-resolver>
<schema xsi:type="schema-file-reference">
<schema-context>/DescriptionType</schema-context>
<node-type>complex-type</node-type>
</schema>
</class-mapping-descriptor>
The mapping for the superclass Text looks like:
<class-mapping-descriptor xsi:type="xml-class-mapping-descriptor">
<class>com.foo.Text</class>
<alias>Text</alias>
<inheritance xsi:type="qname-inheritance-policy">
<class-indicator-field name="@dummy" xsi:type="node"/>
<class-indicator-mappings>
<class-indicator-mapping>
<class>com.foo.Description</class>
<class-indicator
xsi:type="xsd:string">DescriptionType</class-indicator>
</class-indicator-mapping>
<class-indicator-mapping>
<class>com.foo.Text</class>
<class-indicator xsi:type="xsd:string">TextType</class-indicator>
</class-indicator-mapping>
</class-indicator-mappings>
</inheritance>
<events xsi:type="event-policy"/>
<querying xsi:type="query-policy"/>
<attribute-mappings>
<attribute-mapping xsi:type="xml-direct-mapping">
<attribute-name>value</attribute-name>
<field name="text()" xsi:type="node"/>
</attribute-mapping>
<attribute-mapping xsi:type="xml-direct-mapping">
<attribute-name>languageID</attribute-name>
<field name="@languageID" xsi:type="node"/>
</attribute-mapping>
</attribute-mappings>
<descriptor-type>aggregate</descriptor-type>
<instantiation/>
<copying xsi:type="instantiation-copy-policy"/>
<namespace-resolver>
<namespaces/>
<default-namespace-uri>http://www.foo.com/bar/baz</default-namespace-uri>
</namespace-resolver>
<schema xsi:type="schema-file-reference">
<schema-context>/TextType</schema-context>
<node-type>complex-type</node-type>
</schema>
</class-mapping-descriptor>
The test XML file does not have the "class-indicator-field" attribute
"dummy" because we will never get an XML file with that inside it. I have
found that simply having the "class-indicator-mappings" has been enough for
nodes that are not a default root element. However, since this class is a
default root element, the SAXUnmarshallerHandler.startElement finds the
"leafElementType" under the comment "no xsi:type attribute - look for type
indicator on the default root element". The default root element is a QName
with the value "DescriptionType" but no namespace. The code should be able
to "get the class from the inheritance policy", because the map contains:
{class com.foo.Text=TextType,
class com.foo.Description=DescriptionType,
DescriptionType=class com.foo.Description,
TextType=class com.foo.Text,
{http://www.foo.com/bar/baz}TextType=class com.foo.Text,
{http://www.foo.com/bar/baz}DescriptionType=class com.foo.Description}
However, the problems appears to be that the QName type does not match the
key type of String. So the class name cannot be retrieved, and I get an
exception:
Caused by: Exception [EclipseLink-43] (Eclipse Persistence Services - 1.0.1
(Build 20080905)): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing class for indicator field value
[DescriptionType] of type [class javax.xml.namespace.QName].
Descriptor: XMLDescriptor(com.foo.Description -->
[DatabaseTable(Description)])
at
org.eclipse.persistence.exceptions.DescriptorException.missingClassForIndicatorFieldValue(DescriptorException.java:906)
at
org.eclipse.persistence.internal.oxm.record.SAXUnmarshallerHandler.startElement(SAXUnmarshallerHandler.java:246)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
Source)
...
It seems like the QName should either have the default namespace included or
a String should be used to do the matching. However, if I'm doing something
wrong in my mapping, please let me know how I can fix it.
Thank you so much for your help!
--Polly