最愛Java

          書山有路勤為徑,學(xué)海無涯苦作舟

          《AspectJ Cookbook》讀書筆記六: 捕獲通知上的連接點

          一. 捕獲何時執(zhí)行通知
                  
          使用adviceexecution()切入點。adviceexecution()切入點的語法如下:
                  pointcut <pointcut name>() : adviceexecution();
          package com.aspectj;

          public aspect AdviceExecutionRecipe 
          {
             
          /*
                 Specifies calling advice whenever advice is executed
             
          */

             pointcut adviceExecutionPointcut() : adviceexecution();

             
          // Advice declaration
             before() : adviceExecutionPointcut()
             
          {
                System.out.println(
                   
          "------------------- Aspect Advice Logic --------------------");
                System.out.println(
          "In the advice picked by ExecutionRecipe");
                System.out.println(
                   
          "Signature: "
                      
          + thisJoinPoint.getStaticPart().getSignature());
                System.out.println(
                   
          "Source Line: "
                      
          + thisJoinPoint.getStaticPart().getSourceLocation());
                System.out.println(
                   
          "------------------------------------------------------------");
             }

          }


          二. 排出作為通知執(zhí)行結(jié)果的連接點
          三. 在發(fā)出通知時展示原始連接點
                  
          添加JoinPoint標(biāo)識符到切入點定義中。
          package com.aspectj;

          import org.aspectj.lang.JoinPoint;

          public aspect AdviceExecutionRecipe 
          {
             
          /*
                 Specifies calling advice whenever advice is executed
             
          */

             pointcut adviceExecutionPointcut(JoinPoint originalJoinPoint) : adviceexecution() 
          && args(originalJoinPoint) && !within(AdviceExecutionRecipe);

             
          // Advice declaration
             before(JoinPoint originalJoinPoint) : adviceExecutionPointcut(originalJoinPoint)
             
          {
                System.out.println(
                   
          "------------------- Aspect Advice Logic --------------------");
                System.out.println(
          "In the advice picked by AdviceExecutionRecipe");
                System.out.println(
                   
          "Signature: "
                      
          + thisJoinPoint.getStaticPart().getSignature());
                System.out.println(
                   
          "Source Line: "
                      
          + thisJoinPoint.getStaticPart().getSourceLocation());
                
                System.out.println(
                      
          "Advised Advice's Join Point Signature: "
                         
          + originalJoinPoint.getSignature());
                
                System.out.println(
                   
          "------------------------------------------------------------");
             }

          }


           

          posted on 2008-08-29 16:09 Brian 閱讀(375) 評論(0)  編輯  收藏 所屬分類: 《AspectJ Cookbook》讀書筆記

          公告


          導(dǎo)航

          <2008年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          統(tǒng)計

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 和林格尔县| 吐鲁番市| 巴里| 桂东县| 当涂县| 体育| 海口市| 托克托县| 洞口县| 丰顺县| 台中市| 库伦旗| 邵阳县| 常德市| 岳池县| 九寨沟县| 西和县| 伊金霍洛旗| 集贤县| 武清区| 凤山市| 长沙市| 淮滨县| 江源县| 福贡县| 化州市| 宁波市| 稻城县| 鄂州市| 凉城县| 桐梓县| 富锦市| 修武县| 调兵山市| 仲巴县| 和林格尔县| 屯留县| 泰顺县| 南康市| 永城市| 沈丘县|