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.mixindeployment;
9   
10  import org.codehaus.aspectwerkz.CrossCuttingInfo;
11  
12  /***
13   * The aspect mixin is deployed as perInstance
14   * 
15   * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
16   * @Aspect perJVM
17   */
18  public class IntroductionDeploymentAspect {
19      /***
20       * Set to parse
21       * 
22       * @Introduce within(test.mixindeployment.IntroductionDeploymentTest$TargetA) ||
23       *            within(test.mixindeployment.IntroductionDeploymentTest$TargetB)
24       *            deploymentModel=perInstance
25       */
26      public static class MarkerImpl implements Marker {
27          /***
28           * The cross-cutting info.
29           */
30          private final CrossCuttingInfo m_info;
31  
32          /***
33           * We are interested in cross-cutting info, therefore we have added a constructor that takes
34           * a cross-cutting infor instance as its only parameter.
35           * 
36           * @param info the cross-cutting info
37           */
38          public MarkerImpl(final CrossCuttingInfo info) {
39              m_info = info;
40          }
41  
42          public Object getTargetInstance() {
43              return m_info.getMixinTargetInstance(this.getClass().getName(), this);
44          }
45  
46          public Class getTargetClass() {
47              return m_info.getMixinTargetClass(this.getClass().getName(), this);
48          }
49      }
50  
51      /***
52       * Note: explicit within(..) pointcut is needed
53       * 
54       * @Introduce within(test.mixindeployment.IntroductionDeploymentTest$TargetC)
55       *            deploymentModel=perClass
56       */
57      public static class AnotherMarkerImpl implements Marker {
58          /***
59           * The cross-cutting info.
60           */
61          private final CrossCuttingInfo m_info;
62  
63          /***
64           * We are interested in cross-cutting info, therefore we have added a constructor that takes
65           * a cross-cutting infor instance as its only parameter.
66           * 
67           * @param info the cross-cutting info
68           */
69          public AnotherMarkerImpl(final CrossCuttingInfo info) {
70              m_info = info;
71          }
72  
73          public Object getTargetInstance() {
74              // will return null
75              return m_info.getMixinTargetInstance(this.getClass().getName(), this);
76          }
77  
78          public Class getTargetClass() {
79              return m_info.getMixinTargetClass(this.getClass().getName(), this);
80          }
81      }
82  
83      /***
84       * Note: will fail with a StackOverflow if perInstance - due to hashCode use to fetch mixin impl.
85       * @Introduce within(test.mixindeployment.IntroductionDeploymentTest$TargetD)
86       *            deploymentModel=perClass
87       */
88      public static class HashcodeImpl implements Hashcode {
89          public int hashCode() {
90              return 2;
91          }
92      }
93  }