posts - 66,  comments - 11,  trackbacks - 0
          現在你可以為你的應用系統創(chuàng)建可重復使用的切入點了。Spring支持在這些切入點上進行操作-合并與交叉-來創(chuàng)建新的切入點
          。只有當所有切入點都匹配時交叉集合才匹配,任何一個切入點匹配都會使合并集合匹配。為了對2個Pointcut對象進行合并,必須使用Pointcuts類。例如:
          Pointcut union = Pointcuts.union(pointcut1,pointcut2);
          這種方式的一個缺點是它需要通過編碼來實現。
          package com.wyq.spring.base.aopinstance;

          import java.util.List;

          import org.springframework.aop.ClassFilter;
          import org.springframework.aop.MethodMatcher;
          import org.springframework.aop.Pointcut;
          import org.springframework.aop.support.Pointcuts;

          /** 
           * 
          @author 作者 
           * 
          @version 創(chuàng)建時間:2009-11-6 下午02:18:03 
           * 類說明 
           
          */
          public class UnionPointcut implements Pointcut {
              
          //聲明合并的Pointcut實例
              private Pointcut delegate;
              
              
          public Pointcut getDelegate() {
                  
          return delegate;
              }

              
          public void setDelegate(Pointcut delegate) {
                  
          this.delegate = delegate;
              }
              
          //委托給Pointcut的方法
              public ClassFilter getClassFilter() {
                  
          return getDelegate().getClassFilter();
              }

              
          public MethodMatcher getMethodMatcher() {
                  
          return getDelegate().getMethodMatcher();
              }
              
          //創(chuàng)建組合切入點
              public void setPointcuts(List pointcuts){
                  
          if(pointcuts == null || pointcuts.size()==0){
                      System.out.println(
          "沒有要組合的切入點");
                  }
                  delegate 
          = (Pointcut)pointcuts.get(0);
                  
          for(int i=1;i<pointcuts.size();i++){
                      Pointcut pointcut 
          = (Pointcut)pointcuts.get(i);
                      delegate 
          = Pointcuts.union(delegate,pointcut);
                  }
              }

          }
          映射文件如下:
          <?xml version="1.0" encoding="UTF-8"?>
          <beans
              
          xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
              
          <bean id="frequentCustomerAdvice" class="com.wyq.spring.common.aopinstance.namemachmethodpointcut.PrequentCustomerAdvice"></bean>
              
              
          <bean id="queryInterceptor" class="com.wyq.spring.common.aopinstance.namemachmethodpointcut.QueryInterceptor"></bean>
              
              
          <bean id="unionpointcut" class="com.wyq.spring.common.aopinstance.composablepointcut.UnionPointcut">
                  
          <property name="delegate">
                      
          <ref bean="frequentCustomerPointcutAdvisor"/>
                  
          </property>
                  
          <property name="pointcuts">
                      
          <list>
                          
          <ref bean="queryPointCutAdvisor"/>
                      
          </list>
                  
          </property>
              
          </bean>
              
          <bean id="frequentCustomerPointcutAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
                  
          <property name="mappedName">
                      
          <value>order*</value>
                  
          </property>
                  
          <property name="advice">
                      
          <ref bean="frequentCustomerAdvice"/>
                  
          </property>
              
          </bean>
              
              
          <bean id="queryPointCutAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
                  
          <property name="pattern">
                      
          <value>.*get.+By.+</value>
                  
          </property>
                  
          <property name="advice">
                      
          <ref bean="queryInterceptor"/>
                  
          </property>
              
          </bean>
          </beans>

          posted on 2009-11-06 14:48 王永慶 閱讀(167) 評論(0)  編輯  收藏 所屬分類: SPRING
          <2009年11月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          關注blogs

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 樟树市| 白沙| 曲阜市| 当阳市| 武川县| 海伦市| 满洲里市| 瑞金市| 寿宁县| 宁安市| 高邑县| 巴中市| 青州市| 巴里| 新源县| 富民县| 尚志市| 乌鲁木齐县| 乌拉特中旗| 江油市| 清徐县| 东乡县| 奉节县| 云龙县| 宁蒗| 磐石市| 临沂市| 筠连县| 广汉市| 云龙县| 彩票| 麻阳| 北川| 正安县| 彝良县| 察哈| 化州市| 滁州市| 石河子市| 壤塘县| 曲沃县|