posts - 66,  comments - 11,  trackbacks - 0
          現在你可以為你的應用系統創建可重復使用的切入點了。Spring支持在這些切入點上進行操作-合并與交叉-來創建新的切入點
          。只有當所有切入點都匹配時交叉集合才匹配,任何一個切入點匹配都會使合并集合匹配。為了對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 創建時間: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();
              }
              
          //創建組合切入點
              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

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 平南县| 厦门市| 湖北省| 大庆市| 临西县| 洪洞县| 塘沽区| 靖宇县| 历史| 观塘区| 元阳县| 西华县| 射阳县| 台东县| 仁怀市| 邓州市| 新晃| 登封市| 开江县| 太仓市| 都匀市| 汪清县| 福海县| 辽宁省| 曲松县| 扬中市| 新蔡县| 庄浪县| 阿巴嘎旗| 绵竹市| 宁陕县| 甘肃省| 措美县| 嘉义市| 略阳县| 砚山县| 荔浦县| 景德镇市| 德化县| 阜康市| 临夏县|