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 boolean
Whether the parser is at the root element or notprivate ElementHandler
ElementHandler
to use by default for element paths with no handlers registeredprivate HashMap
<String, ElementHandler> HashMap
maintains the mapping between element paths and handlersprivate ArrayList
<ElementHandler> maintains a stack of previously encountered handlersprivate String
The current path in the XML tree (i.e.maintains a stack of previously encountered paths -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHandler
(String handlerPath, ElementHandler handler) Adds theElementHandler
to be called when the specified path is encounted.boolean
containsHandler
(String handlerPath) DOCUMENT ME!int
Returns the number ofElementHandler
objects that are waiting for their elements closing tag.getHandler
(String handlerPath) Get the registeredElementHandler
for the specified path.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.removeHandler
(String handlerPath) Removes theElementHandler
from the event based processor, for the specified path.void
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 multipleElementHandler
instances have been registered, this will set a defaultElementHandler
to 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
HashMap
maintains the mapping between element paths and handlers -
defaultHandler
ElementHandler
to use by default for element paths with no handlers registered
-
-
Constructor Details
-
DispatchHandler
public DispatchHandler()
-
-
Method Details
-
addHandler
Adds theElementHandler
to be called when the specified path is encounted.- Parameters:
handlerPath
- is the path to be handledhandler
- is theElementHandler
to be called by the event based processor.
-
removeHandler
Removes theElementHandler
from the event based processor, for the specified path.- Parameters:
handlerPath
- is the path to remove theElementHandler
for.- Returns:
- DOCUMENT ME!
-
containsHandler
DOCUMENT ME!- Parameters:
handlerPath
- DOCUMENT ME!- Returns:
- true when an
ElementHandler
is registered for the specified path.
-
getHandler
Get the registeredElementHandler
for the specified path.- Parameters:
handlerPath
- XML path to get the handler for- Returns:
- the registered handler
-
getActiveHandlerCount
public int getActiveHandlerCount()Returns the number ofElementHandler
objects that are waiting for their elements closing tag.- Returns:
- number of active handlers
-
setDefaultHandler
When multipleElementHandler
instances have been registered, this will set a defaultElementHandler
to be called for any path which does NOT have a handler registered.- Parameters:
handler
- is theElementHandler
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
-
onStart
Description copied from interface:ElementHandler
Called by an event based processor when an elements openning tag is encountered.- Specified by:
onStart
in interfaceElementHandler
- Parameters:
elementPath
- is the currentElementPath
to process
-
onEnd
Description copied from interface:ElementHandler
Called by an event based processor when an elements closing tag is encountered.- Specified by:
onEnd
in interfaceElementHandler
- Parameters:
elementPath
- is the currentElementPath
to process
-