org.apache.axiom.om.impl.builder
Class SafeXMLStreamReader
java.lang.Object
javax.xml.stream.util.StreamReaderDelegate
org.apache.axiom.om.impl.builder.SafeXMLStreamReader
- All Implemented Interfaces:
- javax.xml.stream.XMLStreamConstants, javax.xml.stream.XMLStreamReader
public class SafeXMLStreamReader
- extends javax.xml.stream.util.StreamReaderDelegate
XMLStreamReader wrapper that prevents access to the underlying parser
after the first error occurs.
Usually, code that uses StAX directly just stops processing of an XML document
once the first parsing error has been reported. However, since Axiom
uses deferred parsing, and client code accesses the XML infoset using
an object model, things are more complicated. Indeed, if the XML
document is not well formed, the corresponding error might be reported
as a runtime exception by any call to a method of an OM node.
Typically the client code will have some error handling that will intercept
runtime exceptions and take appropriate action. Very often this error handling
code might want to access the object model again, for example to log the request that caused the
failure. This causes no problem except if the runtime exception was caused by a
parsing error, in which case Axiom would again try to pull events from the parser.
This would lead to a situation where Axiom accesses a parser that has reported a parsing
error before. While one would expect that after a first error reported by the parser, all
subsequent invocations of the parser will fail, this is not the case for all parsers
(at least not in all situations). Instead, the parser might be left in an inconsistent
state after the error. E.g. WSCOMMONS-372 describes a case where Woodstox
encounters an error in XMLStreamReader.getText() but continues to return
(incorrect) events afterwards. The explanation for this behaviour might be that
the situation described here is quite uncommon when StAX is used directly (i.e. not through
Axiom).
This class provides a simple way to prevent this type of issue by wrapping the underlying
parser implementation. After the first parsing error occurs, the wrapper prevents any call
to XMLStreamReader.next() and similar methods on the underlying parser.
Any attempt to do so will immediately result in an error.
| Fields inherited from interface javax.xml.stream.XMLStreamConstants |
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT |
| Methods inherited from class javax.xml.stream.util.StreamReaderDelegate |
close, getAttributeCount, getAttributeLocalName, getAttributeName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getCharacterEncodingScheme, getEncoding, getEventType, getLocalName, getLocation, getName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getParent, getPITarget, getPrefix, getProperty, getVersion, hasName, hasText, isAttributeSpecified, isCharacters, isEndElement, isStandalone, isStartElement, isWhiteSpace, require, setParent, standaloneSet |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SafeXMLStreamReader
public SafeXMLStreamReader(javax.xml.stream.XMLStreamReader reader)
getElementText
public String getElementText()
throws javax.xml.stream.XMLStreamException
- Specified by:
getElementText in interface javax.xml.stream.XMLStreamReader- Overrides:
getElementText in class javax.xml.stream.util.StreamReaderDelegate
- Throws:
javax.xml.stream.XMLStreamException
getPIData
public String getPIData()
- Specified by:
getPIData in interface javax.xml.stream.XMLStreamReader- Overrides:
getPIData in class javax.xml.stream.util.StreamReaderDelegate
getText
public String getText()
- Specified by:
getText in interface javax.xml.stream.XMLStreamReader- Overrides:
getText in class javax.xml.stream.util.StreamReaderDelegate
getTextCharacters
public char[] getTextCharacters()
- Specified by:
getTextCharacters in interface javax.xml.stream.XMLStreamReader- Overrides:
getTextCharacters in class javax.xml.stream.util.StreamReaderDelegate
getTextCharacters
public int getTextCharacters(int sourceStart,
char[] target,
int targetStart,
int length)
throws javax.xml.stream.XMLStreamException
- Specified by:
getTextCharacters in interface javax.xml.stream.XMLStreamReader- Overrides:
getTextCharacters in class javax.xml.stream.util.StreamReaderDelegate
- Throws:
javax.xml.stream.XMLStreamException
getTextLength
public int getTextLength()
- Specified by:
getTextLength in interface javax.xml.stream.XMLStreamReader- Overrides:
getTextLength in class javax.xml.stream.util.StreamReaderDelegate
getTextStart
public int getTextStart()
- Specified by:
getTextStart in interface javax.xml.stream.XMLStreamReader- Overrides:
getTextStart in class javax.xml.stream.util.StreamReaderDelegate
hasNext
public boolean hasNext()
throws javax.xml.stream.XMLStreamException
- Specified by:
hasNext in interface javax.xml.stream.XMLStreamReader- Overrides:
hasNext in class javax.xml.stream.util.StreamReaderDelegate
- Throws:
javax.xml.stream.XMLStreamException
next
public int next()
throws javax.xml.stream.XMLStreamException
- Specified by:
next in interface javax.xml.stream.XMLStreamReader- Overrides:
next in class javax.xml.stream.util.StreamReaderDelegate
- Throws:
javax.xml.stream.XMLStreamException
nextTag
public int nextTag()
throws javax.xml.stream.XMLStreamException
- Specified by:
nextTag in interface javax.xml.stream.XMLStreamReader- Overrides:
nextTag in class javax.xml.stream.util.StreamReaderDelegate
- Throws:
javax.xml.stream.XMLStreamException
Copyright © 2004-2011 The Apache Software Foundation. All Rights Reserved.