hi Gagan, Kohsuke,
thanks for the information - i had annotations attached globally, and
also on two elements in the xsd that is causing me trouble but in my
case, removing these does not solve the problem..
I tried commenting them out but am still getting the XML validation
errors - bizarrely on an element that never has had any annotation:
<xsd:complexType name="VAR">
<xsd:attribute name="n" type="xsd:string" use="required"/>
<xsd:attribute name="v" type="xsd:string" use="required"/>
</xsd:complexType>
I've very little understanding of the classes that JAXB generates, but
it seems that the problem is somewhere in them (?) - Xerces seems to
legitimately report that the element has ended, but i think there is
possibly something wrong with the generated state machine (which seems
to track where parsing has got to within the element) inside the VAR's
parent?
[junit] com.arm.dragonfly.wh.XMLParsingException: Unexpected end of
element {}:VAR
[junit] at
com.arm.dragonfly.wh.jaxb.WXMLUtil$EThrowingHandler.handleEvent(WXMLUtil
.java:53)
[junit] at
com.arm.dragonfly.wh.jaxb.wxml.impl.runtime.SAXUnmarshallerHandlerImpl.h
andleEvent(SAXUnmarshallerHandlerImpl.java:561)
[junit] at
com.arm.dragonfly.wh.jaxb.wxml.impl.runtime.AbstractUnmarshallingEventHa
ndlerImpl.reportError(AbstractUnmarshallingEventHandlerImpl.java:140)
[junit] at
com.arm.dragonfly.wh.jaxb.wxml.impl.runtime.AbstractUnmarshallingEventHa
ndlerImpl.reportError(AbstractUnmarshallingEventHandlerImpl.java:137)
[junit] at
com.arm.dragonfly.wh.jaxb.wxml.impl.runtime.AbstractUnmarshallingEventHa
ndlerImpl.unexpectedLeaveElement(AbstractUnmarshallingEventHandlerImpl.j
ava:154)
[junit] at
com.arm.dragonfly.wh.jaxb.wxml.impl.runtime.AbstractUnmarshallingEventHa
ndlerImpl.leaveElement(AbstractUnmarshallingEventHandlerImpl.java:64)
[junit] at
com.arm.dragonfly.wh.jaxb.wxml.impl.MATCHImpl$VARImpl$Unmarshaller.leave
Element(MATCHImpl.java:499)
[junit] at
com.arm.dragonfly.wh.jaxb.wxml.impl.runtime.SAXUnmarshallerHandlerImpl.e
ndElement(SAXUnmarshallerHandlerImpl.java:140)
[junit] at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(
AbstractSAXParser.java:585)
The only reason I was thinking that the state machine might be wrong is
that it refers to attributes of the child element - ie attributes that
it does not have. Without really understanding what is going on in this
code then this is surprising, but guess there are probably performance
reasons that might justify this if its not an error?
thanks,
Andrew
________________________________
From: Gagan_Bhatnagar_at_i2.com [mailto:Gagan_Bhatnagar_at_i2.com]
Sent: 29 September 2004 08:46
To: users_at_jaxb.dev.java.net
Subject: RE: Re: how to ignore an error during partial unmarshalling
Hi Andrew, Kohsuke,
Part of the stack trace is identical, so it does look like Issue 29.
After some more testing I found that in my test application (attached
zip: ignore-error-sample.zip) this exception is thrown only when I have
annotated the element on which the error occurs (to use my own data type
converter).
My sample XML is shown below, which has a text value for the quantity
element (defined as a nonNegativeInteger type):
<purchaseOrder orderDate="1999-10-20">
<shipTo country="US">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Cambridge</city>
<state>MA</state>
<zip>12345</zip>
</shipTo>
<billTo country="US">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Cambridge</city>
<state>MA</state>
<zip>12345</zip>
</billTo>
<items>
<item partNum="123-AB">
<productName>Computer</productName>
<quantity>ABCD EFGH IJKL</quantity>
<USPrice>1499.99</USPrice>
</item>
</items>
</purchaseOrder>
When I am recovering from the error while parsing the XML, I get the
UnmarshalException only when the quantity field is defined as
MyAnnotatedInt and not when MyNormalInt (see schema fragment below).
<xsd:complexType name="Items">
<xsd:sequence>
<xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="productName" type="xsd:string"/>
<xsd:element name="quantity" type="MyAnnotatedInt"/> <!-- no error
when MyNormalInt is used -->
<xsd:element name="USPrice" type="xsd:decimal"/>
<xsd:element ref="comment" minOccurs="0"/>
<xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="partNum" type="SKU" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="MyNormalInt">
<xsd:restriction base="xsd:nonNegativeInteger">
<xsd:maxExclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="MyAnnotatedInt">
<xsd:annotation>
<xsd:documentation>
Don't want a java.math.BigInteger generated in the classes for
every integer field, instead want an int.
</xsd:documentation>
<xsd:appinfo>
<jaxb:javaType name="java.lang.Integer"
parseMethod="primer.MyDatatypeConverter.parseInteger"
printMethod="primer.MyDatatypeConverter.printInteger"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:nonNegativeInteger"/>
</xsd:simpleType>
Thanks,
Gagan
"Andrew Ferguson" <Andrew.Ferguson_at_arm.com>
09/28/2004 03:18 PM
Please respond to
users_at_jaxb.dev.java.net
To
<users_at_jaxb.dev.java.net>
cc
Subject
RE: Re: how to ignore an error during partial unmarshalling
hi,
from the stack trace:
Stack Trace :
javax.xml.bind.UnmarshalException: Unexpected end of element
{
http://srm.i2.com/neg}:biddingType
it sounds very like Issue 29?
https://jaxb.dev.java.net/issues/show_bug.cgi?id=29
<
https://jaxb.dev.java.net/issues/show_bug.cgi?id=29>
thanks,
Andrew
________________________________
From: Gagan_Bhatnagar_at_i2.com [mailto:Gagan_Bhatnagar_at_i2.com]
Sent: 28 September 2004 10:37
To: users_at_jaxb.dev.java.net
Subject: Re: how to ignore an error during partial unmarshalling
Thanks Kohsuke,
I created a simple test application. And found that there's no problem
while recovering from schema errors.
Somehow I'm getting this problem only in my main application running in
Weblogic Server which uses it's own Xerces implementation. Or possibly
there's a bug in my code.
Will verify and confirm.
Gagan
Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
09/27/2004 09:31 PM
Please respond to
users_at_jaxb.dev.java.net
To
users_at_jaxb.dev.java.net
cc
Subject
Re: how to ignore an error during partial unmarshalling
Gagan_Bhatnagar_at_i2.com wrote:
> Specifically, in certain fields in my XML a string value appears where
an
> integer is defined in the schema. On receiving errors on these
elements I ignore
> the error and return true in my ValidationEventHandler implementation.
However,
> I get an UnmarshalException because endElement event on the same
element throws
> the exception below.
Recovering from errors is often tricky, and there may very well be bugs.
If you could file a bug and attach schemas / test code and what now,
that would be really helpful.
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net