Class CursorBase

  • Direct Known Subclasses:
    SMInputCursor

    abstract class CursorBase
    extends java.lang.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 class  CursorBase.State
      State constants are used for keeping track of state of individual cursors.
    • Field Summary

      Fields 
      Modifier and Type Field 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.
      private static SMEvent[] EVENTS_BY_IDS
      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

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) org.codehaus.stax2.typed.TypedXMLStreamException _constructTypedException​(java.lang.String value, java.lang.IllegalArgumentException rootCause, java.lang.String msg)  
      protected org.codehaus.stax2.XMLStreamReader2 _getStreamReader()
      Internal method (but available to sub-classes) that allows access to the underlying stream reader.
      protected javax.xml.stream.XMLStreamException _notAccessible​(java.lang.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.
      (package private) void _throwUnexpectedEndDoc()  
      (package private) void _throwWrongEndElem​(int expDepth, int actDepth)  
      protected javax.xml.stream.XMLStreamException _wrongState​(java.lang.String method, SMEvent expState)  
      abstract javax.xml.stream.XMLStreamException constructStreamException​(java.lang.String msg)  
      protected java.lang.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)
      protected abstract java.lang.String getCurrEventDesc()  
      protected java.lang.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.
      abstract boolean isRootCursor()  
      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.
      abstract void throwStreamException​(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

      • 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.
      • _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.
      • _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 Detail

      • 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 Detail

      • getCurrEventDesc

        protected abstract java.lang.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 javax.xml.stream.XMLStreamException constructStreamException​(java.lang.String msg)
      • throwStreamException

        public abstract void throwStreamException​(java.lang.String msg)
                                           throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.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 javax.xml.stream.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:
        javax.xml.stream.XMLStreamException
      • invalidate

        protected void invalidate()
                           throws javax.xml.stream.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:
        javax.xml.stream.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 javax.xml.stream.XMLStreamException _notAccessible​(java.lang.String method)
                                                              throws javax.xml.stream.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:
        javax.xml.stream.XMLStreamException
      • _wrongState

        protected javax.xml.stream.XMLStreamException _wrongState​(java.lang.String method,
                                                                  SMEvent expState)
                                                           throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getStateDesc

        protected java.lang.String getStateDesc()
      • currentEventStr

        protected java.lang.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 javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • _throwWrongEndElem

        void _throwWrongEndElem​(int expDepth,
                                int actDepth)
                         throws java.lang.IllegalStateException
        Throws:
        java.lang.IllegalStateException
      • _constructTypedException

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object