posts - 66,  comments - 11,  trackbacks - 0
          現(xiàn)在你可以為你的應(yīng)用系統(tǒng)創(chuàng)建可重復(fù)使用的切入點了。Spring支持在這些切入點上進(jìn)行操作-合并與交叉-來創(chuàng)建新的切入點
          。只有當(dāng)所有切入點都匹配時交叉集合才匹配,任何一個切入點匹配都會使合并集合匹配。為了對2個Pointcut對象進(jìn)行合并,必須使用Pointcuts類。例如:
          Pointcut union = Pointcuts.union(pointcut1,pointcut2);
          這種方式的一個缺點是它需要通過編碼來實現(xiàn)。
          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 王永慶 閱讀(170) 評論(0)  編輯  收藏 所屬分類: SPRING
          <2009年11月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          關(guān)注blogs

          搜索

          •  

          最新評論

          • 1.?re: 心中的那個她[未登錄]
          • 如果心情能那么容易放開就好了,碰到她是我的緣分,但是她的緣分不知道在哪里。
          • --王永慶
          • 2.?re: 心中的那個她[未登錄]
          • 兄弟,喜歡就大膽去追好了,就是因為喜歡才會有不愉快,如果想一輩子沒有這些煩惱,找一個可有可無的人就好了。這種事講的是緣分吧。別人對你好不好其實不太重要。放開心情就好了。
          • --萍水相逢
          • 3.?re: 心中的那個她
          • 只能同甘不能共苦,就他媽算了吧,程序員也是人啊!我現(xiàn)在也很討厭女的不理解人情。
          • --咖啡妝
          • 4.?re: 難以割舍的那份情感
          • 評論內(nèi)容較長,點擊標(biāo)題查看
          • --王永慶
          • 5.?re: 難以割舍的那份情感
          • 評論內(nèi)容較長,點擊標(biāo)題查看
          • --隔葉黃鶯

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 泾川县| 福贡县| 东台市| 峡江县| 淮北市| 绥棱县| 新竹县| 会东县| 唐山市| 虎林市| 澎湖县| 江西省| 武山县| 邮箱| 五原县| 克东县| 东丰县| 宁晋县| 行唐县| 三台县| 远安县| 湄潭县| 鄂州市| 霸州市| 江川县| 鄂伦春自治旗| 灯塔市| 益阳市| 海淀区| 含山县| 阿克苏市| 金乡县| 库车县| 龙江县| 嘉鱼县| 仁化县| 枣强县| 交口县| 沁水县| 新巴尔虎右旗| 永嘉县|