public abstract class AbstractNamespaceHandler extends Object implements NamespaceHandler
AbstractNamespaceHandler provides a base implementation of a NamespaceHandler with support for implicit and explicit registration of ElementProcessors and AttributeProcessors for those xml attributes and elements occurring in the associated xml namespace.| Constructor and Description |
|---|
AbstractNamespaceHandler()
Construct an
AbstractNamespaceHandler. |
| Modifier and Type | Method and Description |
|---|---|
AttributeProcessor<?> |
getAttributeProcessor(String localName)
Obtains the
AttributeProcessor registered with the specified localName (in the namespace). |
AttributeProcessor<?> |
getAttributeProcessor(XmlAttribute attribute)
Obtains the
AttributeProcessor that is suitable for processing the specified XmlAttribute in the xml namespace associated with this NamespaceHandler. |
DocumentPreprocessor |
getDocumentPreprocessor()
Obtains the
DocumentPreprocessor that must be applied to the XmlElement (ie: document) in which the NamespaceHandler is defined, prior to XmlElements and XmlAttributes being processed defined by this NamespaceHandler. |
ElementProcessor<?> |
getElementProcessor(String localName)
Obtains the
ElementProcessor registered with the specified localName (in the namespace). |
ElementProcessor<?> |
getElementProcessor(XmlElement element)
Obtains the
ElementProcessor that is suitable for processing the specified XmlElement in the xml namespace associated with this NamespaceHandler. |
void |
onEndNamespace(ProcessingContext context, XmlElement element, String prefix, URI uri)
Called when the xml namespace associated with the
NamespaceHandler is last encountered in an xml document. |
void |
onStartNamespace(ProcessingContext context, XmlElement element, String prefix, URI uri)
Called when the xml namespace associated with the
NamespaceHandler is first encountered in an xml document. |
protected AttributeProcessor<?> |
onUnknownAttribute(XmlAttribute attribute)
A call-back to handle when an
XmlAttribute is unknown to the NamespaceHandler. |
protected ElementProcessor<?> |
onUnknownElement(XmlElement element)
A call-back to handle when an
XmlElement is unknown to the NamespaceHandler. |
<T> void |
registerAttributeType(String sLocalName, Class<T> clzType)
Registers (internally creates) an appropriate
AttributeProcessor for XmlAttributes with the specified local name so that they produce the specified type of value when processed. |
<T> void |
registerElementType(String sLocalName, Class<T> clzType)
Registers (internally creates) an appropriate
ElementProcessor for XmlElements with the specified local name so that they produce the specified type of value when processed. |
void |
registerProcessor(Class<?> clzProcessor)
Registers the specified processor as an
ElementProcessor or AttributeProcessor (based on the interfaces it implements) using the XmlSimpleName annotation to determine the localName of the said processor. |
void |
registerProcessor(String sLocalName, AttributeProcessor<?> processor)
Registers an
AttributeProcessor for XmlAttributes with the specified name. |
void |
registerProcessor(String sLocalName, ElementProcessor<?> processor)
Registers an
ElementProcessor for XmlElements with a name with in the context of the NamespaceHandler namespace. |
void |
setDocumentPreprocessor(DocumentPreprocessor preprocessor)
Sets the
DocumentPreprocessor for the NamespaceHandler. |
public AbstractNamespaceHandler()
AbstractNamespaceHandler.public DocumentPreprocessor getDocumentPreprocessor()
DocumentPreprocessor that must be applied to the XmlElement (ie: document) in which the NamespaceHandler is defined, prior to XmlElements and XmlAttributes being processed defined by this NamespaceHandler.getDocumentPreprocessor in interface NamespaceHandlerDocumentPreprocessor or null if one is not required or defined for the NamespaceHandlerpublic AttributeProcessor<?> getAttributeProcessor(XmlAttribute attribute)
AttributeProcessor that is suitable for processing the specified XmlAttribute in the xml namespace associated with this NamespaceHandler.getAttributeProcessor in interface NamespaceHandlerattribute - the XmlAttributeAttributeProcessor or null if a suitable AttributeProcessor could not be foundpublic ElementProcessor<?> getElementProcessor(XmlElement element)
ElementProcessor that is suitable for processing the specified XmlElement in the xml namespace associated with this NamespaceHandler.getElementProcessor in interface NamespaceHandlerelement - the XmlElementElementProcessor or null if a suitable ElementProcessor could not be foundpublic void onStartNamespace(ProcessingContext context, XmlElement element, String prefix, URI uri)
NamespaceHandler is first encountered in an xml document.onStartNamespace in interface NamespaceHandlercontext - the document ProcessingContext in which the xml namespace was encounteredelement - the XmlElement in which the xml namespace was encounteredprefix - the prefix of the declared xml namespaceuri - the URI of the declared xml namespacepublic void onEndNamespace(ProcessingContext context, XmlElement element, String prefix, URI uri)
NamespaceHandler is last encountered in an xml document.onEndNamespace in interface NamespaceHandlercontext - the document ProcessingContext in which the xml namespace was encounteredelement - the XmlElement in which the xml namespace was encounteredprefix - the prefix of the declared xml namespaceuri - the URI of the declared xml namespacepublic void setDocumentPreprocessor(DocumentPreprocessor preprocessor)
DocumentPreprocessor for the NamespaceHandler.preprocessor - the DocumentPreprocessorpublic void registerProcessor(Class<?> clzProcessor)
ElementProcessor or AttributeProcessor (based on the interfaces it implements) using the XmlSimpleName annotation to determine the localName of the said processor.
Note: The specified class must have a no-args constructor.
clzProcessor - A class that implements either (or both) ElementProcessor or AttributeProcessor that is annotated with @XmlSimpleName to specify it's localName.public void registerProcessor(String sLocalName, ElementProcessor<?> processor)
ElementProcessor for XmlElements with a name with in the context of the NamespaceHandler namespace.sLocalName - The local name of the XmlElement to be processed with the ElementProcessorprocessor - The ElementProcessorpublic void registerProcessor(String sLocalName, AttributeProcessor<?> processor)
AttributeProcessor for XmlAttributes with the specified name.sLocalName - The local name of the XmlAttribute to be processed with the AttributeProcessorprocessor - The AttributeProcessorpublic <T> void registerElementType(String sLocalName, Class<T> clzType)
ElementProcessor for XmlElements with the specified local name so that they produce the specified type of value when processed.sLocalName - The local name of the XmlElements to be associated with the typeclzType - The Class of value that should be produced for the XmlElementpublic <T> void registerAttributeType(String sLocalName, Class<T> clzType)
AttributeProcessor for XmlAttributes with the specified local name so that they produce the specified type of value when processed.sLocalName - The local name of the XmlElements to be associated with the typeclzType - The Class of value that should be produced for the XmlAttributeprotected AttributeProcessor<?> onUnknownAttribute(XmlAttribute attribute)
XmlAttribute is unknown to the NamespaceHandler.
Override this method to provide specialized foreign XmlAttribute processing. By default, null will be returned for unknown XmlAttributes.
attribute - The XmlAttribute that was unknown.AttributeProcessor that may be used to process the unknown XmlAttribute or null if no special processing should occur.protected ElementProcessor<?> onUnknownElement(XmlElement element)
XmlElement is unknown to the NamespaceHandler.
Override this method to provide specialized foreign XmlElement processing. By default, unknown XmlElement will return an ElementProcessor that when attempting to process the said element, will throw a ConfigurationException.
element - The XmlElement that was unknown.ElementProcessor that may be used to process the unknown XmlElement or null if no special processing should occur.public AttributeProcessor<?> getAttributeProcessor(String localName)
AttributeProcessor registered with the specified localName (in the namespace).localName - the name of the AttributeProcessor to returnAttributeProcessor or null if not foundpublic ElementProcessor<?> getElementProcessor(String localName)
ElementProcessor registered with the specified localName (in the namespace).localName - the name of the ElementProcessor to returnElementProcessor or null if not found