<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    最愛Java

    書山有路勤為徑,學海無涯苦作舟

    《AspectJ Cookbook》讀書筆記九: 捕獲程序作用域內的連接點

        切入點定義設計中的常用方式是:基于關注的程序作用域,限制捕獲連接點的范圍。這可以讓你即使控制在進一步的切入點定義中將會涉及哪些連接點。
        本章中的切入點相當容易理解,并且他們是AspectJ中一些常用的元素。例如,廣泛使用的within(TypePattern)切入點將以!within(%THIS_ASPECT%)形式使用它。這個AspectJ術語限制了當前方面之外的每個連接點的作用域,從而可以防止通知觸發對相同通知塊的遞歸調用,并導致一個無限循環。
        一. 捕獲特定類中的所有連接點
        使用within(TypePattern)切入點,利用TypePattern指定特定類類型模式,within(TypePattern)切入點的語法如下:
        pointcut <pointcut name>(<any values to be picked up>) : within(<class>);

        within(TypePattern)切入點具有3個關鍵特征:
            1.within(TypePattern)切入點捕獲指定類作用域中的所有連接點。
            2.within(TypePattern)切入點極少孤立使用。相反,它通常與切入點結合使用,用于減少將觸發附帶通知的連接點。
            3.TypePattern可以包含通配符,用于選擇不同類上的一系列連接點。


     

     

    package com.aspectj;

    public aspect WithinClassRecipe {
        
    /**
         * Specifies calling advice on any join point encountered within
         * the defined scope:
         * 
         * Scope:MyClass
         
    */

        pointcut withinMyClass() : within(MyClass);
        
        
    //Advice declaration
        before() : withinMyClass() && !within(WithinClassRecipe+{
            System.out.println(
    "---------- Aspect Advice Logic ----------");
            System.out.println(
    "In the advice picked by withinMyClass()");
            System.out.println(
    "Join Point Kind: " + thisJoinPoint.getKind());
            System.out.println(
    "Signature: " + thisJoinPoint.getStaticPart().getSignature());
            System.out.println(
    "Source Line: " + thisJoinPoint.getStaticPart().getSourceLocation());
            System.out.println(
    "-----------------------------------------");
        }


    }



    二. 捕獲特定包中的所有連接點
        within(TypePattern)切入點提供一種有用的手段,它使用通配符在出現在每個類中的連接點中指定一個關注??梢栽赥ypePattern中使用合適的通配符,從切入點邏輯的余下部分中包含或排除連接點的整個包。

    package com.aspectj;

    public aspect WithinPackageRecipe {
        
    /**
         * Specifies calling advice on any join point encountered within
         * the defined scope:
         * 
         * Scope:packageA
         
    */

        pointcut withinPackageA() : within(packageA.
    *);
        
        
    //Advice declaration
        before() : withinPackageA() && !within(WithinPackageRecipe+{
            System.out.println(
    "---------- Aspect Advice Logic ----------");
            System.out.println(
    "In the advice picked by WitinPackageRecipe()");
            System.out.println(
    "Join Point Kind: " + thisJoinPoint.getKind());
            System.out.println(
    "Signature: " + thisJoinPoint.getStaticPart().getSignature());
            System.out.println(
    "Source Line: " + thisJoinPoint.getStaticPart().getSourceLocation());
            System.out.println(
    "-----------------------------------------");
        }


    }


     

    三. 捕獲特定方法內的所有連接點
        使用withincode(Signature)切入點。withincode(Signature)切入點的語法如下:
        pointcut <pointcut name>(<any values to be picked up>) : withincode(<modifier> <class>.<method>(<paramter types>));

        withincode(Signature)切入點有3個關鍵特征:
            1. withincode(Signature)切入點指定了特定方法的本地作用域內的所有連接點。
            2. withincode(Signature)切入點極少孤立使用。相反,他通常與其他切入點結合使用,用于減少將觸發附帶通知的連接點。
            3. Signaure可以包含通配符,用于選擇不同類的不同方法上的一系列連接點。

    package com.aspectj;

    public aspect WithinMethodRecipe {
        
    /**
         * Specifies calling advice whenever a method
         * matching the following rules gets called:
         * 
         * Class Name:MyClass
         * Method Name:foo
         * Method Return Type: * (any return type)
         * Method Parameters: an int followed by a String
         
    */

        pointcut withinFooIntStringAnyReturnPointcut() : withincode(
    * MyClass.foo(int,String));
        
        
    //Advice declaration
        before() : withinFooIntStringAnyReturnPointcut() && !within(WithinMethodRecipe+{
            System.out.println(
    "---------- Aspect Advice Logic ----------");
            System.out.println(
    "In the advice picked by withinMyClass()");
            System.out.println(
    "Join Point Kind: " + thisJoinPoint.getKind());
            System.out.println(
    "Signature: " + thisJoinPoint.getStaticPart().getSignature());
            System.out.println(
    "Source Line: " + thisJoinPoint.getStaticPart().getSourceLocation());
            System.out.println(
    "-----------------------------------------");
        }


    }

    posted on 2008-08-25 10:32 Brian 閱讀(336) 評論(0)  編輯  收藏 所屬分類: 《AspectJ Cookbook》讀書筆記

    公告


    導航

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

    統計

    常用鏈接

    留言簿(4)

    隨筆分類

    隨筆檔案

    收藏夾

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲啪啪免费视频| 人妻仑刮八A级毛片免费看| 久久精品无码免费不卡| 最近的中文字幕大全免费版| 亚洲熟妇无码乱子AV电影| 亚洲国产精品无码第一区二区三区| 国产免费拔擦拔擦8X高清在线人| 国产免费久久精品久久久| 亚洲人成电影在线观看网| 中文字幕在线免费看| 免费v片在线观看无遮挡| 亚洲av极品无码专区在线观看| 三级网站在线免费观看| 免费a级毛片大学生免费观看 | 可以免费看黄视频的网站| 精品亚洲一区二区三区在线播放| 亚洲人成网站色7799| 91嫩草免费国产永久入口| 亚洲国产精华液网站w| 日韩在线观看免费| 日韩免费视频在线观看| 亚洲a∨无码男人的天堂| 8090在线观看免费观看| 亚洲AV无码一区二区乱孑伦AS| 一级毛片免费毛片毛片| 国产成人无码免费视频97| 中日韩亚洲人成无码网站| 91精品成人免费国产片| 亚洲无删减国产精品一区| 国产免费一区二区三区在线观看| 亚洲一区二区三区在线观看精品中文 | 亚洲精品视频免费看| 亚洲av无码乱码国产精品| a国产成人免费视频| 亚洲综合区小说区激情区| 免费无码国产在线观国内自拍中文字幕 | 无码人妻一区二区三区免费视频 | 无限动漫网在线观看免费| 亚洲国产精品成人综合色在线婷婷 | 成人免费黄色网址| 亚洲第一成年网站大全亚洲|