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

public Class SimpleConstructorNamespaceHandler

extends Object
implements NamespaceHandler
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.xml.NamespaceHandler
Imports
java.util.Collection, org.w3c.dom.Attr, .Element, .Node, org.springframework.beans.factory.config.BeanDefinition, .BeanDefinitionHolder, .ConstructorArgumentValues, .ConstructorArgumentValues.ValueHolder, .RuntimeBeanReference, org.springframework.core.Conventions, org.springframework.lang.Nullable, org.springframework.util.StringUtils

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="author" class="..TestBean" c:name="Enescu" c:work-ref="compositions"/>
Here the 'c:name' corresponds directly to the 'name ' argument declared on the constructor of class 'TestBean'. The 'c:work-ref' attributes corresponds to the 'work' argument and, rather than being the concrete value, it contains the name of the bean that will be considered as a parameter

Note

This implementation supports only named parameters - there is no support for indexes or types. Furthermore, the names are used as hints by the container which, by default, does type introspection.

Author
Costin Leau
Since
3.1
See Also
SimplePropertyNamespaceHandler

Field Summary

Modifier and TypeField and Description
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private boolean
private boolean
public BeanDefinitionHolder
decorate(Node
the source element or attribute that is to be parsed
node
,
BeanDefinitionHolder
the current bean definition
definition
,
ParserContext
the object encapsulating the current state of the parsing process
parserContext
)

Implements org.springframework.beans.factory.xml.NamespaceHandler.decorate.

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

public void
init()

Implements org.springframework.beans.factory.xml.NamespaceHandler.init.

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

public BeanDefinition
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
)

Implements org.springframework.beans.factory.xml.NamespaceHandler.parse.

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DELIMITER_PREFIXback to summary
private static final String DELIMITER_PREFIX
REF_SUFFIXback to summary
private static final String REF_SUFFIX

Constructor Detail

SimpleConstructorNamespaceHandlerback to summary
public SimpleConstructorNamespaceHandler()

Method Detail

checkNameback to summary
private boolean checkName(String name, Collection<ConstructorArgumentValues.ValueHolder> values)
containsArgWithNameback to summary
private boolean containsArgWithName(String name, ConstructorArgumentValues cvs)
decorateback to summary
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext)

Implements org.springframework.beans.factory.xml.NamespaceHandler.decorate.

Doc from org.springframework.beans.factory.xml.NamespaceHandler.decorate.

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
node: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
@Override
initback to summary
public void init()

Implements org.springframework.beans.factory.xml.NamespaceHandler.init.

Doc from org.springframework.beans.factory.xml.NamespaceHandler.init.

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

Annotations
@Override
parseback to summary
public BeanDefinition parse(Element element, ParserContext parserContext)

Implements org.springframework.beans.factory.xml.NamespaceHandler.parse.

Doc from org.springframework.beans.factory.xml.NamespaceHandler.parse.

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
@Override
@Nullable