Class Stax2EventReaderImpl

java.lang.Object
org.codehaus.stax2.ri.Stax2EventReaderImpl
All Implemented Interfaces:
Iterator, XMLEventReader, XMLStreamConstants, XMLEventReader2

public abstract class Stax2EventReaderImpl extends Object implements XMLEventReader2, XMLStreamConstants
Almost complete implementation of XMLEventReader2, built on top of a generic XMLStreamReader implementation (using aggregation). Designed to be used by concrete Stax2 implementations to provide full Event API implementation with minimal effort.

Since there is not much to optimize at this level (API and underlying stream reader pretty much define functionality and optimizations that can be done), implementation is fairly straight forward, with not many surprises.

Implementation notes: the trickiest things to implement are:

  • Peek() functionality! Geez, why did that have to be part of StAX specs???!
  • Adding START_DOCUMENT event that cursor API does not return explicitly.
  • Field Details

    • STATE_INITIAL

      protected static final int STATE_INITIAL
      See Also:
    • STATE_END_OF_INPUT

      protected static final int STATE_END_OF_INPUT
      See Also:
    • STATE_CONTENT

      protected static final int STATE_CONTENT
      See Also:
    • ERR_GETELEMTEXT_NOT_START_ELEM

      protected static final int ERR_GETELEMTEXT_NOT_START_ELEM
      Current state when getElementText() called not START_ELEMENT
      See Also:
    • ERR_GETELEMTEXT_NON_TEXT_EVENT

      protected static final int ERR_GETELEMTEXT_NON_TEXT_EVENT
      Encountered non-textual event (other than closing END_ELEMENT) when collecting text for getElementText()
      See Also:
    • ERR_NEXTTAG_NON_WS_TEXT

      protected static final int ERR_NEXTTAG_NON_WS_TEXT
      Encountered CHARACTERS or CDATA that contains non-white space char(s), when trying to locate tag with nextTag()
      See Also:
    • ERR_NEXTTAG_WRONG_TYPE

      protected static final int ERR_NEXTTAG_WRONG_TYPE
      Encountered non-skippable non-text/element event with nextTag()
      See Also:
    • mAllocator

      protected final XMLEventAllocator mAllocator
    • mReader

      protected final XMLStreamReader2 mReader
    • mPeekedEvent

      protected XMLEvent mPeekedEvent
      Event that has been peeked, ie. loaded without call to nextEvent(); will be returned and cleared by call to nextEvent() (or, returned again if peeked again)
    • mState

      protected int mState
      High-level state indicator, with currently three values: whether we are initializing (need to synthetize START_DOCUMENT), at END_OF_INPUT (end-of-doc), or otherwise, normal operation. Useful in simplifying some methods, as well as to make sure that independent of how stream reader handles things, event reader can reliably detect End-Of-Document.
    • mPrePeekEvent

      protected int mPrePeekEvent
      This variable keeps track of the type of the 'previous' event when peeking for the next Event. It is needed for some functionality, to remember state even when underlying parser has to move to peek the next event.
  • Constructor Details

  • Method Details