Class Stax2EventReaderImpl
java.lang.Object
org.codehaus.stax2.ri.Stax2EventReaderImpl
- All Implemented Interfaces:
Iterator<Object>, 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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final intEncountered non-textual event (other than closing END_ELEMENT) when collecting text for getElementText()protected static final intCurrent state when getElementText() called not START_ELEMENTprotected static final intEncountered CHARACTERS or CDATA that contains non-white space char(s), when trying to locate tag with nextTag()protected static final intEncountered non-skippable non-text/element event with nextTag()protected final XMLEventAllocatorprotected XMLEventEvent that has been peeked, ie.protected intThis variable keeps track of the type of the 'previous' event when peeking for the next Event.protected final XMLStreamReader2protected intHigh-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 intprotected static final intprotected static final intFields inherited from interface 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
ConstructorsModifierConstructorDescriptionprotected -
Method Summary
Modifier and TypeMethodDescriptionprotected XMLStreamExceptionvoidclose()protected XMLEventcreateNextEvent(boolean checkEOD, int type) protected XMLEventMethod called to create the very first event (START_DOCUMENT).protected final StringfindErrorDesc(int errorType, int currEvent) Method used to locate error message description to use.protected abstract StringgetErrorDesc(int errorType, int eventType) Method called upon encountering a problem that should result in an exception being thrown.getProperty(String name) protected XMLStreamReaderbooleanhasNext()booleanNote: although the interface allows implementations to throw anXMLStreamException, the reference implementation doesn't currently need to.abstract booleanisPropertySupported(String name) Method similar toXMLInputFactory.isPropertySupported(String), used to determine whether a property is supported by the Reader instance.next()nextTag()peek()voidremove()Note: only here because we implement Iterator interface.protected voidreportProblem(String msg) protected voidreportProblem(String msg, Location loc) abstract booleansetProperty(String name, Object value) Method that can be used to set per-reader properties; a subset of properties one can set via matchingXMLInputFactory2instance.protected voidprotected voidprotected voidMethod called when we are about to returnEND_DOCUMENTevent.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterator
forEachRemaining
-
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_ELEMCurrent state when getElementText() called not START_ELEMENT- See Also:
-
ERR_GETELEMTEXT_NON_TEXT_EVENT
protected static final int ERR_GETELEMTEXT_NON_TEXT_EVENTEncountered 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_TEXTEncountered 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_TYPEEncountered non-skippable non-text/element event with nextTag()- See Also:
-
mAllocator
-
mReader
-
mPeekedEvent
Event that has been peeked, ie. loaded without call tonextEvent(); will be returned and cleared by call tonextEvent()(or, returned again if peeked again) -
mState
protected int mStateHigh-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 mPrePeekEventThis 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
-
Stax2EventReaderImpl
-
-
Method Details
-
isPropertySupported
Description copied from interface:XMLEventReader2Method similar toXMLInputFactory.isPropertySupported(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.- Specified by:
isPropertySupportedin interfaceXMLEventReader2
-
setProperty
Description copied from interface:XMLEventReader2Method that can be used to set per-reader properties; a subset of properties one can set via matchingXMLInputFactory2instance. Exactly which methods are mutable is implementation specific.- Specified by:
setPropertyin interfaceXMLEventReader2- Parameters:
name- Name of the property to setvalue- Value to set property to.- Returns:
- True, if the specified property was succesfully set to specified value; false if its value was not changed
-
getErrorDesc
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.- Parameters:
errorType- Type of the problem, one ofERR_constantseventType- Type of the event that triggered the problem, if any; -1 if not available.
-
close
- Specified by:
closein interfaceXMLEventReader- Throws:
XMLStreamException
-
getElementText
- Specified by:
getElementTextin interfaceXMLEventReader- Throws:
XMLStreamException
-
getProperty
- Specified by:
getPropertyin interfaceXMLEventReader
-
hasNext
public boolean hasNext()- Specified by:
hasNextin interfaceIterator<Object>- Specified by:
hasNextin interfaceXMLEventReader
-
nextEvent
- Specified by:
nextEventin interfaceXMLEventReader- Throws:
XMLStreamException
-
next
-
nextTag
- Specified by:
nextTagin interfaceXMLEventReader- Throws:
XMLStreamException
-
peek
- Specified by:
peekin interfaceXMLEventReader- Throws:
XMLStreamException
-
remove
-
updateStateEndDocument
Method called when we are about to returnEND_DOCUMENTevent. Usually this should change state toSTATE_END_OF_INPUT, but may vary for some alternative read modes (like multi-document)- Throws:
XMLStreamException- Since:
- 4.2
-
hasNextEvent
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.- Specified by:
hasNextEventin interfaceXMLEventReader2- Throws:
XMLStreamException
-
createNextEvent
- Throws:
XMLStreamException
-
_checkUnwrap
-
createStartDocumentEvent
Method called to create the very first event (START_DOCUMENT).- Throws:
XMLStreamException
-
throwEndOfInput
protected void throwEndOfInput() -
throwUnchecked
-
reportProblem
- Throws:
XMLStreamException
-
reportProblem
- Throws:
XMLStreamException
-
getStreamReader
-
findErrorDesc
Method used to locate error message description to use. Calls sub-classesgetErrorDesc()first, and only if no message found, uses default messages defined here.
-