KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > aspect > AdviceInfo


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.aspect;
5
6 import com.tc.asm.Type;
7
8 import com.tc.aspectwerkz.DeploymentModel;
9 import com.tc.aspectwerkz.expression.ExpressionInfo;
10 import com.tc.aspectwerkz.expression.ExpressionContext;
11 import com.tc.aspectwerkz.definition.AdviceDefinition;
12 import com.tc.aspectwerkz.transform.inlining.AsmHelper;
13
14 import java.io.Serializable JavaDoc;
15
16 /**
17  * Contains advice info, like indexes describing the aspect and a method (advice or introduced),
18  * aspect manager etc.
19  *
20  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
21  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur </a>
22  */

23 public class AdviceInfo implements Serializable JavaDoc {
24
25   public final static AdviceInfo[] EMPTY_ADVICE_INFO_ARRAY = new AdviceInfo[0];
26
27   // -- some magic index used in the m_methodToArgIndexes[] so that we know what to bind except advised target args
28
// -- those constants MUST be negative since positive values are used for args(..) binding
29
public final static int JOINPOINT_ARG = -0x1;
30   public final static int STATIC_JOINPOINT_ARG = -0x2;
31   public final static int TARGET_ARG = -0x3;
32   public final static int THIS_ARG = -0x4;
33   public final static int VALID_NON_AW_AROUND_CLOSURE_TYPE = -0x5;
34   public final static int SPECIAL_ARGUMENT = -0x6;
35   public static final int CUSTOM_JOIN_POINT_ARG = -0x7;
36
37   /**
38    * The method name.
39    */

40   private String JavaDoc m_methodName;
41
42   /**
43    * The method sig.
44    */

45   private String JavaDoc m_methodSignature;
46
47   /**
48    * The method's parameter types.
49    */

50   private Type[] m_methodParameterTypes;
51
52   /**
53    * The advice name
54    * <adviceMethodName>[(... call signature)]
55    */

56   private final String JavaDoc m_name;
57
58   /**
59    * The aspect class name where this advice is defined.
60    */

61   private String JavaDoc m_aspectClassName;
62
63   /**
64    * The aspect qualified name - <uuid>/<aspectNickName or FQNclassName>
65    */

66   private String JavaDoc m_aspectQualifiedName;
67
68   /**
69    * The aspect deployment model
70    */

71   private DeploymentModel m_aspectDeploymentModel;
72
73   /**
74    * The advice method arg index mapped to the advisED target arg index.
75    * If the value is greater or equal to 0, it is an args binding. Else, it is a magic index
76    * (see constants JOINPOINT_ARG, STATIC_JOINPOINT_ARG, THIS_ARG, TARGET_ARG)
77    */

78   private int[] m_methodToArgIndexes;
79
80   /**
81    * The "special" argument type desc for the advice.
82    */

83   private String JavaDoc m_specialArgumentTypeDesc;
84
85   /**
86    * The "special" argument type name for the advice.
87    */

88   private String JavaDoc m_specialArgumentTypeName;
89
90   /**
91    * The advice type.
92    */

93   private AdviceType m_type;
94
95   /**
96    * Runtime check flag.
97    */

98   private boolean m_targetWithRuntimeCheck;
99
100   /**
101    * The expression info.
102    */

103   private ExpressionInfo m_expressionInfo;
104
105   /**
106    * The expression context.
107    */

108   private ExpressionContext m_expressionContext;
109
110   /**
111    * The advice definition for this advice.
112    */

113   private AdviceDefinition m_adviceDef;
114
115   /**
116    * TODO refactor - many member fields holds data that is in either the adviceDef (which is in the class) or the aspectDef (which is accessible from the adviceDef)
117    * <p/>
118    * Creates a new advice info.
119    *
120    * @param aspectQualifiedName
121    * @param aspectClassName
122    * @param aspectDeploymentModel
123    * @param methodName
124    * @param methodSignature
125    * @param methodParameterTypes
126    * @param type the advice type
127    * @param specialArgumentType the special arg type
128    * @param adviceName full qualified advice method name (aspectFQN/advice(call sig))
129    * @param targetWithRuntimeCheck true if a runtime check is needed based on target instance
130    * @param expressionInfo
131    * @param expressionContext
132    * @param adviceDef
133    */

134   public AdviceInfo(final String JavaDoc aspectQualifiedName,
135                     final String JavaDoc aspectClassName,
136                     final DeploymentModel aspectDeploymentModel,
137                     final String JavaDoc methodName,
138                     final String JavaDoc methodSignature,
139                     final Type[] methodParameterTypes,
140                     final AdviceType type,
141                     final String JavaDoc specialArgumentType,
142                     final String JavaDoc adviceName,
143                     final boolean targetWithRuntimeCheck,
144                     final ExpressionInfo expressionInfo,
145                     final ExpressionContext expressionContext,
146                     final AdviceDefinition adviceDef) {
147     m_aspectQualifiedName = aspectQualifiedName;
148     m_aspectClassName = aspectClassName;
149     m_aspectDeploymentModel = aspectDeploymentModel;
150     m_methodName = methodName;
151     m_methodSignature = methodSignature;
152     m_methodParameterTypes = methodParameterTypes;
153     m_type = type;
154     if (specialArgumentType != null && specialArgumentType.length() > 0) {//AW-434
155
m_specialArgumentTypeDesc = AsmHelper.convertReflectDescToTypeDesc(specialArgumentType);
156       m_specialArgumentTypeName = specialArgumentType.replace('.', '/');
157     }
158     m_name = adviceName;
159     m_targetWithRuntimeCheck = targetWithRuntimeCheck;
160     m_expressionInfo = expressionInfo;
161     m_expressionContext = expressionContext;
162     m_adviceDef = adviceDef;
163   }
164
165   /**
166    * Return the method name.
167    *
168    * @return the method name
169    */

170   public String JavaDoc getMethodName() {
171     return m_methodName;
172   }
173
174   /**
175    * Return the method signature.
176    *
177    * @return the method signature
178    */

179   public String JavaDoc getMethodSignature() {
180     return m_methodSignature;
181   }
182
183   /**
184    * Return the method name.
185    *
186    * @return the method name
187    */

188   public Type[] getMethodParameterTypes() {
189     return m_methodParameterTypes;
190   }
191
192   /**
193    * Returns the aspect qualified name.
194    *
195    * @return the aspect qualified name
196    */

197   public String JavaDoc getAspectQualifiedName() {
198     return m_aspectQualifiedName;
199   }
200
201   /**
202    * Returns the aspect FQN className.
203    *
204    * @return the aspect class name
205    */

206   public String JavaDoc getAspectClassName() {
207     return m_aspectClassName;
208   }
209
210   /**
211    * Returns the aspect deployment model
212    *
213    * @return
214    */

215   public DeploymentModel getAspectDeploymentModel() {
216     return m_aspectDeploymentModel;
217   }
218
219   /**
220    * Returns the name of the advice.
221    *
222    * @return
223    */

224   public String JavaDoc getName() {
225     return m_name;
226   }
227
228   /**
229    * Sets the advice method to target method arg mapping A value of -1 means "not mapped"
230    *
231    * @param map
232    */

233   public void setMethodToArgIndexes(final int[] map) {
234     m_methodToArgIndexes = map;
235   }
236
237   /**
238    * Returns the advice method to target method arg index mapping.
239    *
240    * @return the indexes
241    */

242   public int[] getMethodToArgIndexes() {
243     return m_methodToArgIndexes;
244   }
245
246   /**
247    * Returns the special argument type desc.
248    *
249    * @return
250    */

251   public String JavaDoc getSpecialArgumentTypeDesc() {
252     return m_specialArgumentTypeDesc;
253   }
254
255   /**
256    * Returns the special argument type name.
257    *
258    * @return
259    */

260   public String JavaDoc getSpecialArgumentTypeName() {
261     return m_specialArgumentTypeName;
262   }
263
264   /**
265    * Returns the advice type.
266    *
267    * @return
268    */

269   public AdviceType getType() {
270     return m_type;
271   }
272
273   /**
274    * Checks if the target has a runtime check.
275    *
276    * @return
277    */

278   public boolean hasTargetWithRuntimeCheck() {
279     return m_targetWithRuntimeCheck;
280   }
281
282   /**
283    * Returns the expression info.
284    *
285    * @return
286    */

287   public ExpressionInfo getExpressionInfo() {
288     return m_expressionInfo;
289   }
290
291   /**
292    * Returns the expression context.
293    *
294    * @return
295    */

296   public ExpressionContext getExpressionContext() {
297     return m_expressionContext;
298   }
299
300   /**
301    * Returns the advice definition.
302    *
303    * @return
304    */

305   public AdviceDefinition getAdviceDefinition() {
306     return m_adviceDef;
307   }
308
309   public String JavaDoc toString() {
310     StringBuffer JavaDoc sb = new StringBuffer JavaDoc("AdviceInfo[");
311     sb.append(m_type).append(',');
312     sb.append(m_aspectQualifiedName).append(',');
313     sb.append(m_name).append(',');
314     sb.append(m_methodName).append(',');
315     sb.append(m_methodSignature).append(',');
316     sb.append(m_methodParameterTypes).append(',');
317     sb.append(m_specialArgumentTypeDesc).append(',');
318     sb.append(m_expressionInfo).append(',');
319     sb.append(m_expressionContext).append(',');
320     sb.append(m_targetWithRuntimeCheck).append(']');
321     sb.append(hashCode());
322     return sb.toString();
323   }
324
325 }
Popular Tags