GXPARSE hosted by SourceForge.net Logo

ca.gorman.xml.parse.util
Class NamespacePackageMapper<T extends Parser>

java.lang.Object
  extended by ca.gorman.xml.parse.util.NamespacePackageMapper<T>
All Implemented Interfaces:
ElementListener<T>, ElementMapper<T>, NamespaceMapper<T>, Iterable<String>

public class NamespacePackageMapper<T extends Parser>
extends Object
implements NamespaceMapper<T>

In Development Maps each of one or more XML namespaces to a Java package and maps XML elements in each namespace to elment handlers in the corresponding package.

Each namespace is specified by a NamespaceEntry that has the namespace identifier, the corresponding Java package, and information on how to map the names of each element in the namespace to the class name of corresponding element handler. Each element handler class must have a public constructor that takes no parameters.

Warning PackageNamespaceElementMapper uses Java reflection to identify and load element handlers at runtime. Generic type parameters cannot be checked at run time. A handler that is not an ElementListener will throw a ClassCastException from the doElement method when it is invoked by the doElement method. A handler that is an ElementListener, but is not the correct generic type, will be invoked as if it were a valid handler, and will cause an exception that has a much less obvious connection to the actual problem.


Nested Class Summary
 
Nested classes/interfaces inherited from interface ca.gorman.xml.parse.NamespaceMapper
NamespaceMapper.NamespaceMapException
 
Nested classes/interfaces inherited from interface ca.gorman.xml.parse.ElementMapper
ElementMapper.InvalidHandlerException, ElementMapper.NotFoundException
 
Field Summary
 
Fields inherited from interface ca.gorman.xml.parse.ElementMapper
ESCAPE_CENT, ESCAPE_CURRENCY, ESCAPE_DOLLAR, ESCAPE_POUND, ESCAPE_YEN
 
Constructor Summary
NamespacePackageMapper(ElementListener<T> defaultElementHandler, Iterable<NamespaceMapper<T>> mappers)
           Construct an element mapper to invoke element handlers in the Java package that corresponds to the element namespace, specifying a default element handler for elements outside any of the namespaces.
NamespacePackageMapper(ElementListener<T> defaultElementHandler, Map<String,ElementMapper<T>> namespaceMap)
           Construct an element mapper to invoke element handlers in the Java package that corresponds to the element namespace, specifying a default element handler for elements outside any of the namespaces.
 
Method Summary
 void doElement(T parser, CurrentElement element)
           Receive a request to handle a element that is being parsed, and invoke the appropriate element handler for that element.
 Iterator<String> iterator()
           Return an iterator for the namespace URIs that are mapped by the NamespaceMapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamespacePackageMapper

public NamespacePackageMapper(ElementListener<T> defaultElementHandler,
                              Map<String,ElementMapper<T>> namespaceMap)

Construct an element mapper to invoke element handlers in the Java package that corresponds to the element namespace, specifying a default element handler for elements outside any of the namespaces.

Parameters:
defaultElementHandler - the element handler to be invoked when no handler is found.
namespaceMap - a Map of namespaces and their corresponding ElementMappers that invoke the element handlers on elements in each namespace.
Throws:
NullPointerException - if any parameter is null
NullPointerException - if any key or value in namespaceMap is null
NamespaceMapException - if the namespaceMap maps the same namespace name to two ElementMappers that are not equal to each other.

NamespacePackageMapper

public NamespacePackageMapper(ElementListener<T> defaultElementHandler,
                              Iterable<NamespaceMapper<T>> mappers)

Construct an element mapper to invoke element handlers in the Java package that corresponds to the element namespace, specifying a default element handler for elements outside any of the namespaces.

Parameters:
defaultElementHandler - the element handler to be invoked when no handler is found.
mappers - an Iterable that can iterate over the NamespaceMappers that invoke the element handlers on elements in each namespace.
Throws:
NullPointerException - if any parameter is null
NullPointerException - if mappers returns a null Iterator or the Iterator returns a null NamespaceMapper
NullPointerException - if any NamespaceMapper returns a null iterator
NullPointerException - if an iterator from any NamespaceMapper returns a null namespace name.
NamespaceMapException - if the mapperIterator produces two different NamespaceMappers that identify themselves as mappers for the same namespace identifier.
Method Detail

doElement

public void doElement(T parser,
                      CurrentElement element)
               throws ListenerException,
                      IOException

Receive a request to handle a element that is being parsed, and invoke the appropriate element handler for that element.

The element handler will be equivalent to an ElementListener.

Specified by:
doElement in interface ElementListener<T extends Parser>
Specified by:
doElement in interface ElementMapper<T extends Parser>
Parameters:
parser - The Parser that invoked this method
element - CurrentElement instance with a content handler to parse the centent of the element.
Throws:
ListenerException - when the exception has been thrown from a Listener method.
IOException - when an input or output error occurs

iterator

public Iterator<String> iterator()
Description copied from interface: NamespaceMapper

Return an iterator for the namespace URIs that are mapped by the NamespaceMapper.

Specified by:
iterator in interface NamespaceMapper<T extends Parser>
Specified by:
iterator in interface Iterable<String>

GXPARSE download

GXPARSE Generic XML Stream Parser API and supporting tools.   Release $Name: gxparse-sf-alpha-2_0 $
Copyright 2003-2004 Ian E. Gorman
Released under GNU Lesser General Public License