关于spring 2.0自定义xml 标记 (一 主要的相关类)

 在spring 2.0 中,增加了自定义xml标记这一重大的功能。下面主要看一下spring 2.0实现这一功能的主要相关类:

  NamespaceHandlerResolver(接口)
    由DefaultBeanDefinitionDocumentReader使用,用于定位NamespaceHandler,指定特定的命名空间uri

   实现类:
   DefaultNamespaceHandlerResolver
  
   通过map 保存所有的对应关系
   默认使用spring.handlers文件来保存所有的handlers
   可以定义其他的location 如:

   String location = "org/springframework/beans/factory/xml/support/customNamespace.properties";
   NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), location);
  
   NamespaceHandler(接口)
   
      基础接口,用于DefaultBeanDefinitionDocumentReader处理自定义命名空间。
      方法:
         void init();
         由DefaultBeanDefinitionDocumentReader调用在构造完后但在解析自定义元素前。
 
         BeanDefinition parse(Element element, ParserContext parserContext);
         解析指定的元素。
 
         BeanDefinitionHolder decorate(Node element,
                                    BeanDefinitionHolder definition,
                                    ParserContext parserContext);
         执行相应的修饰。

   实现类:
    
     NamespaceHandlerSupport(抽象类)
  
   主要的三个方法:
   protected final void registerBeanDefinitionDecorator(
                         String elementName,
                         BeanDefinitionDecorator decorator)
   注册decorator,通过element
 
   protected final void registerBeanDefinitionDecoratorForAttribute(
                          String attributeName,
                          BeanDefinitionDecorator decorator)
    注册decorator,通过attr
  
    protected final void registerBeanDefinitionParser(
                          String  elementName,
                          BeanDefinitionParser parser)
    注册BeanDefinitionParser,通过element

   实际的操作由具体的BeanDefinitionDecorator 或者BeanDefinitionParser 执行

  BeanDefinitionDecorator(接口)

   装饰相关的自定义属性。

     AbstractInterceptorDrivenBeanDefinitionDecorator
          用于注册相应的Interceptor bean 定义,使用aop代理

  其他类:

    PluggableSchemaResolver,用于自定义相关的schema,默认的schema 保存于spring.schemas文件中

    可以通过覆盖resolveEntity方法来装载相应的自定义xsd文件

  主要的执行类:
 

  XmlBeanDefinitionReader
 
    用于处理相应的读取工作,其实主要的工作委派给BeanDefinitionDocumentReader


  实际的类,就介绍到这,下一节通过实例来说明如何定义自定义xml 元素

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值