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.CallerSideAdviceTest;
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 CallerSideTestAspect {
019: // ============ Pointcuts ============
020:
021: /**
022: * @Expression call(String test.CallerSideTestHelper.invokeMemberMethodPre()) &&
023: * within(test.CallerSideAdviceTest)
024: */
025: Pointcut pc1;
026:
027: /**
028: * @Expression call(String test.CallerSideTestHelper.invokeMemberMethodPost()) &&
029: * within(test.CallerSideAdviceTest)
030: */
031: Pointcut pc2;
032:
033: /**
034: * @Expression call(String test.CallerSideTestHelper.invokeMemberMethodPrePost()) &&
035: * withincode(* test.CallerSideAdviceTest.test*(..))
036: */
037: Pointcut pc3;
038:
039: /**
040: * @Expression call(String test.CallerSideTestHelper.invokeStaticMethodPre()) &&
041: * within(test.CallerSideAdviceTest)
042: */
043: Pointcut pc4;
044:
045: /**
046: * @Expression call(String test.CallerSideTestHelper.invokeStaticMethodPost()) &&
047: * within(test.CallerSideAdviceTest)
048: */
049: Pointcut pc5;
050:
051: /**
052: * @Expression call(String test.CallerSideTestHelper.invokeStaticMethodPrePost()) &&
053: * withincode(* test.CallerSideAdviceTest.test*(..))
054: */
055: Pointcut pc6;
056:
057: /**
058: * @Expression call(* test.CallerSideTestHelper.invokeMemberMethodAround*(..)) &&
059: * within(test.CallerSideAdviceTest)
060: */
061: Pointcut pc7;
062:
063: /**
064: * @Expression call(* test.CallerSideTestHelper.invokeStaticMethodAround*()) && withincode(*
065: * test.CallerSideAdviceTest.test*(..))
066: */
067: Pointcut pc8;
068:
069: // ============ Advices ============
070:
071: /**
072: * @Before pc1 || pc3 || pc4 || pc6
073: */
074: public void preAdvice1(final JoinPoint joinPoint) throws Throwable {
075: CallerSideAdviceTest.log("pre1 ");
076: }
077:
078: /**
079: * @Before pc1 || pc3 || pc4 || pc6
080: */
081: public void preAdvice2(final JoinPoint joinPoint) throws Throwable {
082: CallerSideAdviceTest.log("pre2 ");
083: }
084:
085: /**
086: * @After pc2 || pc3 || pc5 || pc6
087: */
088: public void postAdvice1(final JoinPoint joinPoint) throws Throwable {
089: CallerSideAdviceTest.log("post1 ");
090: }
091:
092: /**
093: * @After pc2 || pc3 || pc5 || pc6
094: */
095: public void postAdvice2(final JoinPoint joinPoint) throws Throwable {
096: CallerSideAdviceTest.log("post2 ");
097: }
098:
099: /**
100: * @Around pc8 || pc7
101: */
102: public Object around(final JoinPoint joinPoint) throws Throwable {
103: CallerSideAdviceTest.log("before ");
104: Object result = joinPoint.proceed();
105: CallerSideAdviceTest.log("after ");
106: return result;
107: }
108: }
|