GXPARSE hosted by SourceForge.net Logo

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

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

public class PackageNamespaceElementMapper<T extends Parser>
extends Object
implements ElementMapper<T>

Will be deprecated or removed Maps each XML namespaces to a Java package and maps XML elements in the namespace to element handlers in the 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 returned handler can be an ElementListener that is is not an ElementListener<T>, leading to runtime exceptions from handler.


Nested Class Summary
static class PackageNamespaceElementMapper.DuplicateNamespaceException
           Exception thrown when attempting to load a namespace entry having the same namespace identifier as a previously loaded entry.
static class PackageNamespaceElementMapper.NamespaceEntry<T extends Parser>
           Associates an XML namespace with a Java package and the information needed to map element names in that namespace to element handler classes in the package.
 
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
PackageNamespaceElementMapper(ElementListener<T> defaultElementHandler, PackageNamespaceElementMapper.NamespaceEntry<T>[] namespaceEntry)
           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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PackageNamespaceElementMapper

public PackageNamespaceElementMapper(ElementListener<T> defaultElementHandler,
                                     PackageNamespaceElementMapper.NamespaceEntry<T>[] namespaceEntry)

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.

Throws:
PackageNamespaceElementMapper.DuplicateNamespaceException - if two namespace entries have the same namespace identifier.
NullPointerException - if any parameter is null
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. Warning: This method uses reflection to load the required subclass of ElementListener<T extends Parser>. The class is loaded as a raw type without checking type parameter T, beyond ensuring that it is a subclass of Parser. A type mismatch on the loaded subclass T of the Parser superclass will not show up until runtime, and is likely to show up as a problem with a method of subclass T that is either not defined, or defined differently in the Parser superclass.

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

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