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:
| Modifier and Type | Field and Description |
|---|---|
| protected static final int | ERR_GETELEMTEXT_NON_TEXT_EVENT
Encountered non-textual event (other than closing END_ELEMENT) when collecting text for getElementText() |
| protected static final int | ERR_GETELEMTEXT_NOT_START_ELEM
Current state when getElementText() called not START_ELEMENT |
| 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() |
| protected static final int | ERR_NEXTTAG_WRONG_TYPE
Encountered non-skippable non-text/element event with nextTag() |
| protected final XMLEventAllocator | |
| protected XMLEvent | mPeekedEvent
Event that has been peeked, ie. |
| protected int | mPrePeekEvent
This variable keeps track of the type of the 'previous' event when peeking for the next Event. |
| protected final XMLStreamReader2 | |
| 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. |
| protected static final int | |
| protected static final int | |
| protected static final int |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| protected XMLStreamException | |
| public void | close()
Implements javax. |
| protected XMLEvent | |
| protected XMLEvent | |
| protected final String | |
| public String | getElementText()
Implements javax. |
| protected abstract String | getErrorDesc(int
Type of the problem, one of errorType, int ERR_
constantsType of the event that triggered the problem,
if any; -1 if not available. eventType)Method called upon encountering a problem that should result in an exception being thrown. |
| public Object | getProperty(String
The name of the property name)Implements javax. |
| protected XMLStreamReader | |
| public boolean | |
| public boolean | hasNextEvent()
Implements org. Note although the interface allows implementations to
throw an |
| public abstract boolean | isPropertySupported(String name)
Redeclares org. javax., used
to determine whether a property is supported by the Reader
instance.
|
| public Object | |
| public XMLEvent | |
| public XMLEvent | nextTag()
Implements javax. |
| public XMLEvent | peek()
Implements javax. |
| public void | remove()
Overrides default java. Note only here because we implement Iterator interface. |
| protected void | |
| protected void | |
| public abstract boolean | setProperty(String
Name of the property to set name, Object Value to set property to. value)Redeclares org. org.
instance.
|
| protected void | |
| protected void | |
| protected void |
| ERR_GETELEMTEXT_NON_TEXT_EVENT | back to summary |
|---|---|
| protected static final int ERR_GETELEMTEXT_NON_TEXT_EVENT Encountered non-textual event (other than closing END_ELEMENT) when collecting text for getElementText() | |
| ERR_GETELEMTEXT_NOT_START_ELEM | back to summary |
|---|---|
| protected static final int ERR_GETELEMTEXT_NOT_START_ELEM Current state when getElementText() called not START_ELEMENT | |
| ERR_NEXTTAG_NON_WS_TEXT | back to summary |
|---|---|
| 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() | |
| ERR_NEXTTAG_WRONG_TYPE | back to summary |
|---|---|
| protected static final int ERR_NEXTTAG_WRONG_TYPE Encountered non-skippable non-text/element event with nextTag() | |
| mAllocator | back to summary |
|---|---|
| protected final XMLEventAllocator mAllocator | |
| mPeekedEvent | back to summary |
|---|---|
| protected XMLEvent mPeekedEvent Event that has been peeked, ie. loaded without call to
| |
| mPrePeekEvent | back to summary |
|---|---|
| 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. | |
| mReader | back to summary |
|---|---|
| protected final XMLStreamReader2 mReader | |
| mState | back to summary |
|---|---|
| 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. | |
| STATE_CONTENT | back to summary |
|---|---|
| protected static final int STATE_CONTENT | |
| STATE_END_OF_INPUT | back to summary |
|---|---|
| protected static final int STATE_END_OF_INPUT | |
| STATE_INITIAL | back to summary |
|---|---|
| protected static final int STATE_INITIAL | |
| Stax2EventReaderImpl | back to summary |
|---|---|
| protected Stax2EventReaderImpl(XMLEventAllocator a, XMLStreamReader2 r) | |
| _checkUnwrap | back to summary |
|---|---|
| protected XMLStreamException _checkUnwrap(RuntimeException rex) | |
| close | back to summary |
|---|---|
| public void close() throws XMLStreamException Implements javax. Doc from javax. Frees any resources associated with this Reader. This method does not close the underlying input source.
| |
| createNextEvent | back to summary |
|---|---|
| protected XMLEvent createNextEvent(boolean checkEOD, int type) throws XMLStreamException | |
| createStartDocumentEvent | back to summary |
|---|---|
| protected XMLEvent createStartDocumentEvent() throws XMLStreamException Method called to create the very first event (START_DOCUMENT). | |
| findErrorDesc | back to summary |
|---|---|
| protected final String findErrorDesc(int errorType, int currEvent) Method used to locate error message description to use.
Calls sub-classes | |
| getElementText | back to summary |
|---|---|
| public String getElementText() throws XMLStreamException Implements javax. Doc from javax. Reads the content of a text-only element. Precondition: the current event is START_ELEMENT. Postcondition: The current event is the corresponding END_ELEMENT.
| |
| getErrorDesc | back to summary |
|---|---|
| protected abstract String getErrorDesc(int errorType, int eventType) Method called upon encountering a problem that should result in an exception being thrown. If non-null String is returned. that will be used as the message of exception thrown; if null, a standard message will be used instead.
| |
| getProperty | back to summary |
|---|---|
| public Object getProperty(String name) Implements javax. Doc from javax. Get the value of a feature/property from the underlying implementation | |
| getStreamReader | back to summary |
|---|---|
| protected XMLStreamReader getStreamReader() | |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements javax. Doc from javax. Check if there are more events. Returns true if there are more events and false otherwise.
| |
| hasNextEvent | back to summary |
|---|---|
| public boolean hasNextEvent() throws XMLStreamException Implements org. Note although the interface allows implementations to
throw an
| |
| isPropertySupported | back to summary |
|---|---|
| public abstract boolean isPropertySupported(String name) Redeclares org. Doc from org. Method similar to
| |
| next | back to summary |
|---|---|
| public Object next() Implements java. Doc from java. Returns the next element in the iteration. | |
| nextEvent | back to summary |
|---|---|
| public XMLEvent nextEvent() throws XMLStreamException Implements javax. Doc from javax. Gets the next XMLEvent. The initial event is
| |
| nextTag | back to summary |
|---|---|
| public XMLEvent nextTag() throws XMLStreamException Implements javax. Doc from javax. Skips any insignificant space events until a START_ELEMENT or END_ELEMENT is reached. If anything other than space characters are encountered, an exception is thrown. This method should be used when processing element-only content because the parser is not able to recognize ignorable whitespace if the DTD is missing or not interpreted.
| |
| peek | back to summary |
|---|---|
| public XMLEvent peek() throws XMLStreamException Implements javax. Doc from javax. Check the next XMLEvent without reading it from the stream. Returns null if the stream is at EOF or has no more XMLEvents. A call to peek() will be equal to the next return of next().
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Note only here because we implement Iterator interface. Will not work, don't bother calling it.
| |
| reportProblem | back to summary |
|---|---|
| protected void reportProblem(String msg) throws XMLStreamException | |
| reportProblem | back to summary |
|---|---|
| protected void reportProblem(String msg, Location loc) throws XMLStreamException | |
| setProperty | back to summary |
|---|---|
| public abstract boolean setProperty(String name, Object value) Redeclares org. Doc from org. Method that can be used to set per-reader properties; a subset of
properties one can set via matching
| |
| throwEndOfInput | back to summary |
|---|---|
| protected void throwEndOfInput() | |
| throwUnchecked | back to summary |
|---|---|
| protected void throwUnchecked(XMLStreamException sex) | |
| updateStateEndDocument | back to summary |
|---|---|
| protected void updateStateEndDocument() throws XMLStreamException Method called when we are about to return
| |