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

public abstract Class AbstractBeanDefinitionParser

extends Object
implements BeanDefinitionParser
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.xml.BeanDefinitionParser
Known Direct Subclasses
org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
Imports
org.w3c.dom.Element, org.springframework.beans.factory.BeanDefinitionStoreException, org.springframework.beans.factory.config.BeanDefinition, .BeanDefinitionHolder, org.springframework.beans.factory.parsing.BeanComponentDefinition, org.springframework.beans.factory.support.AbstractBeanDefinition, .BeanDefinitionReaderUtils, .BeanDefinitionRegistry, org.springframework.lang.Nullable, org.springframework.util.StringUtils

Abstract BeanDefinitionParser implementation providing a number of convenience methods and a template method that subclasses must override to provide the actual parsing logic.

Use this BeanDefinitionParser implementation when you want to parse some arbitrarily complex XML into one or more BeanDefinitions. If you just want to parse some XML into a single BeanDefinition, you may wish to consider the simpler convenience extensions of this class, namely AbstractSingleBeanDefinitionParser and AbstractSimpleBeanDefinitionParser.

Authors
Rob Harrop, Juergen Hoeller, Rick Evans, Dave Syer
Since
2.0

Field Summary

Modifier and TypeField and Description
public static final String
ID_ATTRIBUTE

Constant for the "id" attribute.

public static final String
NAME_ATTRIBUTE

Constant for the "name" attribute.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final 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; provides access to a org.springframework.beans.factory.support.BeanDefinitionRegistry
parserContext
)

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

Parse the specified Element and register the resulting BeanDefinition(s) with the BeanDefinitionRegistry embedded in the supplied ParserContext.
protected abstract AbstractBeanDefinition

Returns:

the primary BeanDefinition resulting from the parsing of the supplied Element
parseInternal
(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; provides access to a org.springframework.beans.factory.support.BeanDefinitionRegistry
parserContext
)

Central template method to actually parse the supplied Element into one or more BeanDefinitions.

protected void
postProcessComponentDefinition(BeanComponentDefinition
the BeanComponentDefinition that is to be processed
componentDefinition
)

Hook method called after the primary parsing of a BeanComponentDefinition but before the BeanComponentDefinition has been registered with a org.springframework.beans.factory.support.BeanDefinitionRegistry.

protected void
registerBeanDefinition(BeanDefinitionHolder
the bean definition to be registered
definition
,
BeanDefinitionRegistry
the registry that the bean is to be registered with
registry
)

Register the supplied bean with the supplied registry.

protected String

Returns:

the resolved id
resolveId
(Element
the element that the bean definition has been built from
element
,
AbstractBeanDefinition
the bean definition to be registered
definition
,
ParserContext
the object encapsulating the current state of the parsing process; provides access to a org.springframework.beans.factory.support.BeanDefinitionRegistry
parserContext
)

Resolve the ID for the supplied BeanDefinition.

protected boolean

Returns:

true in order to fire a component registration event after parsing the bean definition; false to suppress the event
shouldFireEvents
()

Determine whether this parser is supposed to fire a org.springframework.beans.factory.parsing.BeanComponentDefinition event after parsing the bean definition.

protected boolean

Returns:

whether the parser should always generate an id
shouldGenerateId
()

Should an ID be generated instead of read from the passed in Element?

protected boolean

Returns:

whether the parser should generate an id if no id was specified
shouldGenerateIdAsFallback
()

Should an ID be generated instead if the passed in Element does not specify an "id" attribute explicitly?

protected boolean

Returns:

whether the parser should evaluate the "name" attribute as aliases
shouldParseNameAsAliases
()

Determine whether the element's "name" attribute should get parsed as bean definition aliases, i.e. alternative bean definition names.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ID_ATTRIBUTEback to summary
public static final String ID_ATTRIBUTE

Constant for the "id" attribute.

NAME_ATTRIBUTEback to summary
public static final String NAME_ATTRIBUTE

Constant for the "name" attribute.

Constructor Detail

AbstractBeanDefinitionParserback to summary
public AbstractBeanDefinitionParser()

Method Detail

parseback to summary
public final BeanDefinition parse(Element element, ParserContext parserContext)

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

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

Parse the specified Element and register the resulting BeanDefinition(s) with the BeanDefinitionRegistry embedded in the supplied ParserContext.

Implementations must return the primary BeanDefinition that results from the parse if they will ever be used in a nested fashion (for example as an inner tag in a <property/> tag). Implementations may return null if they will not be used in a nested fashion.

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; provides access to a org.springframework.beans.factory.support.BeanDefinitionRegistry

Returns:BeanDefinition

the primary BeanDefinition

Annotations
@Override
@Nullable
parseInternalback to summary
protected abstract AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext)

Central template method to actually parse the supplied Element into one or more BeanDefinitions.

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; provides access to a org.springframework.beans.factory.support.BeanDefinitionRegistry

Returns:AbstractBeanDefinition

the primary BeanDefinition resulting from the parsing of the supplied Element

Annotations
@Nullable
See Also
parse(org.w3c.dom.Element, ParserContext), postProcessComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)
postProcessComponentDefinitionback to summary
protected void postProcessComponentDefinition(BeanComponentDefinition componentDefinition)

Hook method called after the primary parsing of a BeanComponentDefinition but before the BeanComponentDefinition has been registered with a org.springframework.beans.factory.support.BeanDefinitionRegistry.

Derived classes can override this method to supply any custom logic that is to be executed after all the parsing is finished.

The default implementation is a no-op.

Parameters
componentDefinition:BeanComponentDefinition

the BeanComponentDefinition that is to be processed

registerBeanDefinitionback to summary
protected void registerBeanDefinition(BeanDefinitionHolder definition, BeanDefinitionRegistry registry)

Register the supplied bean with the supplied registry.

Subclasses can override this method to control whether the supplied bean is actually even registered, or to register even more beans.

The default implementation registers the supplied bean with the supplied registry only if the isNested parameter is false, because one typically does not want inner beans to be registered as top level beans.

Parameters
definition:BeanDefinitionHolder

the bean definition to be registered

registry:BeanDefinitionRegistry

the registry that the bean is to be registered with

See Also
BeanDefinitionReaderUtils#registerBeanDefinition(BeanDefinitionHolder, BeanDefinitionRegistry)
resolveIdback to summary
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException

Resolve the ID for the supplied BeanDefinition.

When using generation, a name is generated automatically. Otherwise, the ID is extracted from the "id" attribute, potentially with a fallback to a generated id.

Parameters
element:Element

the element that the bean definition has been built from

definition:AbstractBeanDefinition

the bean definition to be registered

parserContext:ParserContext

the object encapsulating the current state of the parsing process; provides access to a org.springframework.beans.factory.support.BeanDefinitionRegistry

Returns:String

the resolved id

Exceptions
BeanDefinitionStoreException:
if no unique name could be generated for the given bean definition
shouldFireEventsback to summary
protected boolean shouldFireEvents()

Determine whether this parser is supposed to fire a org.springframework.beans.factory.parsing.BeanComponentDefinition event after parsing the bean definition.

This implementation returns true by default; that is, an event will be fired when a bean definition has been completely parsed. Override this to return false in order to suppress the event.

Returns:boolean

true in order to fire a component registration event after parsing the bean definition; false to suppress the event

See Also
postProcessComponentDefinition, org.springframework.beans.factory.parsing.ReaderContext#fireComponentRegistered
shouldGenerateIdback to summary
protected boolean shouldGenerateId()

Should an ID be generated instead of read from the passed in Element?

Disabled by default; subclasses can override this to enable ID generation. Note that this flag is about always generating an ID; the parser won't even check for an "id" attribute in this case.

Returns:boolean

whether the parser should always generate an id

shouldGenerateIdAsFallbackback to summary
protected boolean shouldGenerateIdAsFallback()

Should an ID be generated instead if the passed in Element does not specify an "id" attribute explicitly?

Disabled by default; subclasses can override this to enable ID generation as fallback: The parser will first check for an "id" attribute in this case, only falling back to a generated ID if no value was specified.

Returns:boolean

whether the parser should generate an id if no id was specified

shouldParseNameAsAliasesback to summary
protected boolean shouldParseNameAsAliases()

Determine whether the element's "name" attribute should get parsed as bean definition aliases, i.e. alternative bean definition names.

The default implementation returns true.

Returns:boolean

whether the parser should evaluate the "name" attribute as aliases

Since
4.1.5