public abstract class Stax2EventReaderImpl extends Object implements XMLEventReader2, XMLStreamConstants
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 int |
ERR_GETELEMTEXT_NON_TEXT_EVENT
Encountered non-textual event (other than closing END_ELEMENT)
when collecting text for getElementText()
|
protected static int |
ERR_GETELEMTEXT_NOT_START_ELEM
Current state when getElementText() called not START_ELEMENT
|
protected static 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 int |
ERR_NEXTTAG_WRONG_TYPE
Encountered non-skippable non-text/element event with
nextTag()
|
protected XMLEventAllocator |
mAllocator |
protected int |
mPrePeekEvent
This variable keeps track of the type of the 'previous' event
when peeking for the next Event.
|
protected XMLStreamReader2 |
mReader |
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 int |
STATE_CONTENT |
protected static int |
STATE_END_OF_INPUT |
protected static int |
STATE_INITIAL |
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT| Modifier | Constructor and Description |
|---|---|
protected |
Stax2EventReaderImpl(XMLEventAllocator a,
XMLStreamReader2 r) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected XMLEvent |
createNextEvent(boolean checkEOD,
int type) |
protected XMLEvent |
createStartDocumentEvent()
Method called to create the very first event (START_DOCUMENT).
|
String |
getElementText() |
protected abstract String |
getErrorDesc(int errorType,
int eventType)
Method called upon encountering a problem that should result
in an exception being thrown.
|
Object |
getProperty(String name) |
protected XMLStreamReader |
getStreamReader() |
boolean |
hasNext() |
boolean |
hasNextEvent()
Note: although the interface allows implementations to
throw an
XMLStreamException, the reference implementation
doesn't currently need to. |
abstract boolean |
isPropertySupported(String name)
Method similar to
XMLInputFactory.isPropertySupported(java.lang.String), used
to determine whether a property is supported by the Reader
instance. |
Object |
next() |
XMLEvent |
nextEvent() |
XMLEvent |
nextTag() |
XMLEvent |
peek() |
void |
remove()
Note: only here because we implement Iterator interface.
|
protected void |
reportProblem(String msg) |
protected void |
reportProblem(String msg,
Location loc) |
abstract boolean |
setProperty(String name,
Object value)
Method that can be used to set per-reader properties; a subset of
properties one can set via matching
XMLInputFactory2
instance. |
protected void |
throwUnchecked(XMLStreamException sex) |
protected static final int STATE_INITIAL
protected static final int STATE_END_OF_INPUT
protected static final int STATE_CONTENT
protected static final int ERR_GETELEMTEXT_NOT_START_ELEM
protected static final int ERR_GETELEMTEXT_NON_TEXT_EVENT
protected static final int ERR_NEXTTAG_NON_WS_TEXT
protected static final int ERR_NEXTTAG_WRONG_TYPE
protected final XMLEventAllocator mAllocator
protected final XMLStreamReader2 mReader
protected int mState
protected int mPrePeekEvent
protected Stax2EventReaderImpl(XMLEventAllocator a, XMLStreamReader2 r)
public abstract boolean isPropertySupported(String name)
XMLEventReader2XMLInputFactory.isPropertySupported(java.lang.String), used
to determine whether a property is supported by the Reader
instance. This means that this method may return false
for some properties that the input factory does support: specifically,
it should only return true if the value is mutable on per-instance
basis. False means that either the property is not recognized, or
is not mutable via reader instance.isPropertySupported in interface XMLEventReader2public abstract boolean setProperty(String name, Object value)
XMLEventReader2XMLInputFactory2
instance. Exactly which methods are mutable is implementation
specific.setProperty in interface XMLEventReader2name - Name of the property to setvalue - Value to set property to.protected abstract String getErrorDesc(int errorType, int eventType)
errorType - Type of the problem, one of ERR_
constantseventType - Type of the event that triggered the problem,
if any; -1 if not available.public void close()
throws XMLStreamException
close in interface XMLEventReaderXMLStreamExceptionpublic String getElementText() throws XMLStreamException
getElementText in interface XMLEventReaderXMLStreamExceptionpublic Object getProperty(String name)
getProperty in interface XMLEventReaderpublic boolean hasNext()
hasNext in interface IteratorhasNext in interface XMLEventReaderpublic XMLEvent nextEvent() throws XMLStreamException
nextEvent in interface XMLEventReaderXMLStreamExceptionpublic XMLEvent nextTag() throws XMLStreamException
nextTag in interface XMLEventReaderXMLStreamExceptionpublic XMLEvent peek() throws XMLStreamException
peek in interface XMLEventReaderXMLStreamExceptionpublic void remove()
public boolean hasNextEvent()
throws XMLStreamException
Note: although the interface allows implementations to
throw an XMLStreamException, the reference implementation
doesn't currently need to.
It's still declared, in case in future there is need to throw
such an exception.
hasNextEvent in interface XMLEventReader2XMLStreamExceptionprotected XMLEvent createNextEvent(boolean checkEOD, int type) throws XMLStreamException
XMLStreamExceptionprotected XMLEvent createStartDocumentEvent() throws XMLStreamException
XMLStreamExceptionprotected void throwUnchecked(XMLStreamException sex)
protected void reportProblem(String msg) throws XMLStreamException
XMLStreamExceptionprotected void reportProblem(String msg, Location loc) throws XMLStreamException
XMLStreamExceptionprotected XMLStreamReader getStreamReader()
Copyright © 2015 fasterxml.com. All Rights Reserved.