最愛Java

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

          《AspectJ Cookbook》讀書筆記六: 捕獲通知上的連接點(diǎn)

          一. 捕獲何時(shí)執(zhí)行通知
                  
          使用adviceexecution()切入點(diǎn)。adviceexecution()切入點(diǎn)的語法如下:
                  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é)果的連接點(diǎn)
          三. 在發(fā)出通知時(shí)展示原始連接點(diǎn)
                  
          添加JoinPoint標(biāo)識(shí)符到切入點(diǎn)定義中。
          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) 評(píng)論(0)  編輯  收藏 所屬分類: 《AspectJ Cookbook》讀書筆記

          公告


          導(dǎo)航

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

          統(tǒng)計(jì)

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          收藏夾

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 固镇县| 开封市| 宁陵县| 赤峰市| 荥阳市| 宣武区| 涞源县| 个旧市| 武城县| 达孜县| 密山市| 济南市| 湟源县| 昌平区| 南宫市| 安义县| 土默特左旗| 阿瓦提县| 山西省| 三都| 绥德县| 苍梧县| 焦作市| 四子王旗| 定襄县| 台江县| 遂昌县| 凤翔县| 济源市| 依安县| 枣强县| 漳州市| 留坝县| 黔西| 土默特右旗| 龙陵县| 运城市| 漳州市| 怀远县| 永修县| 郸城县|