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 test.aspect;
008:
009: import test.Loggable;
010: import org.codehaus.aspectwerkz.definition.Pointcut;
011: import org.codehaus.aspectwerkz.definition.Pointcut;
012: import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
013:
014: /**
015: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
016: * @Aspect perJVM
017: */
018: public class CFlowTestAspect {
019: // ============ Pointcuts ============
020:
021: /**
022: * @Expression cflow(call(* test.CFlowTest.step1()) AND within(test.CFlowTest))
023: */
024: Pointcut pc1;
025:
026: /**
027: * @Expression cflow(call(* test.CFlowTest.step1_A()) AND within(test.CFlowTest))
028: */
029: Pointcut pc1_A;
030:
031: /**
032: * @Expression cflow(call(* test.CFlowTest.step1_B()) AND within(test.CFlowTest))
033: */
034: Pointcut pc1_B;
035:
036: /**
037: * @Expression execution(* test.CFlowTest.step2())
038: */
039: Pointcut pc2;
040:
041: /**
042: * @Expression execution(* test.CFlowTest.step2_B())
043: */
044: Pointcut pc2_B;
045:
046: // ============ Advices ============
047:
048: /**
049: * @Around pc2 AND pc1
050: */
051: public Object execute(final JoinPoint joinPoint) throws Throwable {
052: ((Loggable) joinPoint.getTarget()).log("advice-before ");
053: final Object result = joinPoint.proceed();
054: ((Loggable) joinPoint.getTarget()).log("advice-after ");
055: return result;
056: }
057:
058: /**
059: * @Around pc2_B AND pc1_B AND pc1_A
060: */
061: public Object execute2(final JoinPoint joinPoint) throws Throwable {
062: ((Loggable) joinPoint.getTarget()).log("advice-before2 ");
063: final Object result = joinPoint.proceed();
064: ((Loggable) joinPoint.getTarget()).log("advice-after2 ");
065: return result;
066: }
067:
068: /**
069: * @Around execution(* test.CFlowTest.step2Anonymous()) AND cflow(call(*
070: * test.CFlowTest.step1Anonymous()) AND within(test.CFlowTest))
071: */
072: public Object executeAnonymous(final JoinPoint joinPoint)
073: throws Throwable {
074: ((Loggable) joinPoint.getTarget())
075: .log("advice-beforeAnonymous ");
076: final Object result = joinPoint.proceed();
077: ((Loggable) joinPoint.getTarget())
078: .log("advice-afterAnonymous ");
079: return result;
080: }
081:
082: /**
083: * FIXME: this expression leads to match all at cflow early filtering.
084: * <p/>
085: * X@Around execution(* test.CFlowTest.step2_C()) AND !cflow(call(* test.CFlowTest.step1_C()) AND
086: * within(test.CFlowTest))
087: */
088: public Object executeC(final JoinPoint joinPoint) throws Throwable {
089: ((Loggable) joinPoint.getTarget()).log("advice-beforeC ");
090: final Object result = joinPoint.proceed();
091: ((Loggable) joinPoint.getTarget()).log("advice-afterC ");
092: return result;
093: }
094:
095: /**
096: * @After execution(* test.CFlowTest.cflowOnMyself()) && cflow(execution(* test.CFlowTest.cflowOnMyself()))
097: */
098: public void afterMySelf(JoinPoint joinPoint) {
099: ((Loggable) joinPoint.getTarget()).log("advice-cflowOnMyself ");
100: }
101: }
|