Interface NamespaceHandler
- All Known Implementing Classes:
AopNamespaceHandler
,CacheNamespaceHandler
,ContextNamespaceHandler
,JdbcNamespaceHandler
,JeeNamespaceHandler
,JmsNamespaceHandler
,LangNamespaceHandler
,MvcNamespaceHandler
,NamespaceHandlerSupport
,OxmNamespaceHandler
,SimpleConstructorNamespaceHandler
,SimplePropertyNamespaceHandler
,TaskNamespaceHandler
,TxNamespaceHandler
,UtilNamespaceHandler
,WebSocketNamespaceHandler
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(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
when it encounters a custom tag
directly under the <beans>
tags and decorate(org.w3c.dom.Node, org.springframework.beans.factory.config.BeanDefinitionHolder, org.springframework.beans.factory.xml.ParserContext)
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.
- Since:
- 2.0
- Author:
- Rob Harrop, Erik Wiersma
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondecorate
(Node source, BeanDefinitionHolder definition, ParserContext parserContext) Parse the specifiedNode
and decorate the suppliedBeanDefinitionHolder
, returning the decorated definition.void
init()
Invoked by theDefaultBeanDefinitionDocumentReader
after construction but before any custom elements are parsed.parse
(Element element, ParserContext parserContext) Parse the specifiedElement
and register any resultingBeanDefinitions
with theBeanDefinitionRegistry
that is embedded in the suppliedParserContext
.
-
Method Details
-
init
void init()Invoked by theDefaultBeanDefinitionDocumentReader
after construction but before any custom elements are parsed. -
parse
Parse the specifiedElement
and register any resultingBeanDefinitions
with theBeanDefinitionRegistry
that is embedded in the suppliedParserContext
.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
- the element that is to be parsed into one or moreBeanDefinitions
parserContext
- the object encapsulating the current state of the parsing process- Returns:
- the primary
BeanDefinition
(can benull
as explained above)
-
decorate
@Nullable BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder definition, ParserContext parserContext) Parse the specifiedNode
and decorate the suppliedBeanDefinitionHolder
, returning the decorated definition.The
Node
may be either anAttr
or anElement
, 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
BeanFactory
.The supplied
ParserContext
can be used to register any additional beans needed to support the main definition.- Parameters:
source
- the source element or attribute that is to be parseddefinition
- the current bean definitionparserContext
- 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.
-