1 8 package examples.logging; 9 10 import org.codehaus.aspectwerkz.joinpoint.MemberSignature; 11 import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint; 12 13 16 public abstract class AbstractLoggingAspect { 17 18 private int m_level = 0; 19 20 23 public Object logMethod(StaticJoinPoint joinPoint) throws Throwable { 24 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 25 indent(); 26 System.out.println( 27 "--> " 28 + joinPoint.getCalleeClass().getName() 29 + "::" 30 + signature.getName() 31 ); 32 m_level++; 33 final Object result = joinPoint.proceed(); 34 m_level--; 35 indent(); 36 System.out.println( 37 "<-- " 38 + joinPoint.getCalleeClass().getName() 39 + "::" 40 + signature.getName() 41 ); 42 return result; 43 } 44 45 48 public void logBefore(final StaticJoinPoint joinPoint) throws Throwable { 49 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 50 System.out.println( 51 "BEFORE: " 52 + joinPoint.getCalleeClass().getName() 53 + "::" 54 + signature.getName() 55 ); 56 } 57 58 61 public void logAfterReturning(final StaticJoinPoint joinPoint) throws Throwable { 62 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 63 System.out.println( 64 "AFTER RETURNING: " 65 + joinPoint.getCalleeClass().getName() 66 + "::" 67 + signature.getName() 68 ); 69 } 70 71 74 public void logAfterThrowingRE(final StaticJoinPoint joinPoint) throws Throwable { 75 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 76 System.out.println( 77 "AFTER THROWING RE: " 78 + joinPoint.getCalleeClass().getName() 79 + "::" 80 + signature.getName() 81 ); 82 } 83 84 87 public void logAfterThrowingIAE(final StaticJoinPoint joinPoint) throws Throwable { 88 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 89 System.out.println( 90 "AFTER THROWING IAE: " 91 + joinPoint.getCalleeClass().getName() 92 + "::" 93 + signature.getName() 94 ); 95 } 96 97 100 public void logAfterFinally(final StaticJoinPoint joinPoint) throws Throwable { 101 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 102 System.out.println( 103 "AFTER FINALLY: " 104 + joinPoint.getCalleeClass().getName() 105 + "::" 106 + signature.getName() 107 ); 108 } 109 110 private void indent() { 111 for (int i = 0; i < m_level; i++) { 112 System.out.print(" "); 113 } 114 } 115 } | Popular Tags |