1 8 package examples.logging; 9 10 import org.codehaus.aspectwerkz.joinpoint.JoinPoint; 11 import org.codehaus.aspectwerkz.joinpoint.MemberSignature; 12 13 16 public class XmlDefLoggingAspect { 17 18 private int m_level = 0; 19 20 public Object logMethod(JoinPoint joinPoint) throws Throwable { 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 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 JoinPoint joinPoint) throws Throwable { 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 JoinPoint joinPoint) throws Throwable { 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 JoinPoint joinPoint) throws Throwable { 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 JoinPoint joinPoint) throws Throwable { 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 logAfterFinally(final JoinPoint joinPoint) throws Throwable { 83 MemberSignature signature = (MemberSignature) joinPoint.getSignature(); 84 System.out.println( 85 "AFTER FINALLY: " 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 |