Class AbstractBeanDefinitionParser
- java.lang.Object
- org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
- All Implemented Interfaces:
BeanDefinitionParser
- Direct Known Subclasses:
AbstractSingleBeanDefinitionParser
public abstract class AbstractBeanDefinitionParser extends Object implements BeanDefinitionParser
AbstractBeanDefinitionParserimplementation providing a number of convenience methods and atemplate methodthat subclasses must override to provide the actual parsing logic.Use this
BeanDefinitionParserimplementation when you want to parse some arbitrarily complex XML into one or moreBeanDefinitions. If you just want to parse some XML into a singleBeanDefinition, you may wish to consider the simpler convenience extensions of this class, namelyAbstractSingleBeanDefinitionParserandAbstractSimpleBeanDefinitionParser.- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller, Rick Evans, Dave Syer
Field Summary
Fields Modifier and Type Field Description static StringID_ATTRIBUTEConstant for the "id" attributestatic StringNAME_ATTRIBUTEConstant for the "name" attribute
Constructor Summary
Constructors Constructor Description AbstractBeanDefinitionParser()
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description BeanDefinitionparse(Element element, ParserContext parserContext)Parse the specifiedElementand register the resultingBeanDefinition(s)with theBeanDefinitionRegistryembedded in the suppliedParserContext.protected abstract AbstractBeanDefinitionparseInternal(Element element, ParserContext parserContext)Central template method to actually parse the suppliedElementinto one or moreBeanDefinitions.protected voidpostProcessComponentDefinition(BeanComponentDefinition componentDefinition)Hook method called after the primary parsing of aBeanComponentDefinitionbut before theBeanComponentDefinitionhas been registered with aBeanDefinitionRegistry.protected voidregisterBeanDefinition(BeanDefinitionHolder definition, BeanDefinitionRegistry registry)protected StringresolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)Resolve the ID for the suppliedBeanDefinition.protected booleanshouldFireEvents()Determine whether this parser is supposed to fire aBeanComponentDefinitionevent after parsing the bean definition.protected booleanshouldGenerateId()Should an ID be generated instead of read from the passed inElement?protected booleanshouldGenerateIdAsFallback()Should an ID be generated instead if the passed inElementdoes not specify an "id" attribute explicitly?protected booleanshouldParseNameAsAliases()Determine whether the element's "name" attribute should get parsed as bean definition aliases, i.e.
Field Detail
ID_ATTRIBUTE
public static final String ID_ATTRIBUTE
Constant for the "id" attribute- See Also:
- Constant Field Values
NAME_ATTRIBUTE
public static final String NAME_ATTRIBUTE
Constant for the "name" attribute- See Also:
- Constant Field Values
Constructor Detail
AbstractBeanDefinitionParser
public AbstractBeanDefinitionParser()
Method Detail
parse
public final BeanDefinition parse(Element element, ParserContext parserContext)
Description copied from interface:BeanDefinitionParserParse the specifiedElementand register the resultingBeanDefinition(s)with theBeanDefinitionRegistryembedded in the suppliedParserContext.Implementations must return the primary
BeanDefinitionthat 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 returnnullif they will not be used in a nested fashion.- Specified by:
parsein interfaceBeanDefinitionParser- Parameters:
element- the element that is to be parsed into one or moreBeanDefinitionsparserContext- the object encapsulating the current state of the parsing process; provides access to aBeanDefinitionRegistry- Returns:
- the primary
BeanDefinition
resolveId
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException
Resolve the ID for the suppliedBeanDefinition.When using
generation, a name is generated automatically. Otherwise, the ID is extracted from the "id" attribute, potentially with afallbackto a generated id.- Parameters:
element- the element that the bean definition has been built fromdefinition- the bean definition to be registeredparserContext- the object encapsulating the current state of the parsing process; provides access to aBeanDefinitionRegistry- Returns:
- the resolved id
- Throws:
BeanDefinitionStoreException- if no unique name could be generated for the given bean definition
registerBeanDefinition
protected void registerBeanDefinition(BeanDefinitionHolder definition, BeanDefinitionRegistry registry)
Register the suppliedbeanwith the suppliedregistry.Subclasses can override this method to control whether or not the supplied
beanis actually even registered, or to register even more beans.The default implementation registers the supplied
beanwith the suppliedregistryonly if theisNestedparameter isfalse, because one typically does not want inner beans to be registered as top level beans.- Parameters:
definition- the bean definition to be registeredregistry- the registry that the bean is to be registered with- See Also:
BeanDefinitionReaderUtils.registerBeanDefinition(BeanDefinitionHolder, BeanDefinitionRegistry)
parseInternal
protected abstract AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext)
Central template method to actually parse the suppliedElementinto one or moreBeanDefinitions.- Parameters:
element- the element that is to be parsed into one or moreBeanDefinitionsparserContext- the object encapsulating the current state of the parsing process; provides access to aBeanDefinitionRegistry- Returns:
- the primary
BeanDefinitionresulting from the parsing of the suppliedElement - See Also:
parse(org.w3c.dom.Element, ParserContext),postProcessComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)
shouldGenerateId
protected boolean shouldGenerateId()
Should an ID be generated instead of read from the passed inElement?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:
- whether the parser should always generate an id
shouldGenerateIdAsFallback
protected boolean shouldGenerateIdAsFallback()
Should an ID be generated instead if the passed inElementdoes 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:
- whether the parser should generate an id if no id was specified
shouldParseNameAsAliases
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:
- whether the parser should evaluate the "name" attribute as aliases
- Since:
- 4.1.5
shouldFireEvents
protected boolean shouldFireEvents()
Determine whether this parser is supposed to fire aBeanComponentDefinitionevent after parsing the bean definition.This implementation returns
trueby default; that is, an event will be fired when a bean definition has been completely parsed. Override this to returnfalsein order to suppress the event.- Returns:
truein order to fire a component registration event after parsing the bean definition;falseto suppress the event- See Also:
postProcessComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition),ReaderContext.fireComponentRegistered(org.springframework.beans.factory.parsing.ComponentDefinition)
postProcessComponentDefinition
protected void postProcessComponentDefinition(BeanComponentDefinition componentDefinition)
Hook method called after the primary parsing of aBeanComponentDefinitionbut before theBeanComponentDefinitionhas been registered with aBeanDefinitionRegistry.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- theBeanComponentDefinitionthat is to be processed