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 examples.proxy.tracing;
08:
09: import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint;
10: import org.codehaus.aspectwerkz.joinpoint.MemberSignature;
11:
12: /**
13: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
14: */
15: public class TracingAspect {
16:
17: private int m_level = 0;
18:
19: public Object logMethod(StaticJoinPoint joinPoint) throws Throwable {
20: MemberSignature signature = (MemberSignature) joinPoint
21: .getSignature();
22: indent();
23: System.out.println("--> "
24: + joinPoint.getCalleeClass().getName() + "::"
25: + signature.getName());
26: m_level++;
27: final Object result = joinPoint.proceed();
28: m_level--;
29: indent();
30: System.out.println("<-- "
31: + joinPoint.getCalleeClass().getName() + "::"
32: + signature.getName());
33: return result;
34: }
35:
36: public void logBefore(final StaticJoinPoint joinPoint)
37: throws Throwable {
38: MemberSignature signature = (MemberSignature) joinPoint
39: .getSignature();
40: System.out.println("BEFORE: "
41: + joinPoint.getCalleeClass().getName() + "::"
42: + signature.getName());
43: }
44:
45: public void logAfterReturning(final StaticJoinPoint joinPoint)
46: throws Throwable {
47: MemberSignature signature = (MemberSignature) joinPoint
48: .getSignature();
49: System.out.println("AFTER RETURNING: "
50: + joinPoint.getCalleeClass().getName() + "::"
51: + signature.getName());
52: }
53:
54: public void logAfterThrowingRE(final StaticJoinPoint joinPoint)
55: throws Throwable {
56: MemberSignature signature = (MemberSignature) joinPoint
57: .getSignature();
58: System.out.println("AFTER THROWING RE: "
59: + joinPoint.getCalleeClass().getName() + "::"
60: + signature.getName());
61: }
62:
63: public void logAfterThrowingIAE(final StaticJoinPoint joinPoint)
64: throws Throwable {
65: MemberSignature signature = (MemberSignature) joinPoint
66: .getSignature();
67: System.out.println("AFTER THROWING IAE: "
68: + joinPoint.getCalleeClass().getName() + "::"
69: + signature.getName());
70: }
71:
72: public void logAfter(final StaticJoinPoint joinPoint)
73: throws Throwable {
74: MemberSignature signature = (MemberSignature) joinPoint
75: .getSignature();
76: System.out.println("AFTER: "
77: + joinPoint.getCalleeClass().getName() + "::"
78: + signature.getName());
79: }
80:
81: private void indent() {
82: for (int i = 0; i < m_level; i++) {
83: System.out.print(" ");
84: }
85: }
86: }
|