org.springframework.beans.factory.xml
Class NamespaceHandlerSupport

java.lang.Object
  extended by org.springframework.beans.factory.xml.NamespaceHandlerSupport
All Implemented Interfaces:
NamespaceHandler
Direct Known Subclasses:
AopNamespaceHandler, ContextNamespaceHandler, JdbcNamespaceHandler, JeeNamespaceHandler, JmsNamespaceHandler, LangNamespaceHandler, MvcNamespaceHandler, OxmNamespaceHandler, TaskNamespaceHandler, TxNamespaceHandler, UtilNamespaceHandler

public abstract class NamespaceHandlerSupport
extends java.lang.Object
implements NamespaceHandler

Support class for implementing custom NamespaceHandlers. Parsing and decorating of individual Nodes is done via BeanDefinitionParser and BeanDefinitionDecorator strategy interfaces, respectively.

Provides the registerBeanDefinitionParser(java.lang.String, org.springframework.beans.factory.xml.BeanDefinitionParser) and registerBeanDefinitionDecorator(java.lang.String, org.springframework.beans.factory.xml.BeanDefinitionDecorator) methods for registering a BeanDefinitionParser or BeanDefinitionDecorator to handle a specific element.

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller
See Also:
registerBeanDefinitionParser(String, BeanDefinitionParser), registerBeanDefinitionDecorator(String, BeanDefinitionDecorator)

Field Summary
private  java.util.Map<java.lang.String,BeanDefinitionDecorator> attributeDecorators
          Stores the BeanDefinitionDecorator implementations keyed by the local name of the Attrs they handle.
private  java.util.Map<java.lang.String,BeanDefinitionDecorator> decorators
          Stores the BeanDefinitionDecorator implementations keyed by the local name of the Elements they handle.
private  java.util.Map<java.lang.String,BeanDefinitionParser> parsers
          Stores the BeanDefinitionParser implementations keyed by the local name of the Elements they handle.
 
Constructor Summary
NamespaceHandlerSupport()
           
 
Method Summary
 BeanDefinitionHolder decorate(org.w3c.dom.Node node, BeanDefinitionHolder definition, ParserContext parserContext)
          Decorates the supplied Node by delegating to the BeanDefinitionDecorator that is registered to handle that Node.
private  BeanDefinitionDecorator findDecoratorForNode(org.w3c.dom.Node node, ParserContext parserContext)
          Locates the BeanDefinitionParser from the register implementations using the local name of the supplied Node.
private  BeanDefinitionParser findParserForElement(org.w3c.dom.Element element, ParserContext parserContext)
          Locates the BeanDefinitionParser from the register implementations using the local name of the supplied Element.
 BeanDefinition parse(org.w3c.dom.Element element, ParserContext parserContext)
          Parses the supplied Element by delegating to the BeanDefinitionParser that is registered for that Element.
protected  void registerBeanDefinitionDecorator(java.lang.String elementName, BeanDefinitionDecorator dec)
          Subclasses can call this to register the supplied BeanDefinitionDecorator to handle the specified element.
protected  void registerBeanDefinitionDecoratorForAttribute(java.lang.String attrName, BeanDefinitionDecorator dec)
          Subclasses can call this to register the supplied BeanDefinitionDecorator to handle the specified attribute.
protected  void registerBeanDefinitionParser(java.lang.String elementName, BeanDefinitionParser parser)
          Subclasses can call this to register the supplied BeanDefinitionParser to handle the specified element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.beans.factory.xml.NamespaceHandler
init
 

Field Detail

parsers

private final java.util.Map<java.lang.String,BeanDefinitionParser> parsers
Stores the BeanDefinitionParser implementations keyed by the local name of the Elements they handle.


decorators

private final java.util.Map<java.lang.String,BeanDefinitionDecorator> decorators
Stores the BeanDefinitionDecorator implementations keyed by the local name of the Elements they handle.


attributeDecorators

private final java.util.Map<java.lang.String,BeanDefinitionDecorator> attributeDecorators
Stores the BeanDefinitionDecorator implementations keyed by the local name of the Attrs they handle.

Constructor Detail

NamespaceHandlerSupport

public NamespaceHandlerSupport()
Method Detail

parse

public BeanDefinition parse(org.w3c.dom.Element element,
                            ParserContext parserContext)
Parses the supplied Element by delegating to the BeanDefinitionParser that is registered for that Element.

Specified by:
parse in interface NamespaceHandler
Parameters:
element - the element that is to be parsed into one or more BeanDefinitions
parserContext - the object encapsulating the current state of the parsing process
Returns:
the primary BeanDefinition (can be null as explained above)

findParserForElement

private BeanDefinitionParser findParserForElement(org.w3c.dom.Element element,
                                                  ParserContext parserContext)
Locates the BeanDefinitionParser from the register implementations using the local name of the supplied Element.


decorate

public BeanDefinitionHolder decorate(org.w3c.dom.Node node,
                                     BeanDefinitionHolder definition,
                                     ParserContext parserContext)
Decorates the supplied Node by delegating to the BeanDefinitionDecorator that is registered to handle that Node.

Specified by:
decorate in interface NamespaceHandler
Parameters:
node - the source element or attribute that is to be parsed
definition - the current bean definition
parserContext - the object encapsulating the current state of the parsing process
Returns:
the decorated definition (to be registered in the BeanFactory), or simply the original bean definition if no decoration is required. A null value is strictly speaking invalid, but will be leniently treated like the case where the original bean definition gets returned.

findDecoratorForNode

private BeanDefinitionDecorator findDecoratorForNode(org.w3c.dom.Node node,
                                                     ParserContext parserContext)
Locates the BeanDefinitionParser from the register implementations using the local name of the supplied Node. Supports both Elements and Attrs.


registerBeanDefinitionParser

protected final void registerBeanDefinitionParser(java.lang.String elementName,
                                                  BeanDefinitionParser parser)
Subclasses can call this to register the supplied BeanDefinitionParser to handle the specified element. The element name is the local (non-namespace qualified) name.


registerBeanDefinitionDecorator

protected final void registerBeanDefinitionDecorator(java.lang.String elementName,
                                                     BeanDefinitionDecorator dec)
Subclasses can call this to register the supplied BeanDefinitionDecorator to handle the specified element. The element name is the local (non-namespace qualified) name.


registerBeanDefinitionDecoratorForAttribute

protected final void registerBeanDefinitionDecoratorForAttribute(java.lang.String attrName,
                                                                 BeanDefinitionDecorator dec)
Subclasses can call this to register the supplied BeanDefinitionDecorator to handle the specified attribute. The attribute name is the local (non-namespace qualified) name.