接口 NamespaceHandler
- 所有已知实现类:
AopNamespaceHandler,CacheNamespaceHandler,ContextNamespaceHandler,JdbcNamespaceHandler,JeeNamespaceHandler,JmsNamespaceHandler,LangNamespaceHandler,MvcNamespaceHandler,NamespaceHandlerSupport,OxmNamespaceHandler,SimpleConstructorNamespaceHandler,SimplePropertyNamespaceHandler,TaskNamespaceHandler,TxNamespaceHandler,UtilNamespaceHandler,WebSocketNamespaceHandler
public interface NamespaceHandler
Base interface used by theDefaultBeanDefinitionDocumentReaderfor handling custom namespaces in a Spring XML configuration file.Implementations are expected to return implementations of the
BeanDefinitionParserinterface for custom top-level tags and implementations of theBeanDefinitionDecoratorinterface for custom nested tags.The parser will call
parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)when it encounters a custom tag directly under the<beans>tags anddecorate(org.w3c.dom.Node, org.springframework.beans.factory.config.BeanDefinitionHolder, org.springframework.beans.factory.xml.ParserContext)when it encounters a custom tag directly under a<bean>tag.Developers writing their own custom element extensions typically will not implement this interface directly, but rather make use of the provided
NamespaceHandlerSupportclass.- 从以下版本开始:
- 2.0
- 作者:
- Rob Harrop, Erik Wiersma
- 另请参阅:
DefaultBeanDefinitionDocumentReader,NamespaceHandlerResolver
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 BeanDefinitionHolderdecorate(Node source, BeanDefinitionHolder definition, ParserContext parserContext)Parse the specifiedNodeand decorate the suppliedBeanDefinitionHolder, returning the decorated definition.voidinit()Invoked by theDefaultBeanDefinitionDocumentReaderafter construction but before any custom elements are parsed.BeanDefinitionparse(Element element, ParserContext parserContext)Parse the specifiedElementand register any resultingBeanDefinitionswith theBeanDefinitionRegistrythat is embedded in the suppliedParserContext.
方法详细资料
init
void init()
Invoked by theDefaultBeanDefinitionDocumentReaderafter construction but before any custom elements are parsed.
parse
BeanDefinition parse(Element element, ParserContext parserContext)
Parse the specifiedElementand register any resultingBeanDefinitionswith theBeanDefinitionRegistrythat is embedded in the suppliedParserContext.Implementations should return the primary
BeanDefinitionthat results from the parse phase if they wish to be used nested inside (for example) a<property>tag.Implementations may return
nullif they will not be used in a nested scenario.- 参数:
element- the element that is to be parsed into one or moreBeanDefinitionsparserContext- the object encapsulating the current state of the parsing process- 返回:
- the primary
BeanDefinition(can benullas explained above)
decorate
BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder definition, ParserContext parserContext)
Parse the specifiedNodeand decorate the suppliedBeanDefinitionHolder, returning the decorated definition.The
Nodemay be either anAttror 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
ParserContextcan be used to register any additional beans needed to support the main definition.- 参数:
source- the source element or attribute that is to be parseddefinition- the current bean definitionparserContext- the object encapsulating the current state of the parsing process- 返回:
- the decorated definition (to be registered in the BeanFactory), or simply the original bean definition if no decoration is required. A
nullvalue is strictly speaking invalid, but will be leniently treated like the case where the original bean definition gets returned.