Package org.dom4j.io

Class ElementStack

  • All Implemented Interfaces:
    ElementPath
    Direct Known Subclasses:
    PruningElementStack

    class ElementStack
    extends java.lang.Object
    implements ElementPath

    ElementStack is used internally inside the SAXContentHandler to maintain a stack of Elementinstances. It opens an integration possibility allowing derivations to prune the tree when a node is complete.

    Version:
    $Revision: 1.14 $
    • Field Detail

      • stack

        protected Element[] stack
        stack of Element objects
      • lastElementIndex

        protected int lastElementIndex
        index of the item at the top of the stack or -1 if the stack is empty
    • Constructor Detail

      • ElementStack

        public ElementStack()
      • ElementStack

        public ElementStack​(int defaultCapacity)
    • Method Detail

      • setDispatchHandler

        public void setDispatchHandler​(DispatchHandler dispatchHandler)
      • clear

        public void clear()
        Peeks at the top element on the stack without changing the contents of the stack.
      • peekElement

        public Element peekElement()
        Peeks at the top element on the stack without changing the contents of the stack.
        Returns:
        the current element on the stack
      • popElement

        public Element popElement()
        Pops the element off the stack
        Returns:
        the element that has just been popped off the stack
      • pushElement

        public void pushElement​(Element element)
        Pushes a new element onto the stack
        Parameters:
        element - DOCUMENT ME!
      • reallocate

        protected void reallocate​(int size)
        Reallocates the stack to the given size
        Parameters:
        size - DOCUMENT ME!
      • size

        public int size()
        Description copied from interface: ElementPath
        DOCUMENT ME!
        Specified by:
        size in interface ElementPath
        Returns:
        the number of elements in the path
      • getElement

        public Element getElement​(int depth)
        Description copied from interface: ElementPath
        DOCUMENT ME!
        Specified by:
        getElement in interface ElementPath
        Parameters:
        depth - DOCUMENT ME!
        Returns:
        the element at the specified depth index, 0 = root element
      • getPath

        public java.lang.String getPath()
        Description copied from interface: ElementPath
        DOCUMENT ME!
        Specified by:
        getPath in interface ElementPath
        Returns:
        the path as a string
      • addHandler

        public void addHandler​(java.lang.String path,
                               ElementHandler elementHandler)
        Description copied from interface: ElementPath
        Adds the ElementHandler to be called when the specified path is encounted. The path can be either an absolute path (i.e. prefixed with "/") or a relative path (i.e. assummed to be a child of the current path as retrieved by getPath .
        Specified by:
        addHandler in interface ElementPath
        Parameters:
        path - is the path to be handled
        elementHandler - is the ElementHandler to be called by the event based processor.
      • removeHandler

        public void removeHandler​(java.lang.String path)
        Description copied from interface: ElementPath
        Removes the ElementHandler from the event based processor, for the specified path. The path can be either an absolute path (i.e. prefixed with "/") or a relative path (i.e. assummed to be a child of the current path as retrieved by getPath .
        Specified by:
        removeHandler in interface ElementPath
        Parameters:
        path - is the path to remove the ElementHandler for.
      • containsHandler

        public boolean containsHandler​(java.lang.String path)
        DOCUMENT ME!
        Parameters:
        path - DOCUMENT ME!
        Returns:
        true when an ElementHandler is registered for the specified path.
      • getHandlerPath

        private java.lang.String getHandlerPath​(java.lang.String path)