public class SMFlatteningCursor extends SMInputCursor
Differences to SMHierarchicCursor
are:
XMLStreamConstants.END_ELEMENT
nodes (except
for the one that closes the outermost level), unless
filtered out by the filter, whereas the nested cursor automatically
leaves those out.
Modifier and Type | Class and Description |
---|---|
static class |
CursorBase.State
State constants are used for keeping track of state of individual
cursors.
|
SMInputCursor.Tracking
Modifier and Type | Field and Description |
---|---|
protected int |
_baseDepth
Depth the underlying stream reader had when this cursor was
created (which is the number of currently open parent elements).
|
protected SMInputCursor |
_childCursor
Cursor that has been opened for iterating child nodes of the
start element node this cursor points to.
|
protected SMInputContext |
_context |
protected SMEvent |
_currEvent
Event that this cursor currently points to, if valid, or
it last pointed to if not (including null if cursor has not
yet been advanced).
|
protected int |
_elemCount
Number of start elements iterated over by this cursor, including the
current one.
|
protected int |
_nodeCount
Number of nodes iterated over by this cursor, including the
current one.
|
protected SMElementInfo |
_parentTrackedElement
Element that the parent of this cursor tracked (if any),
when this cursor was created.
|
protected CursorBase.State |
_state
Current state of the cursor.
|
protected org.codehaus.stax2.XMLStreamReader2 |
_streamReader
Underlying stream reader used.
|
protected SMElementInfo |
_trackedElement
Element that was last "tracked"; element over which cursor was
moved, and of which state has been saved for further use.
|
mData, mElemInfoFactory, mElemTracking, mFilter
Constructor and Description |
---|
SMFlatteningCursor(SMInputContext ctxt,
SMInputCursor parent,
SMFilter f) |
Modifier and Type | Method and Description |
---|---|
protected org.codehaus.stax2.XMLStreamReader2 |
_getStreamReader()
Internal method (but available to sub-classes) that allows
access to the underlying stream reader.
|
protected XMLStreamException |
_notAccessible(String method)
Internal method for throwing a stream exception that indicates
that given method can not be called because the cursor does
not point to event of expected type.
|
protected XMLStreamException |
_wrongState(String method,
SMEvent expState) |
SMInputCursor |
constructChildCursor(SMFilter f)
Abstract method that concrete sub-classes implement, and is used
for all instantiation of child cursors by this cursor instance.
|
SMInputCursor |
constructDescendantCursor(SMFilter f)
Abstract method that concrete sub-classes implement, and is used
for all instantiation of descendant cursors by this cursor instance.
|
protected String |
currentEventStr()
Method for constructing human-readable description of the event
this cursor points to (if cursor valid) or last pointed to (if
not valid; possibly null if cursor has not yet been advanced).
|
protected static SMEvent |
eventObjectByEventId(int type)
Note: no checks are done regarding validity of passed-in
type.
|
protected int |
getBaseParentCount()
This method is needed by flattening cursors when they
have child cursors: if so, they can determine their
depth relative to child cursor's base parent count
(and can not check stream -- as it may have moved --
nor want to have separate field to track this information)
|
SMEvent |
getNext()
Main iterating method.
|
int |
getParentCount()
Number of parent elements that the token/event cursor points to has,
if it points to one.
|
protected String |
getStateDesc() |
protected void |
invalidate()
Method called by the parent cursor, to indicate it has to
traverse over xml content and that child cursor as well
as all of its descendant cursors (if any) are to be
considered invalid.
|
protected void |
rewindPastChild()
Method called to skim through the content that the child
cursor(s) are pointing to, end return once next call to
XMLStreamReader2.next() will return the next event
this cursor should see.
|
_markConsumed, advance, asEvent, childCursor, childCursor, childElementCursor, childElementCursor, childElementCursor, childMixedCursor, collectDescendantText, collectDescendantText, constructElementInfo, constructStreamException, descendantCursor, descendantCursor, descendantElementCursor, descendantElementCursor, descendantElementCursor, descendantMixedCursor, findAttrIndex, getAttrBinaryValue, getAttrBinaryValue, getAttrBooleanValue, getAttrBooleanValue, getAttrCount, getAttrDoubleValue, getAttrDoubleValue, getAttrEnumValue, getAttrIntValue, getAttrIntValue, getAttrIntValue, getAttrIntValue, getAttrLocalName, getAttrLongValue, getAttrLongValue, getAttrName, getAttrNsUri, getAttrPrefix, getAttrValue, getAttrValue, getAttrValue, getCurrEvent, getCurrEventCode, getCurrEventDesc, getCursorLocation, getData, getElemBinaryValue, getElemBinaryValue, getElemBooleanValue, getElemBooleanValue, getElemDoubleValue, getElemDoubleValue, getElementCount, getElementInfoFactory, getElementTracking, getElemEnumValue, getElemIntValue, getElemIntValue, getElemLongValue, getElemLongValue, getElemStringValue, getLocalName, getLocation, getNodeCount, getNsUri, getParentTrackedElement, getPathDesc, getPrefix, getPrefixedName, getQName, getStreamLocation, getStreamReader, getText, getTrackedElement, hasLocalName, hasName, hasName, isRootCursor, processDescendantText, readerAccessible, setData, setElementInfoFactory, setElementTracking, setFilter, throwStreamException, toString
protected final SMInputContext _context
protected final org.codehaus.stax2.XMLStreamReader2 _streamReader
XMLStreamReader2
instance, or a regular (Stax 1.0)
XMLStreamReader
wrapped in an
adapter.protected final int _baseDepth
protected CursorBase.State _state
protected SMEvent _currEvent
protected int _nodeCount
protected int _elemCount
protected SMElementInfo _trackedElement
protected SMElementInfo _parentTrackedElement
protected SMInputCursor _childCursor
public SMFlatteningCursor(SMInputContext ctxt, SMInputCursor parent, SMFilter f)
public int getParentCount()
SMInputCursor
For example, here are expected return values for an example XML document:
<!-- Comment outside tree --> [0] <root> [0] Text [1] <branch> [1] Inner text [2] <child /> [2]/[2] </branch> [1] </root> [0]Numbers in bracket are depths that would be returned when the cursor points to the node.
Note: depths are different from what many other xml processing APIs (such as Stax and XmlPull)return.
getParentCount
in class SMInputCursor
public SMEvent getNext() throws XMLStreamException
SMInputCursor
Note that one side-effect of calling this method is to invalidate the child cursor, if one was active. This is done by iterating over any events child cursor (and its descendants if any) might expose.
getNext
in class SMInputCursor
XMLStreamConstants
, such as
XMLStreamConstants.START_ELEMENT
, if a new node was
iterated over; null
when there are no more
nodes this cursor can iterate over.XMLStreamException
- If there are underlying parsing
problems.public SMInputCursor constructChildCursor(SMFilter f)
SMInputCursor
Note that custom cursor implementations can be used by overriding this method.
constructChildCursor
in class SMInputCursor
public SMInputCursor constructDescendantCursor(SMFilter f)
SMInputCursor
Note that custom cursor implementations can be used by overriding this method.
constructDescendantCursor
in class SMInputCursor
protected final int getBaseParentCount()
protected final void rewindPastChild() throws XMLStreamException
XMLStreamException
protected void invalidate() throws XMLStreamException
XMLStreamException
protected final org.codehaus.stax2.XMLStreamReader2 _getStreamReader()
protected static final SMEvent eventObjectByEventId(int type)
Note: no checks are done regarding validity of passed-in type.
SMEvent
matching given typeprotected XMLStreamException _notAccessible(String method) throws XMLStreamException
XMLStreamException
protected XMLStreamException _wrongState(String method, SMEvent expState) throws XMLStreamException
XMLStreamException
protected String getStateDesc()
protected String currentEventStr()
Copyright © 2013 FasterXML. All Rights Reserved.