I actually have a fix for this, although I refrained from changing the whole
code-block (which is what should be done) just to keep the patch simple. In
other words, it fixes my immediate problem, but isn't really the right fix.
1. Changed org.exolab.castor.xml.UnmarshalHandler to handle three-level
deep unmarshalling (altered searchContainers())
diff -r1.67 UnmarshalHandler.java
1484a1493,1497
> descriptor = xfd;
> break;
> }
> else if (searchContainers(name,
(XMLClassDescriptor)xfd.getClassDescriptor()) != null)
* {
Here is the whole method:
private XMLFieldDescriptor searchContainers
(String name, XMLClassDescriptor classDesc)
throws SAXException
{
XMLFieldDescriptor[] descriptors =
classDesc.getElementDescriptors();
XMLFieldDescriptor descriptor = null;
for (int i = 0; i < descriptors.length; i++) {
if (descriptors[i] == null) continue;
XMLFieldDescriptor xfd = descriptors[i];
if (xfd.isContainer()) {
//-- set class descriptor if necessary
if (xfd.getClassDescriptor() == null) {
XMLClassDescriptor xcd
= getClassDescriptor(xfd.getFieldType());
if (xcd != null) {
//-- set class descriptor if necessary
if (xfd instanceof XMLFieldDescriptorImpl) {
((XMLFieldDescriptorImpl)xfd).setClassDescriptor(xcd);
}
if (xcd.getFieldDescriptor(name, NodeType.Element)
!= null) {
descriptor = xfd;
break;
}
else if (searchContainers(name, xcd) != null) {
descriptor = xfd;
break;
}
}
}
else if (xfd.matches(name)) {
descriptor = xfd;
break;
}
else if (searchContainers(name,
(XMLClassDescriptor)xfd.getClassDescriptor()) != null)
{
descriptor = xfd;
break;
}
}
}
return descriptor;
} //-- searchContainers.
-----Original Message-----
From: Arnaud Blandin [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 07, 2001 2:50 AM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] XML SourceGen question
Hi Joseph,
this is an identified bug we are working on (at least it is on our to-do
list
;+)).
Arnaud
> -----Original Message-----
> From: Joseph Campolongo [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, August 04, 2001 12:20 AM
> To: [EMAIL PROTECTED]
> Subject: [castor-dev] XML SourceGen question
>
>
> I have the following element described in my xsd:
>
> <element name='cXML'>
> <complexType>
> <choice>
> <sequence>
> <element ref='Header'/>
> <choice>
> <element ref='Message'/>
> <element ref='Request'/>
> </choice>
> </sequence>
> <element ref='Response'/>
> </choice>
> <attribute name='version' type='string' default='1.2.005'/>
> <attribute name='payloadID' type='string' use='required'/>
> <attribute name='timestamp' type='string' use='required'/>
> <attribute name='xml:lang' type='string' use='optional'/>
> </complexType>
> </element>
>
> It generates a class with _response and _cxmlSequence members for the
> elements.
>
> The problem is that when I try to unmarshal the XML
>
> <?xml version="1.0" encoding="UTF-8"?>
> <cXML payloadID="996539335546.1513265632@demo-nt1"
> timestamp="2001-07-30T17:28:55-07:00" version="1.0" xml:lang="en">
> <Header>
> ....
> </Header>
> <Request deploymentMode="production">
> ...
> </Request>
> </cXML>
>
> I get the following exception:
>
> org.xml.sax.SAXException: unable to find FieldDescriptor for 'Request' in
> ClassDescriptor of cXML
> at
>
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:80
> 4)
> at
> org.apache.xerces.parsers.SAXParser.startElement(SAXParser.java:1340)
> at
>
org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidat
> or.java:1197)
> at
>
org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanne
> r.java:1862)
> at
>
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XM
> LDocumentScanner.java:1238)
> at
>
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.
> java:381)
> at
org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1035)
> at
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:338)
> at
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:270)
> at
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:391)
> at
com.cascadeworks.app.cXML.protocol.CXML.unmarshal(CXML.java:226)
> at com.cascadeworks.app.cXML.protocol.Main.main(Main.java:33)
>
> It looks like at least part of the error is in
> UnmarshalHandler.searchContainers(), where it doesn't recurse more than
one
> level into a container, and XMLFieldDescriptor.match() also recurses one
> level, meaning that you can only have a schema with two levels of group
tags
> at most.
>
> Is this analysis correct, or am I simply doing something wrong? The
> particular schema, matching the DTD
>
> <!ELEMENT cXML (( Header, (Message | Request)) | Response)>
> <!ATTLIST cXML
> version %string; "&cxml.version;"
> payloadID %string; #REQUIRED
> timestamp %datetime.tz; #REQUIRED
> xml:lang %xmlLangCode; #IMPLIED
> >
>
> is reasonably common, so I'm surprised this hasn't come up before.
>
> jvc
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev