Package org.dom4j.io

Class DispatchHandler

  • All Implemented Interfaces:
    ElementHandler
    Direct Known Subclasses:
    PruningDispatchHandler

    class DispatchHandler
    extends java.lang.Object
    implements ElementHandler

    DispatchHandler implements the ElementHandler interface and provides a means to register multiple ElementHandler instances to be used by an event based processor. This is a special ElementHandler in that it's onStart and onEnd implementation methods are called for every element encountered during the parse. It then delegates to other ElementHandler instances registered with it to process the elements encountered.

    Version:
    $Revision: 1.11 $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean atRoot
      Whether the parser is at the root element or not
      private ElementHandler defaultHandler
      ElementHandler to use by default for element paths with no handlers registered
      private java.util.HashMap<java.lang.String,​ElementHandler> handlers
      HashMap maintains the mapping between element paths and handlers
      private java.util.ArrayList<ElementHandler> handlerStack
      maintains a stack of previously encountered handlers
      private java.lang.String path
      The current path in the XML tree (i.e.
      private java.util.ArrayList<java.lang.String> pathStack
      maintains a stack of previously encountered paths
    • Constructor Summary

      Constructors 
      Constructor Description
      DispatchHandler()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addHandler​(java.lang.String handlerPath, ElementHandler handler)
      Adds the ElementHandler to be called when the specified path is encounted.
      boolean containsHandler​(java.lang.String handlerPath)
      DOCUMENT ME!
      int getActiveHandlerCount()
      Returns the number of ElementHandlerobjects that are waiting for their elements closing tag.
      ElementHandler getHandler​(java.lang.String handlerPath)
      Get the registered ElementHandlerfor the specified path.
      java.lang.String getPath()
      DOCUMENT ME!
      void onEnd​(ElementPath elementPath)
      Called by an event based processor when an elements closing tag is encountered.
      void onStart​(ElementPath elementPath)
      Called by an event based processor when an elements openning tag is encountered.
      ElementHandler removeHandler​(java.lang.String handlerPath)
      Removes the ElementHandler from the event based processor, for the specified path.
      void resetHandlers()
      Used to remove all the Element Handlers and return things back to the way they were when object was created.
      void setDefaultHandler​(ElementHandler handler)
      When multiple ElementHandler instances have been registered, this will set a default ElementHandler to be called for any path which does NOT have a handler registered.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • atRoot

        private boolean atRoot
        Whether the parser is at the root element or not
      • path

        private java.lang.String path
        The current path in the XML tree (i.e. /a/b/c)
      • pathStack

        private java.util.ArrayList<java.lang.String> pathStack
        maintains a stack of previously encountered paths
      • handlerStack

        private java.util.ArrayList<ElementHandler> handlerStack
        maintains a stack of previously encountered handlers
      • handlers

        private java.util.HashMap<java.lang.String,​ElementHandler> handlers
        HashMap maintains the mapping between element paths and handlers
      • defaultHandler

        private ElementHandler defaultHandler
        ElementHandler to use by default for element paths with no handlers registered
    • Constructor Detail

      • DispatchHandler

        public DispatchHandler()
    • Method Detail

      • addHandler

        public void addHandler​(java.lang.String handlerPath,
                               ElementHandler handler)
        Adds the ElementHandler to be called when the specified path is encounted.
        Parameters:
        handlerPath - is the path to be handled
        handler - is the ElementHandler to be called by the event based processor.
      • removeHandler

        public ElementHandler removeHandler​(java.lang.String handlerPath)
        Removes the ElementHandler from the event based processor, for the specified path.
        Parameters:
        handlerPath - is the path to remove the ElementHandler for.
        Returns:
        DOCUMENT ME!
      • containsHandler

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

        public ElementHandler getHandler​(java.lang.String handlerPath)
        Get the registered ElementHandlerfor the specified path.
        Parameters:
        handlerPath - XML path to get the handler for
        Returns:
        the registered handler
      • getActiveHandlerCount

        public int getActiveHandlerCount()
        Returns the number of ElementHandlerobjects that are waiting for their elements closing tag.
        Returns:
        number of active handlers
      • setDefaultHandler

        public void setDefaultHandler​(ElementHandler handler)
        When multiple ElementHandler instances have been registered, this will set a default ElementHandler to be called for any path which does NOT have a handler registered.
        Parameters:
        handler - is the ElementHandler to be called by the event based processor.
      • resetHandlers

        public void resetHandlers()
        Used to remove all the Element Handlers and return things back to the way they were when object was created.
      • getPath

        public java.lang.String getPath()
        DOCUMENT ME!
        Returns:
        the current path for the parse
      • onStart

        public void onStart​(ElementPath elementPath)
        Description copied from interface: ElementHandler
        Called by an event based processor when an elements openning tag is encountered.
        Specified by:
        onStart in interface ElementHandler
        Parameters:
        elementPath - is the current ElementPath to process
      • onEnd

        public void onEnd​(ElementPath elementPath)
        Description copied from interface: ElementHandler
        Called by an event based processor when an elements closing tag is encountered.
        Specified by:
        onEnd in interface ElementHandler
        Parameters:
        elementPath - is the current ElementPath to process