001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package samples.tracing;
008:
009: import org.codehaus.aspectwerkz.definition.Pointcut;
010: import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint;
011: import org.codehaus.aspectwerkz.joinpoint.MemberSignature;
012:
013: /**
014: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
015: */
016: public class TracingAspect {
017:
018: private int m_level = 0;
019:
020: public Object logMethod(StaticJoinPoint joinPoint) throws Throwable {
021: MemberSignature signature = (MemberSignature) joinPoint
022: .getSignature();
023: indent();
024: System.out.println("--> "
025: + joinPoint.getCalleeClass().getName() + "::"
026: + signature.getName());
027: m_level++;
028: final Object result = joinPoint.proceed();
029: m_level--;
030: indent();
031: System.out.println("<-- "
032: + joinPoint.getCalleeClass().getName() + "::"
033: + signature.getName());
034: return result;
035: }
036:
037: public void logBeforeArgs(final StaticJoinPoint joinPoint,
038: Trace.Target t, Trace.Target arg) throws Throwable {
039: System.out.println("BEFORE: ARGS: I am [" + t
040: + "] and args is [" + arg + "]");
041: }
042:
043: public void logBefore(final StaticJoinPoint joinPoint)
044: throws Throwable {
045: MemberSignature signature = (MemberSignature) joinPoint
046: .getSignature();
047: System.out.println("BEFORE: "
048: + joinPoint.getCalleeClass().getName() + "::"
049: + signature.getName());
050: }
051:
052: public void logAfterReturning(final StaticJoinPoint joinPoint)
053: throws Throwable {
054: MemberSignature signature = (MemberSignature) joinPoint
055: .getSignature();
056: System.out.println("AFTER RETURNING: "
057: + joinPoint.getCalleeClass().getName() + "::"
058: + signature.getName());
059: }
060:
061: public void logAfterThrowingRE(final StaticJoinPoint joinPoint)
062: throws Throwable {
063: MemberSignature signature = (MemberSignature) joinPoint
064: .getSignature();
065: System.out.println("AFTER THROWING RE: "
066: + joinPoint.getCalleeClass().getName() + "::"
067: + signature.getName());
068: }
069:
070: public void logAfterThrowingIAE(final StaticJoinPoint joinPoint)
071: throws Throwable {
072: MemberSignature signature = (MemberSignature) joinPoint
073: .getSignature();
074: System.out.println("AFTER THROWING IAE: "
075: + joinPoint.getCalleeClass().getName() + "::"
076: + signature.getName());
077: }
078:
079: public void logAfter(final StaticJoinPoint joinPoint)
080: throws Throwable {
081: MemberSignature signature = (MemberSignature) joinPoint
082: .getSignature();
083: System.out.println("AFTER: "
084: + joinPoint.getCalleeClass().getName() + "::"
085: + signature.getName());
086: }
087:
088: private void indent() {
089: for (int i = 0; i < m_level; i++) {
090: System.out.print(" ");
091: }
092: }
093:
094: /**
095: * @Expression execution(* examples.logging.Target.toLog*(..))
096: */
097: Pointcut methodsToLog() {
098: return null;
099: };
100: }
|