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.definition.Pointcut;
12 import org.codehaus.aspectwerkz.definition.Pointcut;
13 import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
14
15 /***
16 * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
17 * @Aspect perJVM
18 * @TODO: need nested pointcuts, need to be able to specify one singe pointcut name for the advice
19 * to be able to easily refer to it when modifying the advices at runtime. this the handle is
20 * the pointcut expression bound to the advice and this handle then need to be simplified
21 * (one single name that can be reused).
22 */
23 public class DynamicDeploymentTestAspect {
24
25
26 /***
27 * @Expression execution(void test.DynamicDeploymentTest.reorderAdvicesTestMethod())
28 */
29 Pointcut pc1;
30
31 /***
32 * @Expression execution(void test.DynamicDeploymentTest.removeAdviceTestMethod())
33 */
34 Pointcut pc2;
35
36 /***
37 * @Expression execution(void test.DynamicDeploymentTest.addAdviceTestMethod())
38 */
39 Pointcut pc3;
40
41 /***
42 * @Expression execution(void test.DynamicDeploymentTest.createAspectTestMethod())
43 */
44 Pointcut pc4;
45
46
47
48 /***
49 * @Around pc1 || pc2 || pc3
50 */
51 public Object advice1(final JoinPoint joinPoint) throws Throwable {
52 ((Loggable) joinPoint.getTarget()).log("before1 ");
53 final Object result = joinPoint.proceed();
54 ((Loggable) joinPoint.getTarget()).log("after1 ");
55 return result;
56 }
57
58 /***
59 * @Around pc1 || pc2 || pc4
60 */
61 public Object advice2(final JoinPoint joinPoint) throws Throwable {
62 ((Loggable) joinPoint.getTarget()).log("before2 ");
63 final Object result = joinPoint.proceed();
64 ((Loggable) joinPoint.getTarget()).log("after2 ");
65 return result;
66 }
67 }