GXPARSE hosted by SourceForge.net Logo

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

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

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

In Development Maps one XML namespace to a Java package and maps XML each element in the namespace to a subclass of ElementListener 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 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.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
ElementClassMapper(ElementListener<T> defaultElementHandler, QName namespace, String prefix)
           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

ElementClassMapper

public ElementClassMapper(ElementListener<T> defaultElementHandler,
                          QName namespace,
                          String prefix)

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:
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