|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.codehaus.staxmate.in.SMInputCursor
public abstract class SMInputCursor
Base class for reader-side cursors that form the main input-side abstraction offered by StaxMate.
Note: since cursors are thin wrappers around XMLStreamReader2,
and since not all Stax implementations implement
XMLStreamReader2, some wrapping may be involved.
| Nested Class Summary | |
|---|---|
protected static class |
SMInputCursor.State
|
static class |
SMInputCursor.Tracking
This enumeration lists different tracking behaviors available for cursors. |
| Field Summary | |
|---|---|
protected int |
mBaseDepth
Depth the underlying stream reader had when this cursor was created (which is the number of currently open parent elements). |
protected SMInputCursor |
mChildCursor
Cursor that has been opened for iterating child nodes of the start element node this cursor points to. |
protected SMEvent |
mCurrEvent
|
protected java.lang.Object |
mData
Non-typesafe payload data that applications can use, to pass an extra argument along with cursors. |
protected int |
mElemCount
Number of start elements iterated over by this cursor, including the current one. |
protected ElementInfoFactory |
mElemInfoFactory
Optional factory instance that is used to create element info objects if element tracking is enabled. |
protected SMInputCursor.Tracking |
mElemTracking
Whether element information is to be tracked or not, and if it is, how much of it will be stored. |
protected SMFilter |
mFilter
Optional filter object that can be used to filter out events of types caller is not interested in. |
protected int |
mNodeCount
Number of nodes iterated over by this cursor, including the current one. |
protected SMElementInfo |
mParentTrackedElement
Element that the parent of this cursor tracked (if any), when this cursor was created. |
protected SMInputCursor.State |
mState
Current state of the cursor. |
protected org.codehaus.stax2.XMLStreamReader2 |
mStreamReader
Underlying stream reader used. |
protected SMElementInfo |
mTrackedElement
Element that was last "tracked"; element over which cursor was moved, and of which state has been saved for further use. |
protected static SMEvent[] |
sEventsByIds
This is the mapping array, indexed by Stax 1.0 event type integer code, value being matching SMEvent enumeration value. |
| Constructor Summary | |
|---|---|
SMInputCursor(SMInputCursor parent,
org.codehaus.stax2.XMLStreamReader2 sr,
SMFilter filter)
|
|
| Method Summary | |
|---|---|
SMInputCursor |
childCursor()
|
SMInputCursor |
childCursor(SMFilter f)
Method that will create a new nested cursor for iterating over all (immediate) child nodes of the start element this cursor currently points to. |
SMInputCursor |
childElementCursor()
Convenience method; equivalent to childCursor(SMFilterFactory.getElementOnlyFilter()); |
SMInputCursor |
childElementCursor(javax.xml.namespace.QName elemName)
Convenience method; equivalent to childCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element
name matches given qname. |
SMInputCursor |
childElementCursor(java.lang.String elemLocalName)
Convenience method; equivalent to childCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element's
local name matches given local name, and that does not belong to
a namespace. |
SMInputCursor |
childMixedCursor()
Convenience method; equivalent to childCursor(SMFilterFactory.getMixedFilter()); |
java.lang.String |
collectDescendantText(boolean includeIgnorable)
Method that can collect all text contained within START_ELEMENT currently pointed by this cursor. |
protected abstract SMInputCursor |
constructChildCursor(SMFilter f)
|
protected abstract SMInputCursor |
constructDescendantCursor(SMFilter f)
|
protected SMElementInfo |
constructElementInfo(SMElementInfo parent,
SMElementInfo prevSibling)
Method cursor calls when it needs to track element state information; if so, it calls this method to take a snapshot of the element. |
protected java.lang.String |
currentEventStr()
|
SMInputCursor |
descendantCursor()
|
SMInputCursor |
descendantCursor(SMFilter f)
Method that will create a new nested cursor for iterating over all the descendant (children and grandchildren) nodes of the start element this cursor currently points to. |
SMInputCursor |
descendantElementCursor()
Convenience method; equivalent to descendantCursor(SMFilterFactory.getElementOnlyFilter()); |
SMInputCursor |
descendantElementCursor(javax.xml.namespace.QName elemName)
Convenience method; equivalent to descendantCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element
name matches given qname. |
SMInputCursor |
descendantElementCursor(java.lang.String elemLocalName)
Convenience method; equivalent to descendantCursor(SMFilterFactory.getElementOnlyFilter(elemLocalName));. |
SMInputCursor |
descendantMixedCursor()
Convenience method; equivalent to descendantCursor(SMFilterFactory.getMixedFilter()); |
protected int |
doParseInt(java.lang.String valueStr)
|
protected int |
doParseInt(java.lang.String valueStr,
int defValue)
|
int |
findAttrIndex(java.lang.String uri,
java.lang.String localName)
|
int |
getAttrCount()
|
int |
getAttrIntValue(int index)
|
int |
getAttrIntValue(int index,
int defValue)
|
int |
getAttrIntValue(java.lang.String uri,
java.lang.String localName)
|
int |
getAttrIntValue(java.lang.String uri,
java.lang.String localName,
int defValue)
|
java.lang.String |
getAttrLocalName(int index)
|
javax.xml.namespace.QName |
getAttrName(int index)
|
java.lang.String |
getAttrNsUri(int index)
|
java.lang.String |
getAttrPrefix(int index)
|
java.lang.String |
getAttrValue(int index)
|
java.lang.String |
getAttrValue(java.lang.String localName)
Convenience accessor method to access an attribute that is not in a namespace (has no prefix). |
java.lang.String |
getAttrValue(java.lang.String uri,
java.lang.String localName)
|
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 |
getCurrEvent()
Returns the type of event this cursor either currently points to (if in valid state), or pointed to (if ever iterated forward), or null if just created. |
int |
getCurrEventCode()
Convenience method doing |
java.lang.Object |
getData()
|
int |
getDepth()
Deprecated. |
int |
getElementCount()
|
ElementInfoFactory |
getElementInfoFactory()
|
SMInputCursor.Tracking |
getElementTracking()
|
java.lang.String |
getLocalName()
For events with fully qualified names (START_ELEMENT, END_ELEMENT, ATTRIBUTE, NAMESPACE), returns the local component of the full name. |
javax.xml.stream.Location |
getLocation()
|
abstract SMEvent |
getNext()
Main iterating method. |
int |
getNodeCount()
|
java.lang.String |
getNsUri()
|
abstract int |
getParentCount()
Number of parent elements that the token/event cursor points to has, if it points to one. |
SMElementInfo |
getParentTrackedElement()
|
java.lang.String |
getPrefix()
|
java.lang.String |
getPrefixedName()
Returns a String representation of either the fully-qualified name (if the event has full name) or the local name (if event does not have full name but has local name); or if no name available, throws stream exception. |
javax.xml.namespace.QName |
getQName()
|
protected java.lang.String |
getStateDesc()
|
org.codehaus.stax2.XMLStreamReader2 |
getStreamReader()
Method that can be used to get direct access to the underlying stream reader. |
java.lang.String |
getText()
Method that can be used when this cursor points to a textual event; something for which XMLStreamReader.getText() can
be called. |
SMElementInfo |
getTrackedElement()
|
boolean |
hasLocalName(java.lang.String expName)
|
boolean |
hasName(java.lang.String expNsURI,
java.lang.String expLN)
|
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 boolean |
isRootCursor()
|
protected java.lang.String |
notAccessible(java.lang.String method)
|
void |
processDescendantText(java.io.Writer w,
boolean includeIgnorable)
Method similar to collectDescendantText(boolean), but will write
the text to specified Writer instead of collecting it into a
String. |
boolean |
readerAccessible()
|
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. |
void |
setData(java.lang.Object o)
|
void |
setElementInfoFactory(ElementInfoFactory f)
|
void |
setElementTracking(SMInputCursor.Tracking tracking)
Changes tracking mode of this cursor to the new specified mode. |
void |
setFilter(SMFilter f)
|
protected void |
throwUnexpectedEndDoc()
|
protected void |
throwWrongEndElem(int expDepth,
int actDepth)
|
protected void |
throwXsEx(java.lang.String msg)
|
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final SMEvent[] sEventsByIds
SMEvent enumeration value.
protected final org.codehaus.stax2.XMLStreamReader2 mStreamReader
XMLStreamReader2 instance, or a regular (Stax 1.0)
XMLStreamReader wrapped in an
adapter.
protected SMFilter mFilter
protected SMInputCursor.Tracking mElemTracking
SMInputCursor.Tracking for details.
protected ElementInfoFactory mElemInfoFactory
Note that by default, this factory will be passed down to child and descendant cursors this cursor creates, so usually one only needs to set the factory of the root cursor.
protected SMEvent mCurrEvent
protected SMInputCursor.State mState
protected int mNodeCount
protected int mElemCount
protected final int mBaseDepth
protected SMElementInfo mTrackedElement
protected SMElementInfo mParentTrackedElement
protected SMInputCursor mChildCursor
protected java.lang.Object mData
| Constructor Detail |
|---|
public SMInputCursor(SMInputCursor parent,
org.codehaus.stax2.XMLStreamReader2 sr,
SMFilter filter)
| Method Detail |
|---|
public final void setFilter(SMFilter f)
public final void setElementTracking(SMInputCursor.Tracking tracking)
SMInputCursor.Tracking.NONE for root cursors with no parent.
public final SMInputCursor.Tracking getElementTracking()
public final void setElementInfoFactory(ElementInfoFactory f)
public final ElementInfoFactory getElementInfoFactory()
public int getNodeCount()
XMLStreamReader.next() method
is called, but not counting child cursors' node counts.public int getElementCount()
XMLStreamReader.next() method
is called and has moved over a start element, but not counting
child cursors' element counts.@Deprecated public final int getDepth()
public abstract int getParentCount()
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.
public SMEvent getCurrEvent()
public int getCurrEventCode()
public SMElementInfo getTrackedElement()
public SMElementInfo getParentTrackedElement()
public final boolean readerAccessible()
public final org.codehaus.stax2.XMLStreamReader2 getStreamReader()
public javax.xml.stream.Location getLocation()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public java.lang.String getText()
throws javax.xml.stream.XMLStreamException
XMLStreamReader.getText() can
be called. Note that it does not advance the cursor, or combine
multiple textual events.
javax.xml.stream.XMLStreamException - if either the underlying parser has
problems (possibly including event type not being of textual
type, see Stax 1.0 specs for details); or if this cursor does
not currently point to an event.
public java.lang.String collectDescendantText(boolean includeIgnorable)
throws javax.xml.stream.XMLStreamException
includeIgnorable - Whether text for events of type SPACE should
be ignored in the results or not. If false, SPACE events will be
skipped; if true, white space will be included in results.
javax.xml.stream.XMLStreamException
public void processDescendantText(java.io.Writer w,
boolean includeIgnorable)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
collectDescendantText(boolean), but will write
the text to specified Writer instead of collecting it into a
String.
w - Writer to use for outputting text foundincludeIgnorable - Whether text for events of type SPACE should
be ignored in the results or not. If false, SPACE events will be
skipped; if true, white space will be included in results.
java.io.IOException
javax.xml.stream.XMLStreamException
public javax.xml.namespace.QName getQName()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public java.lang.String getLocalName()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public java.lang.String getPrefix()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public java.lang.String getNsUri()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public java.lang.String getPrefixedName()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public boolean hasLocalName(java.lang.String expName)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public boolean hasName(java.lang.String expNsURI,
java.lang.String expLN)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public int getAttrCount()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public int findAttrIndex(java.lang.String uri,
java.lang.String localName)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public javax.xml.namespace.QName getAttrName(int index)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public java.lang.String getAttrLocalName(int index)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public java.lang.String getAttrPrefix(int index)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public java.lang.String getAttrNsUri(int index)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public java.lang.String getAttrValue(int index)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public java.lang.String getAttrValue(java.lang.String localName)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public java.lang.String getAttrValue(java.lang.String uri,
java.lang.String localName)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public int getAttrIntValue(int index)
throws java.lang.NumberFormatException,
javax.xml.stream.XMLStreamException
java.lang.NumberFormatException
javax.xml.stream.XMLStreamException
public int getAttrIntValue(java.lang.String uri,
java.lang.String localName)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public int getAttrIntValue(int index,
int defValue)
throws java.lang.NumberFormatException,
javax.xml.stream.XMLStreamException
java.lang.NumberFormatException
javax.xml.stream.XMLStreamException
public int getAttrIntValue(java.lang.String uri,
java.lang.String localName,
int defValue)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamExceptionpublic java.lang.Object getData()
public void setData(java.lang.Object o)
public abstract SMEvent getNext()
throws javax.xml.stream.XMLStreamException
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.
javax.xml.stream.XMLStreamException
public SMInputCursor childCursor(SMFilter f)
throws javax.xml.stream.XMLStreamException
IllegalStateException; if it does not support
concept of child cursors, it will throw
UnsupportedOperationException
f - Filter child cursor is to use for filtering out
'unwanted' nodes; may be null for no filtering
java.lang.IllegalStateException - If cursor can not be created due
to the state cursor is in.
java.lang.UnsupportedOperationException - If cursor does not allow
creation of child cursors.
javax.xml.stream.XMLStreamException
public final SMInputCursor childCursor()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public SMInputCursor descendantCursor(SMFilter f)
throws javax.xml.stream.XMLStreamException
IllegalStateException; if it does not support
concept of descendant cursors, it will throw
UnsupportedOperationException
java.lang.IllegalStateException - If cursor can not be created due
to the state cursor is in (or for some cursors, if they never
allow creating such cursors)
java.lang.UnsupportedOperationException - If cursor does not allow
creation of descendant cursors.
javax.xml.stream.XMLStreamException
public final SMInputCursor descendantCursor()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public final SMInputCursor childElementCursor()
throws javax.xml.stream.XMLStreamException
childCursor(SMFilterFactory.getElementOnlyFilter());
javax.xml.stream.XMLStreamException
public final SMInputCursor childElementCursor(javax.xml.namespace.QName elemName)
throws javax.xml.stream.XMLStreamException
childCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element
name matches given qname.
javax.xml.stream.XMLStreamException
public final SMInputCursor childElementCursor(java.lang.String elemLocalName)
throws javax.xml.stream.XMLStreamException
childCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element's
local name matches given local name, and that does not belong to
a namespace.
javax.xml.stream.XMLStreamException
public final SMInputCursor descendantElementCursor()
throws javax.xml.stream.XMLStreamException
descendantCursor(SMFilterFactory.getElementOnlyFilter());
javax.xml.stream.XMLStreamException
public final SMInputCursor descendantElementCursor(javax.xml.namespace.QName elemName)
throws javax.xml.stream.XMLStreamException
descendantCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element
name matches given qname.
javax.xml.stream.XMLStreamException
public final SMInputCursor descendantElementCursor(java.lang.String elemLocalName)
throws javax.xml.stream.XMLStreamException
descendantCursor(SMFilterFactory.getElementOnlyFilter(elemLocalName));.
Will only return START_ELEMENT and END_ELEMENT events, whose element
local name matches given local name, and that do not belong to a
namespace
javax.xml.stream.XMLStreamException
public final SMInputCursor childMixedCursor()
throws javax.xml.stream.XMLStreamException
childCursor(SMFilterFactory.getMixedFilter());
javax.xml.stream.XMLStreamException
public final SMInputCursor descendantMixedCursor()
throws javax.xml.stream.XMLStreamException
descendantCursor(SMFilterFactory.getMixedFilter());
javax.xml.stream.XMLStreamExceptionprotected final int getBaseParentCount()
protected final void rewindPastChild()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
protected void invalidate()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
protected SMElementInfo constructElementInfo(SMElementInfo parent,
SMElementInfo prevSibling)
throws javax.xml.stream.XMLStreamException
Note caller already suppresses calls so that this method is only called when information needs to be preserved. Further, previous element is only passed if such linkage is to be preserved (reason for not always doing it is the increased memory usage).
Finally, note that this method does NOT implement
ElementInfoFactory, as its signature does not include the
cursor argument, as that's passed as this pointer already.
javax.xml.stream.XMLStreamException
protected abstract SMInputCursor constructChildCursor(SMFilter f)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
protected abstract SMInputCursor constructDescendantCursor(SMFilter f)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
protected int doParseInt(java.lang.String valueStr)
throws java.lang.NumberFormatException
java.lang.NumberFormatException
protected int doParseInt(java.lang.String valueStr,
int defValue)
protected final boolean isRootCursor()
protected java.lang.String notAccessible(java.lang.String method)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamExceptionprotected java.lang.String getStateDesc()
protected java.lang.String currentEventStr()
protected void throwUnexpectedEndDoc()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
protected void throwWrongEndElem(int expDepth,
int actDepth)
throws java.lang.IllegalStateException
java.lang.IllegalStateException
protected void throwXsEx(java.lang.String msg)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamExceptionpublic java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||