Class DispatchHandler

java.lang.Object
org.dom4j.io.DispatchHandler
All Implemented Interfaces:
ElementHandler
Direct Known Subclasses:
PruningDispatchHandler

class DispatchHandler extends 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 Details

    • atRoot

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

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

      private ArrayList<String> pathStack
      maintains a stack of previously encountered paths
    • handlerStack

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

      private HashMap<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 Details

    • DispatchHandler

      public DispatchHandler()
  • Method Details

    • addHandler

      public void addHandler(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(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(String handlerPath)
      DOCUMENT ME!
      Parameters:
      handlerPath - DOCUMENT ME!
      Returns:
      true when an ElementHandler is registered for the specified path.
    • getHandler

      public ElementHandler getHandler(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 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