Package org.dom4j.io

Class 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 $
    Author:
    Dave White
    • Constructor Detail

      • DispatchHandler

        public DispatchHandler()
    • Method Detail

      • 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