1   /***************************************************************************************
2    * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved.                 *
3    * http://aspectwerkz.codehaus.org                                                    *
4    * ---------------------------------------------------------------------------------- *
5    * The software in this package is published under the terms of the LGPL license      *
6    * a copy of which has been included with this distribution in the license.txt file.  *
7    **************************************************************************************/
8   package test.aspect;
9   
10  import test.Loggable;
11  import org.codehaus.aspectwerkz.Pointcut;
12  import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
13  
14  /***
15   * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
16   * @Aspect perJVM
17   * @TODO: need nested pointcuts, need to be able to specify one singe pointcut name for the advice
18   *        to be able to easily refer to it when modifying the advices at runtime. this the handle is
19   *        the pointcut expression bound to the advice and this handle then need to be simplified
20   *        (one single name that can be reused).
21   */
22  public class DynamicDeploymentTestAspect {
23      // ============ Pointcuts ============
24  
25      /***
26       * @Expression execution(void test.DynamicDeploymentTest.reorderAdvicesTestMethod())
27       */
28      Pointcut pc1;
29  
30      /***
31       * @Expression execution(void test.DynamicDeploymentTest.removeAdviceTestMethod())
32       */
33      Pointcut pc2;
34  
35      /***
36       * @Expression execution(void test.DynamicDeploymentTest.addAdviceTestMethod())
37       */
38      Pointcut pc3;
39  
40      /***
41       * @Expression execution(void test.DynamicDeploymentTest.createAspectTestMethod())
42       */
43      Pointcut pc4;
44  
45      // ============ Advices ============
46  
47      /***
48       * @Around pc1 || pc2 || pc3
49       */
50      public Object advice1(final JoinPoint joinPoint) throws Throwable {
51          ((Loggable) joinPoint.getTarget()).log("before1 ");
52          final Object result = joinPoint.proceed();
53          ((Loggable) joinPoint.getTarget()).log("after1 ");
54          return result;
55      }
56  
57      /***
58       * @Around pc1 || pc2 || pc4
59       */
60      public Object advice2(final JoinPoint joinPoint) throws Throwable {
61          ((Loggable) joinPoint.getTarget()).log("before2 ");
62          final Object result = joinPoint.proceed();
63          ((Loggable) joinPoint.getTarget()).log("after2 ");
64          return result;
65      }
66  }