Class SimplePropertyNamespaceHandler
java.lang.Object
org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler
- All Implemented Interfaces:
NamespaceHandler
Simple
NamespaceHandler
implementation that maps custom attributes
directly through to bean properties. An important point to note is that this
NamespaceHandler
does not have a corresponding schema since there
is no way to know in advance all possible attribute names.
An example of the usage of this NamespaceHandler
is shown below:
<bean id="rob" class="..TestBean" p:name="Rob Harrop" p:spouse-ref="sally"/>Here the '
p:name
' corresponds directly to the 'name
'
property on class 'TestBean
'. The 'p:spouse-ref
'
attributes corresponds to the 'spouse
' property and, rather
than being the concrete value, it contains the name of the bean that will
be injected into that property.- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondecorate
(Node node, 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
.
-
Constructor Details
-
SimplePropertyNamespaceHandler
public SimplePropertyNamespaceHandler()
-
-
Method Details
-
init
public void init()Description copied from interface:NamespaceHandler
Invoked by theDefaultBeanDefinitionDocumentReader
after construction but before any custom elements are parsed.- Specified by:
init
in interfaceNamespaceHandler
- See Also:
-
parse
Description copied from interface:NamespaceHandler
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.- Specified by:
parse
in interfaceNamespaceHandler
- 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
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) Description copied from interface:NamespaceHandler
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.- Specified by:
decorate
in interfaceNamespaceHandler
- Parameters:
node
- 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.
-