Class StAXOMBuilder

  • All Implemented Interfaces:
    OMXMLParserWrapper
    Direct Known Subclasses:
    StAXSOAPModelBuilder, XOPAwareStAXOMBuilder

    public class StAXOMBuilder
    extends StAXBuilder
    StAX based builder that produces a pure XML infoset compliant object model.

    This class supports the XMLStreamReader extension defined by DataHandlerReader as well as the legacy extension mechanism defined in the documentation of XMLStreamReaderUtils.

    Error handling

    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).

    To avoid this, the builder remembers exceptions thrown by the parser and rethrows them during a call to next().

    • Method Detail

      • createNextOMElement

        protected OMNode createNextOMElement()
        Creates a new OMElement using either a CustomBuilder or the default Builder mechanism.
        Returns:
        TODO
      • logParserState

        protected void logParserState()
        Dump the current event of the parser.
      • endElement

        protected void endElement()
      • getDocumentElement

        public OMElement getDocumentElement​(boolean discardDocument)
        Description copied from interface: OMXMLParserWrapper
        Get the document element, optionally discarding the document. The return value of this method is the same as OMXMLParserWrapper.getDocumentElement(). However, if the discardDocument parameter is set to true, then the document element is removed from the document and the document itself is discarded. In contrast to using OMNode.detach() this will not build the element. The implementation also ensures that the element is not built when it is added to another OM tree. This makes it possible to add the content of a document to an existing OM tree while preserving the deferred parsing feature. It is even possible to create an OM tree where different subtrees are associated with different builder instances.
        Parameters:
        discardDocument - specifies whether the document should be discarded
        Returns:
        the document element
      • setDoDebug

        public void setDoDebug​(boolean doDebug)
        Deprecated.
        Parameters:
        doDebug -
      • createPrefix

        protected String createPrefix()
      • setNamespaceURIInterning

        public void setNamespaceURIInterning​(boolean b)
        Set namespace uri interning
        Parameters:
        b -
      • isNamespaceURIInterning

        public boolean isNamespaceURIInterning()
        Returns:
        if namespace uri interning
      • lookahead

        public boolean lookahead()
        This method looks ahead to the next start element.
        Returns:
        true if successful