com.ctc.wstx.evt
Class WstxEventReader

java.lang.Object
  extended by com.ctc.wstx.evt.WstxEventReader
All Implemented Interfaces:
java.util.Iterator, javax.xml.stream.XMLEventReader, javax.xml.stream.XMLStreamConstants, XMLEventReader2

public class WstxEventReader
extends java.lang.Object
implements XMLEventReader2, javax.xml.stream.XMLStreamConstants

Implementation of XMLEventReader, built on top of BasicStreamReader (using composition). 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: trickiest things to implement are:


Field Summary
protected  int mPrePeekEvent
          This variable keeps track of the type of the 'previous' event when peeking for the next Event.
protected  int mState
          High-level state indicator, with currently three values: whether we are initializing (need to synthetize START_DOCUMENT), at EOD (end-of-doc), or otherwise, normal operation.
protected static int STATE_CONTENT
           
protected static int STATE_EOD
           
protected static int STATE_INITIAL
           
 
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
 
Constructor Summary
WstxEventReader(javax.xml.stream.util.XMLEventAllocator a, javax.xml.stream.XMLStreamReader r)
           
 
Method Summary
 void close()
           
protected  javax.xml.stream.events.XMLEvent createNextEvent(boolean checkEOD, int type)
           
protected  javax.xml.stream.events.XMLEvent createStartEvent()
          Method called to create the very first START_DOCUMENT event.
 java.lang.String getElementText()
           
 java.lang.Object getProperty(java.lang.String name)
           
 boolean hasNext()
           
 boolean hasNextEvent()
           Note: although the interface allows implementations to throw an XMLStreamException, Woodstox doesn't currently need to.
 java.lang.Object next()
           
 javax.xml.stream.events.XMLEvent nextEvent()
           
 javax.xml.stream.events.XMLEvent nextTag()
           
 javax.xml.stream.events.XMLEvent peek()
           
 void remove()
          Note: only here because we implement Iterator interface
protected  void throwFromSex(javax.xml.stream.XMLStreamException sex)
           
protected  void throwParseError(java.lang.String msg)
           
protected  void throwParseError(java.lang.String msg, javax.xml.stream.Location loc)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_INITIAL

protected static final int STATE_INITIAL
See Also:
Constant Field Values

STATE_EOD

protected static final int STATE_EOD
See Also:
Constant Field Values

STATE_CONTENT

protected static final int STATE_CONTENT
See Also:
Constant Field Values

mState

protected int mState
High-level state indicator, with currently three values: whether we are initializing (need to synthetize START_DOCUMENT), at EOD (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 Detail

WstxEventReader

public WstxEventReader(javax.xml.stream.util.XMLEventAllocator a,
                       javax.xml.stream.XMLStreamReader r)
Method Detail

close

public void close()
           throws javax.xml.stream.XMLStreamException
Specified by:
close in interface javax.xml.stream.XMLEventReader
Throws:
javax.xml.stream.XMLStreamException

getElementText

public java.lang.String getElementText()
                                throws javax.xml.stream.XMLStreamException
Specified by:
getElementText in interface javax.xml.stream.XMLEventReader
Throws:
javax.xml.stream.XMLStreamException

getProperty

public java.lang.Object getProperty(java.lang.String name)
Specified by:
getProperty in interface javax.xml.stream.XMLEventReader

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator
Specified by:
hasNext in interface javax.xml.stream.XMLEventReader

nextEvent

public javax.xml.stream.events.XMLEvent nextEvent()
                                           throws javax.xml.stream.XMLStreamException
Specified by:
nextEvent in interface javax.xml.stream.XMLEventReader
Throws:
javax.xml.stream.XMLStreamException

next

public java.lang.Object next()
Specified by:
next in interface java.util.Iterator

nextTag

public javax.xml.stream.events.XMLEvent nextTag()
                                         throws javax.xml.stream.XMLStreamException
Specified by:
nextTag in interface javax.xml.stream.XMLEventReader
Throws:
javax.xml.stream.XMLStreamException

peek

public javax.xml.stream.events.XMLEvent peek()
                                      throws javax.xml.stream.XMLStreamException
Specified by:
peek in interface javax.xml.stream.XMLEventReader
Throws:
javax.xml.stream.XMLStreamException

remove

public void remove()
Note: only here because we implement Iterator interface

Specified by:
remove in interface java.util.Iterator

hasNextEvent

public boolean hasNextEvent()
                     throws javax.xml.stream.XMLStreamException

Note: although the interface allows implementations to throw an XMLStreamException, Woodstox doesn't currently need to. It's still declared, in case in future there is need to throw such an exception.

Specified by:
hasNextEvent in interface XMLEventReader2
Throws:
javax.xml.stream.XMLStreamException

createNextEvent

protected javax.xml.stream.events.XMLEvent createNextEvent(boolean checkEOD,
                                                           int type)
                                                    throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

createStartEvent

protected javax.xml.stream.events.XMLEvent createStartEvent()
                                                     throws javax.xml.stream.XMLStreamException
Method called to create the very first START_DOCUMENT event.

Throws:
javax.xml.stream.XMLStreamException

throwFromSex

protected void throwFromSex(javax.xml.stream.XMLStreamException sex)

throwParseError

protected void throwParseError(java.lang.String msg)
                        throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

throwParseError

protected void throwParseError(java.lang.String msg,
                               javax.xml.stream.Location loc)
                        throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException