KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > rtti > RttiTarget


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 import org.codehaus.aspectwerkz.joinpoint.Rtti;
13
14 /**
15  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur</a>
16  */

17 public class RttiTarget {
18
19     public static StringBuffer JavaDoc LOG = new StringBuffer JavaDoc();
20
21     private static int COUNT = 0;
22
23     private static boolean NESTED = false;
24
25     private final int m_id = ++COUNT;
26
27     public void doSomething(int i) {
28         LOG.append(toString()).append(".").append(i).append(" ");
29         if (!NESTED) {
30             NESTED = true;
31             RttiTarget nested = new RttiTarget();
32             nested.doSomething(i + 1);
33         }
34     }
35
36     public String JavaDoc toString() {
37         return "Target-" + m_id;
38     }
39
40     /**
41      * This aspect within the target class allows testing of non side effect at system init time
42      */

43     public static class TestAspect {
44
45         /**
46          * This field of type the target class allows testing of non side effect at system init time
47          */

48         public static RttiTarget ASPECT_Rtti_TARGET_EXECUTING_INSTANCE;
49
50         /**
51          * This method using the type of the target class allows testing of non side effect at system init time
52          *
53          * NOT SUPPORTED IN 1.0
54          */

55         //public Target fake(Target target) {return null;}
56

57         /**
58          * @param jp
59          * @return
60          * @throws Throwable
61          * @Around execution(* test.rtti.RttiTarget.doSomething(int))
62          */

63         public Object JavaDoc around(JoinPoint jp) throws Throwable JavaDoc {
64             Object JavaDoc target = jp.getTarget();
65             int arg0 = ((Integer JavaDoc) (((MethodRtti) jp.getRtti()).getParameterValues()[0])).intValue();
66             LOG.append("+").append(target.toString()).append(".").append(arg0).append(" ");
67
68             Object JavaDoc ret = jp.proceed();
69
70             Object JavaDoc targetAfter = jp.getTarget();
71             int arg0After = ((Integer JavaDoc) (((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
80
Popular Tags