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.logging;
08:
09: import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
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 XmlDefLoggingAspect {
16:
17: private int m_level = 0;
18:
19: public Object logMethod(JoinPoint 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 JoinPoint joinPoint) throws Throwable {
37: MemberSignature signature = (MemberSignature) joinPoint
38: .getSignature();
39: System.out.println("BEFORE: "
40: + joinPoint.getCalleeClass().getName() + "::"
41: + signature.getName());
42: }
43:
44: public void logAfterReturning(final JoinPoint joinPoint)
45: throws Throwable {
46: MemberSignature signature = (MemberSignature) joinPoint
47: .getSignature();
48: System.out.println("AFTER RETURNING: "
49: + joinPoint.getCalleeClass().getName() + "::"
50: + signature.getName());
51: }
52:
53: public void logAfterThrowingRE(final JoinPoint joinPoint)
54: throws Throwable {
55: MemberSignature signature = (MemberSignature) joinPoint
56: .getSignature();
57: System.out.println("AFTER THROWING RE: "
58: + joinPoint.getCalleeClass().getName() + "::"
59: + signature.getName());
60: }
61:
62: public void logAfterThrowingIAE(final JoinPoint joinPoint)
63: throws Throwable {
64: MemberSignature signature = (MemberSignature) joinPoint
65: .getSignature();
66: System.out.println("AFTER THROWING IAE: "
67: + joinPoint.getCalleeClass().getName() + "::"
68: + signature.getName());
69: }
70:
71: public void logAfterFinally(final JoinPoint joinPoint)
72: throws Throwable {
73: MemberSignature signature = (MemberSignature) joinPoint
74: .getSignature();
75: System.out.println("AFTER FINALLY: "
76: + joinPoint.getCalleeClass().getName() + "::"
77: + signature.getName());
78: }
79:
80: private void indent() {
81: for (int i = 0; i < m_level; i++) {
82: System.out.print(" ");
83: }
84: }
85: }
|