Top Description Methods
org.springframework.beans.factory.xml

public Interface NamespaceHandler

Known Direct Implementers
org.springframework.beans.factory.xml.SimpleConstructorNamespaceHandler, org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler, org.springframework.beans.factory.xml.NamespaceHandlerSupport
Imports
org.w3c.dom.Element, .Node, org.springframework.beans.factory.config.BeanDefinition, .BeanDefinitionHolder, org.springframework.lang.Nullable

Base interface used by the DefaultBeanDefinitionDocumentReader for handling custom namespaces in a Spring XML configuration file.

Implementations are expected to return implementations of the BeanDefinitionParser interface for custom top-level tags and implementations of the BeanDefinitionDecorator interface for custom nested tags.

The parser will call parse when it encounters a custom tag directly under the <beans> tags and decorate when it encounters a custom tag directly under a <bean> tag.

Developers writing their own custom element extensions typically will not implement this interface directly, but rather make use of the provided NamespaceHandlerSupport class.

Authors
Rob Harrop, Erik Wiersma
Since
2.0
See Also
DefaultBeanDefinitionDocumentReader, NamespaceHandlerResolver

Method Summary

Modifier and TypeMethod and Description
public BeanDefinitionHolder

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.
decorate
(Node
the source element or attribute that is to be parsed
source
,
BeanDefinitionHolder
the current bean definition
definition
,
ParserContext
the object encapsulating the current state of the parsing process
parserContext
)

Parse the specified Node and decorate the supplied BeanDefinitionHolder, returning the decorated definition.

public void
init()

Invoked by the DefaultBeanDefinitionDocumentReader after construction but before any custom elements are parsed.

public BeanDefinition

Returns:

the primary BeanDefinition (can be null as explained above)
parse
(Element
the element that is to be parsed into one or more BeanDefinitions
element
,
ParserContext
the object encapsulating the current state of the parsing process
parserContext
)

Parse the specified Element and register any resulting BeanDefinitions with the org.springframework.beans.factory.support.BeanDefinitionRegistry that is embedded in the supplied ParserContext.

Method Detail

decorateback to summary
public BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder definition, ParserContext parserContext)

Parse the specified Node and decorate the supplied BeanDefinitionHolder, returning the decorated definition.

The Node may be either an org.w3c.dom.Attr or an Element, depending on whether a custom attribute or element is being parsed.

Implementations may choose to return a completely new definition, which will replace the original definition in the resulting org.springframework.beans.factory.BeanFactory.

The supplied ParserContext can be used to register any additional beans needed to support the main definition.

Parameters
source:Node

the source element or attribute that is to be parsed

definition:BeanDefinitionHolder

the current bean definition

parserContext:ParserContext

the object encapsulating the current state of the parsing process

Returns:BeanDefinitionHolder

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.

Annotations
@Nullable
initback to summary
public void init()

Invoked by the DefaultBeanDefinitionDocumentReader after construction but before any custom elements are parsed.

See Also
NamespaceHandlerSupport#registerBeanDefinitionParser(String, BeanDefinitionParser)
parseback to summary
public BeanDefinition parse(Element element, ParserContext parserContext)

Parse the specified Element and register any resulting BeanDefinitions with the org.springframework.beans.factory.support.BeanDefinitionRegistry that is embedded in the supplied ParserContext.

Implementations should return the primary BeanDefinition that results from the parse phase if they wish to be used nested inside (for example) a <property> tag.

Implementations may return null if they will not be used in a nested scenario.

Parameters
element:Element

the element that is to be parsed into one or more BeanDefinitions

parserContext:ParserContext

the object encapsulating the current state of the parsing process

Returns:BeanDefinition

the primary BeanDefinition (can be null as explained above)

Annotations
@Nullable