Class SMHierarchicCursor
java.lang.Object
org.codehaus.staxmate.in.SMInputCursor
org.codehaus.staxmate.in.SMHierarchicCursor
Default implementation of generic nested (scoped) cursor; cursor that only
traverses direct children of a single start element.
- Author:
- Tatu Saloranta
-
Nested Class Summary
Nested classes/interfaces inherited from class SMInputCursor
SMInputCursor.Tracking -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intDepth the underlying stream reader had when this cursor was created (which is the number of currently open parent elements). 0 only for root cursor.protected SMInputCursorCursor that has been opened for iterating child nodes of the start element node this cursor points to.protected final SMInputContextprotected SMEventEvent 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 intNumber of start elements iterated over by this cursor, including the current one.protected intNumber of nodes iterated over by this cursor, including the current one.protected SMElementInfoElement that the parent of this cursor tracked (if any), when this cursor was created.protected org.codehaus.staxmate.in.CursorBase.StateCurrent state of the cursor.protected final org.codehaus.stax2.XMLStreamReader2Underlying stream reader used.protected SMElementInfoElement that was last "tracked"; element over which cursor was moved, and of which state has been saved for further use.Fields inherited from class SMInputCursor
mData, mElemInfoFactory, mElemTracking, mFilter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final org.codehaus.stax2.XMLStreamReader2Internal 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) Abstract method that concrete sub-classes implement, and is used for all instantiation of child cursors by this cursor instance.Abstract method that concrete sub-classes implement, and is used for all instantiation of descendant cursors by this cursor instance.protected StringMethod 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 final SMEventeventObjectByEventId(int type) Note: no checks are done regarding validity of passed-in type.protected final intThis 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)getNext()Main iterating method.intNumber of parent elements that the token/event cursor points to has, if it points to one.protected Stringprotected voidMethod 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 final voidMethod 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.protected voidMethod called when current event/token is START_ELEMENT, but we are not interested in its contents (children).Methods inherited from class SMInputCursor
_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
-
Field Details
-
_context
-
_streamReader
protected final org.codehaus.stax2.XMLStreamReader2 _streamReaderUnderlying stream reader used. It will either be a nativeXMLStreamReader2instance, or a regular (Stax 1.0)XMLStreamReaderwrapped in an adapter. -
_baseDepth
protected final int _baseDepthDepth the underlying stream reader had when this cursor was created (which is the number of currently open parent elements). 0 only for root cursor. -
_state
protected org.codehaus.staxmate.in.CursorBase.State _stateCurrent state of the cursor. -
_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). -
_nodeCount
protected int _nodeCountNumber of nodes iterated over by this cursor, including the current one. -
_elemCount
protected int _elemCountNumber of start elements iterated over by this cursor, including the current one. -
_trackedElement
Element that was last "tracked"; element over which cursor was moved, and of which state has been saved for further use. At this point, it can be null if no elements have yet been iterater over. Alternatively, if it's not null, it may be currently pointed to or not; if it's not, either child cursor is active, or this cursor points to a non-start-element node. -
_parentTrackedElement
Element that the parent of this cursor tracked (if any), when this cursor was created. -
_childCursor
Cursor that has been opened for iterating child nodes of the start element node this cursor points to. Needed to keep cursor hierarchy synchronized, independent of which ones are traversed.
-
-
Constructor Details
-
SMHierarchicCursor
-
-
Method Details
-
getParentCount
public int getParentCount()Description copied from class:SMInputCursorNumber of parent elements that the token/event cursor points to has, if it points to one. If not, either most recent valid parent count (if cursor is closed), or the depth that it will have once is is advanced. One practical result is that a nested cursor instance will always have a single constant value it returns, whereas flattening cursors can return different values during traversal. Another thing to notice that matching START_ELEMENT and END_ELEMENT will always correspond to the same parent count.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.
- Specified by:
getParentCountin classSMInputCursor- Returns:
- Number of enclosing nesting levels, ie. number of parent start elements for the node that cursor currently points to (or, in case of initial state, that it will point to if scope has node(s)).
-
getNext
Description copied from class:SMInputCursorMain iterating method. Will try to advance the cursor to the next visible event (visibility defined by the filter cursor is configured with, if any), and return event type. If no such events are available, will return null.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.
- Specified by:
getNextin classSMInputCursor- Returns:
- Type of event (from
XMLStreamConstants, such asXMLStreamConstants.START_ELEMENT, if a new node was iterated over;nullwhen there are no more nodes this cursor can iterate over. - Throws:
XMLStreamException- If there are underlying parsing problems.
-
constructChildCursor
Description copied from class:SMInputCursorAbstract method that concrete sub-classes implement, and is used for all instantiation of child cursors by this cursor instance.Note that custom cursor implementations can be used by overriding this method.
- Specified by:
constructChildCursorin classSMInputCursor
-
constructDescendantCursor
Description copied from class:SMInputCursorAbstract method that concrete sub-classes implement, and is used for all instantiation of descendant cursors by this cursor instance.Note that custom cursor implementations can be used by overriding this method.
- Specified by:
constructDescendantCursorin classSMInputCursor
-
skipToEndElement
Method called when current event/token is START_ELEMENT, but we are not interested in its contents (children). Hence, needs to skip all intervening events/tokens until matching END_ELEMENT is encountered.- Throws:
XMLStreamException
-
getBaseParentCount
protected final 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) -
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.- Throws:
XMLStreamException
-
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.- Throws:
XMLStreamException
-
_getStreamReader
protected final org.codehaus.stax2.XMLStreamReader2 _getStreamReader()Internal method (but available to sub-classes) that allows access to the underlying stream reader. -
eventObjectByEventId
-
_notAccessible
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. This can be either because cursor is invalid (doesn't point to any event), or because it points to "wrong" event type. Distinction is reflected in the exception message.- Throws:
XMLStreamException
-
_wrongState
- Throws:
XMLStreamException
-
getStateDesc
-
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).- Returns:
- Human-readable description of the underlying Stax event this cursor points to.
-