Top Description Fields Constructors Methods
org.dom4j.io

pack-priv Class DispatchHandler

extends Object
implements ElementHandler
Class Inheritance
All Implemented Interfaces
org.dom4j.ElementHandler
Known Direct Subclasses
org.dom4j.io.PruningDispatchHandler
Imports
java.util.ArrayList, .HashMap, org.dom4j.Element, .ElementHandler, .ElementPath

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.

Author
Dave White
Version
$Revision: 1.11 $

Field Summary

Modifier and TypeField and 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 HashMap<String, ElementHandler>
handlers

HashMap maintains the mapping between element paths and handlers

private ArrayList<ElementHandler>
handlerStack

maintains a stack of previously encountered handlers

private String
path

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

private ArrayList<String>
pathStack

maintains a stack of previously encountered paths

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addHandler(String
is the path to be handled
handlerPath
,
ElementHandler
is the ElementHandler to be called by the event based processor.
handler
)

Adds the ElementHandler to be called when the specified path is encounted.

public boolean

Returns:

true when an ElementHandler is registered for the specified path.
containsHandler
(String
DOCUMENT ME!
handlerPath
)

DOCUMENT ME!

public int

Returns:

number of active handlers
getActiveHandlerCount
()

Returns the number of ElementHandlerobjects that are waiting for their elements closing tag.

public ElementHandler

Returns:

the registered handler
getHandler
(String
XML path to get the handler for
handlerPath
)

Get the registered ElementHandlerfor the specified path.

public String

Returns:

the current path for the parse
getPath
()

DOCUMENT ME!

public void
onEnd(ElementPath
is the current ElementPath to process
elementPath
)

Implements org.dom4j.ElementHandler.onEnd.

Called by an event based processor when an elements closing tag is encountered.
public void
onStart(ElementPath
is the current ElementPath to process
elementPath
)

Implements org.dom4j.ElementHandler.onStart.

Called by an event based processor when an elements openning tag is encountered.
public ElementHandler

Returns:

DOCUMENT ME!
removeHandler
(String
is the path to remove the ElementHandler for.
handlerPath
)

Removes the ElementHandler from the event based processor, for the specified path.

public void
resetHandlers()

Used to remove all the Element Handlers and return things back to the way they were when object was created.

public void
setDefaultHandler(ElementHandler
is the ElementHandler to be called by the event based processor.
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

atRootback to summary
private boolean atRoot

Whether the parser is at the root element or not

defaultHandlerback to summary
private ElementHandler defaultHandler

ElementHandler to use by default for element paths with no handlers registered

handlersback to summary
private HashMap<String, ElementHandler> handlers

HashMap maintains the mapping between element paths and handlers

handlerStackback to summary
private ArrayList<ElementHandler> handlerStack

maintains a stack of previously encountered handlers

pathback to summary
private String path

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

pathStackback to summary
private ArrayList<String> pathStack

maintains a stack of previously encountered paths

Constructor Detail

DispatchHandlerback to summary
public DispatchHandler()

Method Detail

addHandlerback to summary
public void addHandler(String handlerPath, ElementHandler handler)

Adds the ElementHandler to be called when the specified path is encounted.

Parameters
handlerPath:String

is the path to be handled

handler:ElementHandler

is the ElementHandler to be called by the event based processor.

containsHandlerback to summary
public boolean containsHandler(String handlerPath)

DOCUMENT ME!

Parameters
handlerPath:String

DOCUMENT ME!

Returns:boolean

true when an ElementHandler is registered for the specified path.

getActiveHandlerCountback to summary
public int getActiveHandlerCount()

Returns the number of ElementHandlerobjects that are waiting for their elements closing tag.

Returns:int

number of active handlers

getHandlerback to summary
public ElementHandler getHandler(String handlerPath)

Get the registered ElementHandlerfor the specified path.

Parameters
handlerPath:String

XML path to get the handler for

Returns:ElementHandler

the registered handler

getPathback to summary
public String getPath()

DOCUMENT ME!

Returns:String

the current path for the parse

onEndback to summary
public void onEnd(ElementPath elementPath)

Implements org.dom4j.ElementHandler.onEnd.

Doc from org.dom4j.ElementHandler.onEnd.

Called by an event based processor when an elements closing tag is encountered.

Parameters
elementPath:ElementPath

is the current ElementPath to process

onStartback to summary
public void onStart(ElementPath elementPath)

Implements org.dom4j.ElementHandler.onStart.

Doc from org.dom4j.ElementHandler.onStart.

Called by an event based processor when an elements openning tag is encountered.

Parameters
elementPath:ElementPath

is the current ElementPath to process

removeHandlerback to summary
public ElementHandler removeHandler(String handlerPath)

Removes the ElementHandler from the event based processor, for the specified path.

Parameters
handlerPath:String

is the path to remove the ElementHandler for.

Returns:ElementHandler

DOCUMENT ME!

resetHandlersback to summary
public void resetHandlers()

Used to remove all the Element Handlers and return things back to the way they were when object was created.

setDefaultHandlerback to summary
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:ElementHandler

is the ElementHandler to be called by the event based processor.