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

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

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

    最?lèi)?ài)Java

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

    《AspectJ Cookbook》讀書(shū)筆記十: 捕獲基于控制流程的連接點(diǎn)

        本章中描述的切入點(diǎn)支持捕獲另一個(gè)初始連接點(diǎn)作用域或環(huán)境內(nèi)的所有連接點(diǎn)。每個(gè)連接點(diǎn)在程序的控制流程中都有一個(gè)具體位置,這為通過(guò)這里描述的切入點(diǎn)聲明捕獲的連接點(diǎn)提供了環(huán)境。
        一. 捕獲通過(guò)初始連接點(diǎn)開(kāi)始的程序控制流程內(nèi)的所有連接點(diǎn)
        使用cflow(Pointcut)切入點(diǎn)。cflow(Pointcut)切入點(diǎn)的語(yǔ)法如下:
        pointcut <pointcut name>(<any values to be picked up>) : cflow(<pointcut>);

        cflow(Pointcut)切入點(diǎn)具有3個(gè)關(guān)鍵特征:
            1.cflow(Pointcut)切入點(diǎn)捕獲在初始特定的連接點(diǎn)環(huán)境內(nèi)遇到的所有連接點(diǎn),這個(gè)初始連接點(diǎn)是通過(guò)另一個(gè)切入點(diǎn)選擇的。
            2.捕獲的連接點(diǎn)包括初始連接點(diǎn)。
            3.作用域是cflow(pointcut)切入點(diǎn)中重要的鑒別器。這個(gè)切入點(diǎn)將捕獲通過(guò)切入點(diǎn)參數(shù)捕獲的連接點(diǎn)的控制流程內(nèi)的所有連接點(diǎn)。


    package com.aspectj;

    public aspect CFlowRecipe {
        
    /**
         * Specifies calling advice whenever a method
         * matching the following rules gets called:
         * 
         * Class Name:MyClass
         * Method Name:foo
         * Method Return Type:void
         * Method Parameters: an int followed by a String
         
    */

        pointcut callInitialPointcut():call(
    void MyClass.foo(int,String));
        
        
    /**
         * Specifies calling advice whenever a join point is encountered
         * including and after the initial join point triggers the pointcut
         * that is specified in the parameter:
         * 
         * Pointcut Name:callInitialPointcut
         
    */

        pointcut cflowPointcut():cflow(callInitialPointcut());
        
        
    //Advice declaration
        before() : cflowPointcut() && !within(CFlowRecipe+{
            System.out.println(
    "---------- Aspect Advice Logic ----------");
            System.out.println(
    "In the advice picked by CFlowRecipe()");
            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(
    "-----------------------------------------");
        }
        
        

    }



            值得更詳細(xì)研究cflow(Pointcut)做什么。這個(gè)特殊的切入點(diǎn)引入了連接點(diǎn)環(huán)境的概念。它是指每個(gè)連接點(diǎn)具有一個(gè)作用域,在這個(gè)用途域內(nèi),它被看成是執(zhí)行程序的控制流程的一部分。
            在這個(gè)控制流程內(nèi),任何遇到的連接點(diǎn)都會(huì)觸發(fā)cflow(Pointcut)切入點(diǎn),并調(diào)用任何關(guān)聯(lián)的通知。當(dāng)初始連接點(diǎn)觸發(fā)指定的切入點(diǎn)參數(shù)時(shí),cflow(Pointcut)切入點(diǎn)會(huì)起作用,并觸發(fā)其關(guān)聯(lián)的通知。然后,將為在初始連接點(diǎn)環(huán)境內(nèi)的控制流程中遇到的每個(gè)連接點(diǎn)調(diào)用與cflow(Pointcut)關(guān)聯(lián)的通知。最后,捕獲的連接點(diǎn)集合包括初始連接點(diǎn)本身,這就是這個(gè)切入點(diǎn)與cflowbelow(Pointcut)切入點(diǎn)之間的主要區(qū)別。

            在cflow(Pointcut)的當(dāng)前實(shí)現(xiàn)中,在使用它時(shí),其實(shí)現(xiàn)方式會(huì)引入大量的系統(tǒng)開(kāi)銷(xiāo)。在可能的地方,并且連接點(diǎn)重用不受影響時(shí),可以考慮優(yōu)先使用withincode(Signature)切入點(diǎn)。

        二.捕獲程序控制流程內(nèi)的所有連接點(diǎn),不包括初始連接點(diǎn)
        使用cflowbelow(Pointcut)切入點(diǎn)。cflowbelow(Pointcut)切入點(diǎn)的語(yǔ)法如下:
        pointcut <pointcut name>(<any values to be picked up>) : cflowbelow(<pointcut>);


    package com.aspectj;

    public aspect CFlowBelowRecipe {
        
    /**
         * Specifies calling advice whenever a method
         * matching the following rules gets called:
         * 
         * Class Name:MyClass
         * Method Name:foo
         * Method Return Type:void
         * Method Parameters: an int followed by a String
         
    */

        pointcut callInitialPointcut():call(
    void MyClass.foo(int,String));
        
        
    /**
         * Specifies calling advice whenever a join point is encountered
         * after the initial join point triggers the pointcut
         * that is specified in the parameter:
         * 
         * Pointcut Name:callInitialPointcut
         
    */

        pointcut cflowPointcut():cflowbelow(callInitialPointcut());
        
        
    //Advice declaration
        before() : cflowPointcut() && !within(CFlowBelowRecipe+{
            System.out.println(
    "---------- Aspect Advice Logic ----------");
            System.out.println(
    "In the advice picked by CFlowBelowRecipe()");
            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)區(qū)別;其區(qū)別是實(shí)際捕獲的連接點(diǎn)數(shù)量。cflow(Pointcut)切入點(diǎn)會(huì)觸發(fā)在初始連接點(diǎn)環(huán)境內(nèi)遇到的所有連接點(diǎn)(包括初始連接點(diǎn))上的通知,而cflowbelow(Pointcut)切入點(diǎn)則不包括那個(gè)初始連接點(diǎn)。

    posted on 2008-08-25 10:36 Brian 閱讀(427) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): 《AspectJ Cookbook》讀書(shū)筆記

    公告


    導(dǎo)航

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

    統(tǒng)計(jì)

    常用鏈接

    留言簿(4)

    隨筆分類(lèi)

    隨筆檔案

    收藏夾

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 国产啪亚洲国产精品无码| 国产成人免费ā片在线观看 | 亚洲酒色1314狠狠做| ssswww日本免费网站片| 国产免费观看视频| 美女啪啪网站又黄又免费| 国产一级一片免费播放| 亚洲AV无码资源在线观看| 日韩中文字幕免费| 亚洲AV无码专区在线厂| 国产jizzjizz免费看jizz| 国产亚洲高清在线精品不卡| 国产jizzjizz视频全部免费| 美女被爆羞羞网站免费| 久久久久亚洲精品男人的天堂| 一级女性全黄生活片免费看| 中文字幕亚洲激情| 久久免费国产视频| 精品亚洲成a人片在线观看| 1000部拍拍拍18勿入免费视频下载 | 拍拍拍又黄又爽无挡视频免费| 亚洲午夜电影一区二区三区| 在线观看无码AV网站永久免费| 亚洲熟妇无码AV| 波多野结衣免费视频观看| 黄色片网站在线免费观看| 亚洲欧洲美洲无码精品VA| 69精品免费视频| 亚洲人成人网站18禁| 亚洲精品国产福利一二区| 久久99免费视频| 2020天堂在线亚洲精品专区| 国产免费直播在线观看视频| 久久不见久久见免费影院www日本| 亚洲AV第一页国产精品| 久久久久久久久免费看无码| 无套内谢孕妇毛片免费看看| 亚洲AV无码一区东京热| 国产精品免费观看久久| caoporm超免费公开视频| 亚洲另类小说图片|