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

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

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

    posts - 431,  comments - 344,  trackbacks - 0

    1.   捕獲對構造函數的調用
           pointcut <pointcut name>(<any values to be picked up>) : call(<optional modifier> <class>.new(<parameter types>));

    2.   在執行構造函數時捕獲它
          pointcut <pointcut name>(<any values to be picked up>) : execution(<optional modifier> <class>.new(<parameter types>));

    3.   捕獲何時初始化對象
          pointcut <pointcut name>(<any values to be picked up>) : initialization(<optional modifier> <class>.new(<parameter types>));
          initialization(Signature)切入點必須包含new關鍵字,Signature必須解析成特定類的構造函數,而不是一個簡單的方法。
          由于AspectJ編譯器中的編譯器限制,當與around()通知關聯時,不能使用initialization(Signature)切入點。
          與execution(Signature)切入點相比,使用initialization(Signature)切入點最大優點是:它提供了編譯時檢查,以確保簽名實際上制定了一個構造函數。

    4.   捕獲何時將要初始化一個對象
          pointcut <pointcut name>(<any values to be picked up>) : preinitialization(<optional modifier> <class>.new(<parameter types>));

    5.   捕獲何時初始化類
          
    pointcut <pointcut name>(<any values to be picked up>) : staticinitialization(<class>);


    package com.eric.aspectj;

    public aspect CallNewRecipe {
     pointcut myClassConstructorWithIntAndStringPointcutStaticinitialization() : staticinitialization(MyClass);
     pointcut myClassConstructorWithIntAndStringPointcutCall() : call(MyClass.new(int, String));
     pointcut myClassConstructorWithIntAndStringPointcutExecution() : execution(MyClass.new(int, String));
     pointcut myClassConstructorWithIntAndStringPointcutPreinitialization() : preinitialization(MyClass.new(int, String));
     pointcut myClassConstructorWithIntAndStringPointcutInitialization() : initialization(MyClass.new(int, String));
     
     
     before() : myClassConstructorWithIntAndStringPointcutExecution() {
      System.out.println("-------------- Aspect Advice Logic Execution ---------------");
      System.out.println("In the advice picked by " + "myClassConstructorWithIntAndOthersPointcut()");
      System.out.println("The current type of object under construction is: ");
      System.out.println("getThis: " + thisJoinPoint.getThis());
      System.out.println("getTarget: " + thisJoinPoint.getTarget());
      System.out.println("getKind: " + thisJoinPoint.getKind());
      System.out.println("Signature: " + thisJoinPoint.getSignature());
      System.out.println("getName: " + thisJoinPoint.getSignature().getName());
      System.out.println("getDeclaringTypeName: " + thisJoinPoint.getSignature().getDeclaringTypeName());
      System.out.println("getDeclaringType: " + thisJoinPoint.getSignature().getDeclaringType());
      System.out.println("getModifiers: " + thisJoinPoint.getSignature().getModifiers());
      System.out.println("Source Line: " + thisJoinPoint.getSourceLocation());
      System.out.println("toString: " + thisJoinPoint.toString());
      System.out.println("--------------------------------------------------");
     }
     before() : myClassConstructorWithIntAndStringPointcutStaticinitialization() {
      System.out.println("--------------- Staticinitialization ------------------");
     }
     before() : myClassConstructorWithIntAndStringPointcutCall() {
      System.out.println("--------------- Call ------------------");
     }
     before() : myClassConstructorWithIntAndStringPointcutPreinitialization() {
      System.out.println("--------------- Preinitialization ------------------");
     }
     before() : myClassConstructorWithIntAndStringPointcutInitialization() {
      System.out.println("--------------- Initialization ------------------");
     }
    }

    package com.eric.aspectj;

    public class MyClass {

     private int number;
     private String name;
     
     public MyClass(int number, String name) {
      this.number = number;
      this.name = name;
     }
     /**
      * @param args
      */
     public static void main(String[] args) {
      // TODO Auto-generated method stub
      MyClass myObject = new MyClass(123, "Eric Chau");
     }

    }

    運行結果:
    --------------- Staticinitialization ------------------
    --------------- Call ------------------
    --------------- Preinitialization ------------------
    --------------- Initialization ------------------
    -------------- Aspect Advice Logic Execution ---------------
    In the advice picked by myClassConstructorWithIntAndOthersPointcut()
    The current type of object under construction is:
    getThis: com.eric.aspectj.MyClass@10d448
    getTarget: com.eric.aspectj.MyClass@10d448
    getKind: constructor-execution
    Signature: com.eric.aspectj.MyClass(int, String)
    getName: <init>
    getDeclaringTypeName: com.eric.aspectj.MyClass
    getDeclaringType: class com.eric.aspectj.MyClass
    getModifiers: 1
    Source Line: MyClass.java:8
    toString: execution(com.eric.aspectj.MyClass(int, String))
    --------------------------------------------------

    posted on 2007-07-04 13:56 周銳 閱讀(255) 評論(0)  編輯  收藏 所屬分類: AspectJ
    主站蜘蛛池模板: 国产成人久久AV免费| 免费无码作爱视频| 国产免费AV片在线播放唯爱网| 亚洲av午夜福利精品一区| 东北美女野外bbwbbw免费| 中文字幕亚洲综合久久菠萝蜜 | 青青草97国产精品免费观看| 成年女人永久免费观看片| 亚洲欧美日韩一区二区三区| 四虎免费在线观看| 妇女自拍偷自拍亚洲精品| 四虎影视永久免费观看网址| 四虎影视在线看免费观看| 亚洲国产综合人成综合网站| 精品国产免费一区二区三区| 国产∨亚洲V天堂无码久久久| 亚洲免费电影网站| 永久免费av无码不卡在线观看| 在线观看亚洲AV日韩A∨| 国产特级淫片免费看| 无码AV动漫精品一区二区免费| 久久久久亚洲AV成人网人人软件| 中文字幕无码毛片免费看| 亚洲AV日韩精品久久久久| 免费能直接在线观看黄的视频| 国内精品久久久久影院亚洲| 国产一区二区三区免费看| 久青草视频97国内免费影视| 久久久久亚洲AV无码永不| 无码一区二区三区AV免费| 美女被免费视频网站| 精品国产亚洲一区二区三区| 亚洲美女免费视频| 精品日韩亚洲AV无码| 24小时免费直播在线观看| 免费中文字幕视频| 久久精品亚洲中文字幕无码麻豆| 女人18毛片a级毛片免费视频| 又硬又粗又长又爽免费看 | 亚洲午夜精品一级在线播放放 | 亚洲综合AV在线在线播放|