Class CursorBase

java.lang.Object
org.codehaus.staxmate.in.CursorBase
Direct Known Subclasses:
SMInputCursor

abstract class CursorBase extends Object
Abstract base class that contains non-public methods to be used by public sub-classes (SMInputCursor and its sub-classes).
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    State constants are used for keeping track of state of individual cursors.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final int
    Depth the underlying stream reader had when this cursor was created (which is the number of currently open parent elements).
    protected SMInputCursor
    Cursor that has been opened for iterating child nodes of the start element node this cursor points to.
    protected final SMInputContext
     
    protected SMEvent
    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
    Number of start elements iterated over by this cursor, including the current one.
    protected int
    Number of nodes iterated over by this cursor, including the current one.
    protected SMElementInfo
    Element that the parent of this cursor tracked (if any), when this cursor was created.
    Current state of the cursor.
    protected final org.codehaus.stax2.XMLStreamReader2
    Underlying stream reader used.
    protected SMElementInfo
    Element that was last "tracked"; element over which cursor was moved, and of which state has been saved for further use.
    private static final SMEvent[]
    This is the mapping array, indexed by Stax 1.0 event type integer code, value being matching SMEvent enumeration value.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    CursorBase(SMInputContext ctxt, int baseDepth)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) org.codehaus.stax2.typed.TypedXMLStreamException
     
    protected final org.codehaus.stax2.XMLStreamReader2
    Internal method (but available to sub-classes) that allows access to the underlying stream reader.
    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.
    (package private) void
     
    (package private) void
    _throwWrongEndElem(int expDepth, int actDepth)
     
    _wrongState(String method, SMEvent expState)
     
     
    protected String
    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 final SMEvent
    Note: no checks are done regarding validity of passed-in type.
    protected final int
    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)
    protected abstract String
     
    protected String
     
    protected void
    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.
    abstract boolean
     
    protected final void
    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.
    abstract void
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • EVENTS_BY_IDS

      private static final SMEvent[] EVENTS_BY_IDS
      This is the mapping array, indexed by Stax 1.0 event type integer code, value being matching SMEvent enumeration value.
    • _context

      protected final SMInputContext _context
    • _streamReader

      protected final org.codehaus.stax2.XMLStreamReader2 _streamReader
      Underlying stream reader used. It will either be a native XMLStreamReader2 instance, or a regular (Stax 1.0) XMLStreamReader wrapped in an adapter.
    • _baseDepth

      protected final int _baseDepth
      Depth 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 CursorBase.State _state
      Current state of the cursor.
    • _currEvent

      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).
    • _nodeCount

      protected int _nodeCount
      Number of nodes iterated over by this cursor, including the current one.
    • _elemCount

      protected int _elemCount
      Number of start elements iterated over by this cursor, including the current one.
    • _trackedElement

      protected SMElementInfo _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

      protected SMElementInfo _parentTrackedElement
      Element that the parent of this cursor tracked (if any), when this cursor was created.
    • _childCursor

      protected SMInputCursor _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

    • CursorBase

      protected CursorBase(SMInputContext ctxt, int baseDepth)
      Parameters:
      baseDepth - Base depth (number of enclosing open start elements) of the underlying stream at point when this cursor was instantiated
  • Method Details

    • getCurrEventDesc

      protected abstract String getCurrEventDesc()
      Returns:
      Developer-readable description of the event this cursor currently points to.
    • isRootCursor

      public abstract boolean isRootCursor()
      Returns:
      True if this cursor iterates over root level of the underlying stream reader
    • constructStreamException

      public abstract XMLStreamException constructStreamException(String msg)
    • throwStreamException

      public abstract void throwStreamException(String msg) throws XMLStreamException
      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

      protected final void rewindPastChild() throws XMLStreamException
      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

      protected void invalidate() throws XMLStreamException
      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

      protected static final SMEvent eventObjectByEventId(int type)

      Note: no checks are done regarding validity of passed-in type.

      Returns:
      SMEvent matching given type
    • _notAccessible

      protected XMLStreamException _notAccessible(String method) throws XMLStreamException
      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

      protected XMLStreamException _wrongState(String method, SMEvent expState) throws XMLStreamException
      Throws:
      XMLStreamException
    • getStateDesc

      protected String getStateDesc()
    • currentEventStr

      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).
      Returns:
      Human-readable description of the underlying Stax event this cursor points to.
    • _throwUnexpectedEndDoc

      void _throwUnexpectedEndDoc() throws XMLStreamException
      Throws:
      XMLStreamException
    • _throwWrongEndElem

      void _throwWrongEndElem(int expDepth, int actDepth) throws IllegalStateException
      Throws:
      IllegalStateException
    • _constructTypedException

      org.codehaus.stax2.typed.TypedXMLStreamException _constructTypedException(String value, IllegalArgumentException rootCause, String msg)
    • toString

      public String toString()
      Overrides:
      toString in class Object