[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xmlbeans-dev
Subject:    Error handler overwritten on parse
From:       peter_van_de_water () vero ! co ! nz
Date:       2007-09-03 2:50:11
Message-ID: OFD6D98FE9.2BB6BFB4-ONCC25734B.000B87BA-CC25734B.000F9515 () promina ! com ! au
[Download RAW message or body]

--=_alternative 000F9515CC25734B_=
Content-Type: text/plain; charset="US-ASCII"

I'm looking to parse and validate incoming XML in a single pass with 
customised error handling for validation errors.

Here's what I do:

Get a new instance of a validating reader.
Turn on the validation features.
Set its error handler with a new instance of my customer error handler.
Create a new instance of XML options and set its XML reader to be my 
validating one with the custom error handler.
Parse the XML using the XML options.

Prior to the parse my error handler is an instance of 
nz.co.vero.renew.datatransfer.component.messagegateway.GatewayManagerImpl$1 
but after the call it is an 
org.apache.xmlbeans.impl.store.Locale$XmlReaderSaxLoader and so my custom 
error handling code never gets called :-(

This looks like a bug to me - it should check the error handler isn't null 
before reassigning it, or at the very least state in the docs that the 
parse method mutates the XML options underlying XML reader by overwriting 
its error handler reference. Am I missing something? Some other properties 
I should have set? A different (efficient) way of doing it?

Thanks in advance for any help / thoughts, Pete


PS: Java 1.4.2, XML4J 4.3.6,  XMLBeans 2.3.0

PPS: Code snippet:

XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setFeature("http://apache.org/xml/features/validation/schema", 
true);
reader.setFeature("http://xml.org/sax/features/validation", true);
reader.setErrorHandler(new ErrorHandler() { // Snip custom handling
        public void error(SAXParseException e) {}
        public void fatalError(SAXParseException e) {}
        public void warning(SAXParseException e) {}
});
XmlOptions options = new 
XmlOptions().setUnsynchronized().setLoadUseXMLReader(reader);
log.config("Error handler: " + 
reader.getErrorHandler().getClass().getName());
RatePolicyRequestDocument.Factory.parse(request.getCharacterStream(), 
options);
log.config("Error handler: " + 
reader.getErrorHandler().getClass().getName());

Pete van de Water
Technical Consultant
Vero Insurance New Zealand Limited
Mobile +64 21 226 6228
Facsimile +64 9 363 2586
Email peter_van_de_water@vero.co.nz
www.vero.co.nz 

**********************************************************************
CAUTION - This message is intended for the addressee named above. It
may contain privileged or confidential information. If you are not the
intended recipient of this message you must not use, copy, distribute
or disclose it to anyone.
**********************************************************************
--=_alternative 000F9515CC25734B_=
Content-Type: text/html; charset="US-ASCII"


<br><font size=2 face="sans-serif">I'm looking to parse and validate incoming
XML in a single pass with customised error handling for validation errors.</font>
<br>
<br><font size=2 face="sans-serif">Here's what I do:</font>
<br>
<ul>
<li><font size=2 face="sans-serif">Get a new instance of a validating reader.</font>
<li><font size=2 face="sans-serif">Turn on the validation features.</font>
<li><font size=2 face="sans-serif">Set its error handler with a new instance
of my customer error handler.</font>
<li><font size=2 face="sans-serif">Create a new instance of XML options
and set its XML reader to be my validating one with the custom error handler.</font>
<li><font size=2 face="sans-serif">Parse the XML using the XML options.</font></ul>
<br><font size=2 face="sans-serif">Prior to the parse my error handler
is an instance of nz.co.vero.renew.datatransfer.component.messagegateway.GatewayManagerImpl$1
 but after the call it is an org.apache.xmlbeans.impl.store.Locale$XmlReaderSaxLoader
and so my custom error handling code never gets called :-(</font>
<br>
<br><font size=2 face="sans-serif">This looks like a bug to me - it should
check the error handler isn't null before reassigning it, or at the very
least state in the docs that the parse method mutates the XML options underlying
XML reader by overwriting its error handler reference. Am I missing something?
Some other properties I should have set? A different (efficient) way of
doing it?</font>
<br>
<br><font size=2 face="sans-serif">Thanks in advance for any help / thoughts,
Pete</font>
<br>
<br>
<br><font size=2 face="sans-serif">PS: Java 1.4.2, XML4J 4.3.6, &nbsp;XMLBeans
2.3.0</font>
<br>
<br><font size=2 face="sans-serif">PPS: Code snippet:</font>
<br>
<br><font size=2 face="sans-serif">XMLReader reader = \
XMLReaderFactory.createXMLReader();</font> <br><font size=2 \
face="sans-serif">reader.setFeature(&quot;http://apache.org/xml/features/validation/schema&quot;,
 true);</font>
<br><font size=2 face="sans-serif">reader.setFeature(&quot;http://xml.org/sax/features/validation&quot;,
 true);</font>
<br><font size=2 face="sans-serif">reader.setErrorHandler(new ErrorHandler()
{ // Snip custom handling</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; public
void error(SAXParseException e) {}</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; public
void fatalError(SAXParseException e) {}</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; public
void warning(SAXParseException e) {}</font>
<br><font size=2 face="sans-serif">});</font>
<br><font size=2 face="sans-serif">XmlOptions options = new \
XmlOptions().setUnsynchronized().setLoadUseXMLReader(reader);</font> <br><font size=2 \
face="sans-serif">log.config(&quot;Error handler: &quot; + \
reader.getErrorHandler().getClass().getName());</font> <br><font size=2 \
face="sans-serif">RatePolicyRequestDocument.Factory.parse(request.getCharacterStream(),
 options);</font>
<br><font size=2 face="sans-serif">log.config(&quot;Error handler: &quot;
+ reader.getErrorHandler().getClass().getName());</font>
<br><font size=2 face="sans-serif"><br>
Pete van de Water<br>
Technical Consultant<br>
Vero Insurance New Zealand Limited<br>
Mobile +64 21 226 6228<br>
Facsimile +64 9 363 2586<br>
Email peter_van_de_water@vero.co.nz<br>
www.vero.co.nz </font>

<BR>
**********************************************************************<BR>
CAUTION - This message is intended for the addressee named above. It<BR>
may contain privileged or confidential information. If you are not the<BR>
intended recipient of this message you must not use, copy, distribute<BR>
or disclose it to anyone.<BR>
**********************************************************************<BR>

--=_alternative 000F9515CC25734B_=--


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic