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

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

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

    最愛Java

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

    《AspectJ Cookbook》讀書筆記九: 捕獲程序作用域內(nèi)的連接點(diǎn)

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

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


     

     

    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(
    "-----------------------------------------");
        }


    }



    二. 捕獲特定包中的所有連接點(diǎn)
        within(TypePattern)切入點(diǎn)提供一種有用的手段,它使用通配符在出現(xiàn)在每個(gè)類中的連接點(diǎn)中指定一個(gè)關(guān)注。可以在TypePattern中使用合適的通配符,從切入點(diǎn)邏輯的余下部分中包含或排除連接點(diǎn)的整個(gè)包。

    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(
    "-----------------------------------------");
        }


    }


     

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

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

    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》讀書筆記

    公告


    導(dǎo)航

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

    統(tǒng)計(jì)

    常用鏈接

    留言簿(4)

    隨筆分類

    隨筆檔案

    收藏夾

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产精品黄页免费高清在线观看| 6080午夜一级毛片免费看| 亚洲人色婷婷成人网站在线观看| 69免费视频大片| 看成年女人免费午夜视频| 亚洲成AV人片在线观看无| 无码人妻一区二区三区免费| 2022国内精品免费福利视频 | 亚洲国产成人综合精品| 国产自偷亚洲精品页65页| 青青青免费国产在线视频小草| 污视频网站在线免费看| 亚洲人成电影福利在线播放| 国产精品国产免费无码专区不卡 | 亚洲av无码片区一区二区三区| 亚洲AⅤ无码一区二区三区在线| 色猫咪免费人成网站在线观看| 久久人午夜亚洲精品无码区| 麻豆亚洲av熟女国产一区二| 亚洲国产成人乱码精品女人久久久不卡| 午夜无码A级毛片免费视频 | 一级毛片a免费播放王色电影 | 久久亚洲熟女cc98cm| 亚洲精品国精品久久99热| 免费毛片a在线观看67194| 成在线人视频免费视频 | 免费的黄色的网站| 亚洲成年人电影网站| 国产美女亚洲精品久久久综合| 中文字幕影片免费在线观看| 国产情侣久久久久aⅴ免费| 国产精品国产亚洲区艳妇糸列短篇| 亚洲国产人成网站在线电影动漫| 又大又硬又爽免费视频| 好男人www免费高清视频在线| 久久99青青精品免费观看| 一级毛片在线免费播放| 国产精品手机在线亚洲| 亚洲色欲色欲www| 亚洲一区二区在线视频| 亚洲AV无码第一区二区三区|