1   /***************************************************************************************
2    * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved.                 *
3    * http://aspectwerkz.codehaus.org                                                    *
4    * ---------------------------------------------------------------------------------- *
5    * The software in this package is published under the terms of the LGPL license      *
6    * a copy of which has been included with this distribution in the license.txt file.  *
7    **************************************************************************************/
8   package test.rtti;
9   
10  import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
11  import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
12  
13  /***
14   * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
15   */
16  public class RttiTarget {
17  
18      public static StringBuffer LOG = new StringBuffer();
19  
20      private static int COUNT = 0;
21  
22      private static boolean NESTED = false;
23  
24      private final int m_id = ++COUNT;
25  
26      public void doSomething(int i) {
27          LOG.append(toString()).append(".").append(i).append(" ");
28          if (!NESTED) {
29              NESTED = true;
30              RttiTarget nested = new RttiTarget();
31              nested.doSomething(i+1);
32          }
33      }
34  
35      public String toString() {
36          return "Target-" + m_id;
37      }
38  
39      /***
40       * This aspect within the target class allows testing of non side effect at system init time
41       */
42      public static class TestAspect {
43  
44          /***
45           * This field of type the target class allows testing of non side effect at system init time
46           */
47          public static RttiTarget ASPECT_Rtti_TARGET_EXECUTING_INSTANCE;
48  
49          /***
50           * This method using the type of the target class allows testing of non side effect at system init time
51           *
52           * NOT SUPPORTED IN 1.0
53           */
54          //public Target fake(Target target) {return null;}
55  
56          /***
57           * @Around execution(* test.rtti.RttiTarget.doSomething(int))
58           *
59           * @param jp
60           * @return
61           * @throws Throwable
62           */
63          public Object around(JoinPoint jp) throws Throwable {
64              Object target = jp.getTarget();
65              int arg0 = ((Integer)(((MethodRtti)jp.getRtti()).getParameterValues()[0])).intValue();
66              LOG.append("+").append(target.toString()).append(".").append(arg0).append(" ");
67  
68              Object ret = jp.proceed();
69  
70              Object targetAfter = jp.getTarget();
71              int arg0After = ((Integer)(((MethodRtti)jp.getRtti()).getParameterValues()[0])).intValue();
72              LOG.append("-").append(targetAfter.toString()).append(".").append(arg0After).append(" ");
73  
74              return ret;
75          }
76      }
77  
78  }
79