01: /**************************************************************************************
02: * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package test.rtti;
08:
09: import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
10: import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
11: import org.codehaus.aspectwerkz.joinpoint.Rtti;
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: * @param jp
57: * @return
58: * @throws Throwable
59: * @Around execution(* test.rtti.RttiTarget.doSomething(int))
60: */
61: public Object around(JoinPoint jp) throws Throwable {
62: Object target = jp.getTarget();
63: int arg0 = ((Integer) (((MethodRtti) jp.getRtti())
64: .getParameterValues()[0])).intValue();
65: LOG.append("+").append(target.toString()).append(".")
66: .append(arg0).append(" ");
67:
68: Object ret = jp.proceed();
69:
70: Object targetAfter = jp.getTarget();
71: int arg0After = ((Integer) (((MethodRtti) jp.getRtti())
72: .getParameterValues()[0])).intValue();
73: LOG.append("-").append(targetAfter.toString()).append(".")
74: .append(arg0After).append(" ");
75:
76: return ret;
77: }
78: }
79:
80: }
|