Class DispatchHandler
java.lang.Object
org.dom4j.io.DispatchHandler
- All Implemented Interfaces:
ElementHandler
- Direct Known Subclasses:
PruningDispatchHandler
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
FieldsModifier and TypeFieldDescriptionprivate booleanWhether the parser is at the root element or notprivate ElementHandlerElementHandlerto use by default for element paths with no handlers registeredprivate HashMap<String, ElementHandler> HashMapmaintains the mapping between element paths and handlersprivate ArrayList<ElementHandler> maintains a stack of previously encountered handlersprivate StringThe current path in the XML tree (i.e.maintains a stack of previously encountered paths -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHandler(String handlerPath, ElementHandler handler) Adds theElementHandlerto be called when the specified path is encounted.booleancontainsHandler(String handlerPath) DOCUMENT ME!intReturns the number ofElementHandlerobjects that are waiting for their elements closing tag.getHandler(String handlerPath) Get the registeredElementHandlerfor the specified path.getPath()DOCUMENT ME!voidonEnd(ElementPath elementPath) Called by an event based processor when an elements closing tag is encountered.voidonStart(ElementPath elementPath) Called by an event based processor when an elements openning tag is encountered.removeHandler(String handlerPath) Removes theElementHandlerfrom the event based processor, for the specified path.voidUsed to remove all the Element Handlers and return things back to the way they were when object was created.voidsetDefaultHandler(ElementHandler handler) When multipleElementHandlerinstances have been registered, this will set a defaultElementHandlerto be called for any path which does NOT have a handler registered.
-
Field Details
-
atRoot
private boolean atRootWhether the parser is at the root element or not -
path
The current path in the XML tree (i.e. /a/b/c) -
pathStack
-
handlerStack
maintains a stack of previously encountered handlers -
handlers
HashMapmaintains the mapping between element paths and handlers -
defaultHandler
ElementHandlerto use by default for element paths with no handlers registered
-
-
Constructor Details
-
DispatchHandler
public DispatchHandler()
-
-
Method Details
-
addHandler
Adds theElementHandlerto be called when the specified path is encounted.- Parameters:
handlerPath- is the path to be handledhandler- is theElementHandlerto be called by the event based processor.
-
removeHandler
Removes theElementHandlerfrom the event based processor, for the specified path.- Parameters:
handlerPath- is the path to remove theElementHandlerfor.- Returns:
- DOCUMENT ME!
-
containsHandler
DOCUMENT ME!- Parameters:
handlerPath- DOCUMENT ME!- Returns:
- true when an
ElementHandleris registered for the specified path.
-
getHandler
Get the registeredElementHandlerfor the specified path.- Parameters:
handlerPath- XML path to get the handler for- Returns:
- the registered handler
-
getActiveHandlerCount
public int getActiveHandlerCount()Returns the number ofElementHandlerobjects that are waiting for their elements closing tag.- Returns:
- number of active handlers
-
setDefaultHandler
When multipleElementHandlerinstances have been registered, this will set a defaultElementHandlerto be called for any path which does NOT have a handler registered.- Parameters:
handler- is theElementHandlerto 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
-
onStart
Description copied from interface:ElementHandlerCalled by an event based processor when an elements openning tag is encountered.- Specified by:
onStartin interfaceElementHandler- Parameters:
elementPath- is the currentElementPathto process
-
onEnd
Description copied from interface:ElementHandlerCalled by an event based processor when an elements closing tag is encountered.- Specified by:
onEndin interfaceElementHandler- Parameters:
elementPath- is the currentElementPathto process
-