类 AbstractBeanDefinitionParser
- java.lang.Object
- org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
- 所有已实现的接口:
BeanDefinitionParser
public abstract class AbstractBeanDefinitionParser extends Object implements BeanDefinitionParser
AbstractBeanDefinitionParser
implementation providing a number of convenience methods and atemplate 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 moreBeanDefinitions
. If you just want to parse some XML into a singleBeanDefinition
, you may wish to consider the simpler convenience extensions of this class, namelyAbstractSingleBeanDefinitionParser
andAbstractSimpleBeanDefinitionParser
.- 从以下版本开始:
- 2.0
- 作者:
- Rob Harrop, Juergen Hoeller, Rick Evans, Dave Syer
字段概要
字段 修饰符和类型 字段 说明 static String
ID_ATTRIBUTE
Constant for the "id" attributestatic String
NAME_ATTRIBUTE
Constant for the "name" attribute
构造器概要
构造器 构造器 说明 AbstractBeanDefinitionParser()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 BeanDefinition
parse(Element element, ParserContext parserContext)
Parse the specifiedElement
and register the resultingBeanDefinition(s)
with theBeanDefinitionRegistry
embedded in the suppliedParserContext
.protected abstract AbstractBeanDefinition
parseInternal(Element element, ParserContext parserContext)
Central template method to actually parse the suppliedElement
into one or moreBeanDefinitions
.protected void
postProcessComponentDefinition(BeanComponentDefinition componentDefinition)
Hook method called after the primary parsing of aBeanComponentDefinition
but before theBeanComponentDefinition
has been registered with aBeanDefinitionRegistry
.protected void
registerBeanDefinition(BeanDefinitionHolder definition, BeanDefinitionRegistry registry)
protected String
resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
Resolve the ID for the suppliedBeanDefinition
.protected boolean
shouldFireEvents()
Determine whether this parser is supposed to fire aBeanComponentDefinition
event after parsing the bean definition.protected boolean
shouldGenerateId()
Should an ID be generated instead of read from the passed inElement
?protected boolean
shouldGenerateIdAsFallback()
Should an ID be generated instead if the passed inElement
does not specify an "id" attribute explicitly?protected boolean
shouldParseNameAsAliases()
Determine whether the element's "name" attribute should get parsed as bean definition aliases, i.e. alternative bean definition names.
字段详细资料
ID_ATTRIBUTE
public static final String ID_ATTRIBUTE
Constant for the "id" attribute- 另请参阅:
- 常量字段值
NAME_ATTRIBUTE
public static final String NAME_ATTRIBUTE
Constant for the "name" attribute- 另请参阅:
- 常量字段值
构造器详细资料
AbstractBeanDefinitionParser
public AbstractBeanDefinitionParser()
方法详细资料
parse
public final BeanDefinition parse(Element element, ParserContext parserContext)
从接口复制的说明:BeanDefinitionParser
Parse the specifiedElement
and register the resultingBeanDefinition(s)
with theBeanDefinitionRegistry
embedded in the suppliedParserContext
.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 returnnull
if they will not be used in a nested fashion.- 指定者:
parse
在接口中BeanDefinitionParser
- 参数:
element
- the element that is to be parsed into one or moreBeanDefinitions
parserContext
- the object encapsulating the current state of the parsing process; provides access to aBeanDefinitionRegistry
- 返回:
- 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 afallback
to a generated id.- 参数:
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
- 返回:
- the resolved id
- 抛出:
BeanDefinitionStoreException
- if no unique name could be generated for the given bean definition
registerBeanDefinition
protected void registerBeanDefinition(BeanDefinitionHolder definition, BeanDefinitionRegistry registry)
Register the suppliedbean
with the suppliedregistry
.Subclasses can override this method to control whether or not the supplied
bean
is actually even registered, or to register even more beans.The default implementation registers the supplied
bean
with the suppliedregistry
only if theisNested
parameter isfalse
, because one typically does not want inner beans to be registered as top level beans.- 参数:
definition
- the bean definition to be registeredregistry
- the registry that the bean is to be registered with- 另请参阅:
BeanDefinitionReaderUtils.registerBeanDefinition(BeanDefinitionHolder, BeanDefinitionRegistry)
parseInternal
protected abstract AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext)
Central template method to actually parse the suppliedElement
into one or moreBeanDefinitions
.- 参数:
element
- the element that is to be parsed into one or moreBeanDefinitions
parserContext
- the object encapsulating the current state of the parsing process; provides access to aBeanDefinitionRegistry
- 返回:
- the primary
BeanDefinition
resulting from the parsing of the suppliedElement
- 另请参阅:
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.
- 返回:
- whether the parser should always generate an id
shouldGenerateIdAsFallback
protected boolean shouldGenerateIdAsFallback()
Should an ID be generated instead if the passed inElement
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.
- 返回:
- 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
.- 返回:
- whether the parser should evaluate the "name" attribute as aliases
- 从以下版本开始:
- 4.1.5
shouldFireEvents
protected boolean shouldFireEvents()
Determine whether this parser is supposed to fire aBeanComponentDefinition
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 returnfalse
in order to suppress the event.- 返回:
true
in order to fire a component registration event after parsing the bean definition;false
to suppress the event- 另请参阅:
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 aBeanComponentDefinition
but before theBeanComponentDefinition
has 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.
- 参数:
componentDefinition
- theBeanComponentDefinition
that is to be processed