KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > proxy > tracing > TracingAspect


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 examples.proxy.tracing;
9
10 import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint;
11 import org.codehaus.aspectwerkz.joinpoint.MemberSignature;
12
13 /**
14  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
15  */

16 public class TracingAspect {
17
18     private int m_level = 0;
19
20     public Object JavaDoc logMethod(StaticJoinPoint joinPoint) throws Throwable JavaDoc {
21         MemberSignature signature = (MemberSignature) joinPoint.getSignature();
22         indent();
23         System.out.println(
24                 "--> "
25                 + joinPoint.getCalleeClass().getName()
26                 + "::"
27                 + signature.getName()
28         );
29         m_level++;
30         final Object JavaDoc result = joinPoint.proceed();
31         m_level--;
32         indent();
33         System.out.println(
34                 "<-- "
35                 + joinPoint.getCalleeClass().getName()
36                 + "::"
37                 + signature.getName()
38         );
39         return result;
40     }
41
42     public void logBefore(final StaticJoinPoint joinPoint) throws Throwable JavaDoc {
43         MemberSignature signature = (MemberSignature) joinPoint.getSignature();
44         System.out.println(
45                 "BEFORE: "
46                 + joinPoint.getCalleeClass().getName()
47                 + "::"
48                 + signature.getName()
49         );
50     }
51
52     public void logAfterReturning(final StaticJoinPoint joinPoint) throws Throwable JavaDoc {
53         MemberSignature signature = (MemberSignature) joinPoint.getSignature();
54         System.out.println(
55                 "AFTER RETURNING: "
56                 + joinPoint.getCalleeClass().getName()
57                 + "::"
58                 + signature.getName()
59         );
60     }
61
62     public void logAfterThrowingRE(final StaticJoinPoint joinPoint) throws Throwable JavaDoc {
63         MemberSignature signature = (MemberSignature) joinPoint.getSignature();
64         System.out.println(
65                 "AFTER THROWING RE: "
66                 + joinPoint.getCalleeClass().getName()
67                 + "::"
68                 + signature.getName()
69         );
70     }
71
72     public void logAfterThrowingIAE(final StaticJoinPoint joinPoint) throws Throwable JavaDoc {
73         MemberSignature signature = (MemberSignature) joinPoint.getSignature();
74         System.out.println(
75                 "AFTER THROWING IAE: "
76                 + joinPoint.getCalleeClass().getName()
77                 + "::"
78                 + signature.getName()
79         );
80     }
81
82     public void logAfter(final StaticJoinPoint joinPoint) throws Throwable JavaDoc {
83         MemberSignature signature = (MemberSignature) joinPoint.getSignature();
84         System.out.println(
85                 "AFTER: "
86                 + joinPoint.getCalleeClass().getName()
87                 + "::"
88                 + signature.getName()
89         );
90     }
91
92     private void indent() {
93         for (int i = 0; i < m_level; i++) {
94             System.out.print(" ");
95         }
96     }
97 }
Popular Tags