1 8 package samples.tracing; 9 10 import org.codehaus.aspectwerkz.definition.Pointcut; 11 import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint; 12 import org.codehaus.aspectwerkz.joinpoint.MemberSignature; 13 14 17 public class TracingAspect { 18 19 private int m_level = 0; 20 21 public Object logMethod(StaticJoinPoint joinPoint) throws Throwable { 22 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 23 indent(); 24 System.out.println( 25 "--> " 26 + joinPoint.getCalleeClass().getName() 27 + "::" 28 + signature.getName() 29 ); 30 m_level++; 31 final Object result = joinPoint.proceed(); 32 m_level--; 33 indent(); 34 System.out.println( 35 "<-- " 36 + joinPoint.getCalleeClass().getName() 37 + "::" 38 + signature.getName() 39 ); 40 return result; 41 } 42 43 public void logBeforeArgs(final StaticJoinPoint joinPoint, Trace.Target t, Trace.Target arg) throws Throwable { 44 System.out.println("BEFORE: ARGS: I am [" + t + "] and args is [" + arg + "]") ; 45 } 46 public void logBefore(final StaticJoinPoint joinPoint) throws Throwable { 47 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 48 System.out.println( 49 "BEFORE: " 50 + joinPoint.getCalleeClass().getName() 51 + "::" 52 + signature.getName() 53 ); 54 } 55 56 public void logAfterReturning(final StaticJoinPoint joinPoint) throws Throwable { 57 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 58 System.out.println( 59 "AFTER RETURNING: " 60 + joinPoint.getCalleeClass().getName() 61 + "::" 62 + signature.getName() 63 ); 64 } 65 66 public void logAfterThrowingRE(final StaticJoinPoint joinPoint) throws Throwable { 67 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 68 System.out.println( 69 "AFTER THROWING RE: " 70 + joinPoint.getCalleeClass().getName() 71 + "::" 72 + signature.getName() 73 ); 74 } 75 76 public void logAfterThrowingIAE(final StaticJoinPoint joinPoint) throws Throwable { 77 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 78 System.out.println( 79 "AFTER THROWING IAE: " 80 + joinPoint.getCalleeClass().getName() 81 + "::" 82 + signature.getName() 83 ); 84 } 85 86 public void logAfter(final StaticJoinPoint joinPoint) throws Throwable { 87 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 88 System.out.println( 89 "AFTER: " 90 + joinPoint.getCalleeClass().getName() 91 + "::" 92 + signature.getName() 93 ); 94 } 95 96 private void indent() { 97 for (int i = 0; i < m_level; i++) { 98 System.out.print(" "); 99 } 100 } 101 102 105 Pointcut methodsToLog() { 106 return null; 107 }; 108 } | Popular Tags |