KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > transform > inlining > spi > AspectModel


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.transform.inlining.spi;
5
6 import com.tc.asm.ClassWriter;
7 import com.tc.asm.MethodVisitor;
8 import com.tc.asm.Type;
9 import com.tc.asm.ClassVisitor;
10
11 import com.tc.aspectwerkz.definition.AspectDefinition;
12 import com.tc.aspectwerkz.transform.JoinPointCompiler;
13 import com.tc.aspectwerkz.transform.inlining.AdviceMethodInfo;
14 import com.tc.aspectwerkz.transform.inlining.AspectInfo;
15 import com.tc.aspectwerkz.transform.inlining.compiler.CompilationInfo;
16 import com.tc.aspectwerkz.transform.inlining.compiler.CompilerInput;
17 import com.tc.aspectwerkz.reflect.ClassInfo;
18
19 /**
20  * An aspect model defines a custom hook for the JoinPointCompiler.
21  * <p/>
22  * The AspectModel is registered using AspectModelManager, and the AspectDefinition is linked to the model
23  * "getAspectModelType()" unique identifier.
24  * <p/>
25  * An no arg constructor instance of the model will be callback during aspect registration for defineAspect(..)
26  * </p>
27  * During compilation, different aspect model instance can be instantiated per compilation using the getInstance(..)
28  * method (not returning "this").
29  *
30  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
31  * @author <a HREF="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
32  */

33 public interface AspectModel {
34
35   /**
36    * A prototype patttern. Ones may return "this" if singleton / non thread safe instance is enough.
37    *
38    * @param compilationModel
39    * @return
40    */

41   AspectModel getInstance(CompilationInfo.Model compilationModel);
42
43   /**
44    * Returns the aspect model type, which is an id for the the special aspect model, can be anything as long
45    * as it is unique.
46    *
47    * @return the aspect model type id
48    */

49   String JavaDoc getAspectModelType();
50
51   /**
52    * Defines the aspect and adds definition to the aspect definition.
53    *
54    * @param aspectClassInfo
55    * @param aspectDef
56    * @param loader
57    */

58   void defineAspect(ClassInfo aspectClassInfo, AspectDefinition aspectDef, ClassLoader JavaDoc loader);
59
60   /**
61    * Returns info about the closure class, name and type (interface or class).
62    *
63    * @return the closure class info
64    */

65   AroundClosureClassInfo getAroundClosureClassInfo();
66
67   /**
68    * Creates the methods required to implement or extend to implement the closure for the specific aspect model type.
69    *
70    * @param cw
71    * @param compiler
72    */

73   void createMandatoryMethods(ClassWriter cw, JoinPointCompiler compiler);
74
75   /**
76    * Creates invocation of the super class for the around closure.
77    * <p/>
78    * E.g. the invocation of super(..) in the constructor.
79    * <p/>
80    * Only needed to be implemented if the around closure base class is really a base class and not an interface.
81    *
82    * @param cv
83    */

84   void createInvocationOfAroundClosureSuperClass(MethodVisitor cv);
85
86   /**
87    * Creates aspect reference field (field in the jit jointpoint class f.e.) for an aspect instance.
88    * Creates instantiation of an aspect instance and stores them if appropriate (see createAspectReferenceField).
89    *
90    * @param cw for the jp class beeing compiled
91    * @param cv for the <clinit> method
92    * @param aspectInfo
93    * @param joinPointClassName
94    */

95   void createAndStoreStaticAspectInstantiation(ClassVisitor cw, MethodVisitor cv, AspectInfo aspectInfo, String JavaDoc joinPointClassName);
96
97   /**
98    * Initializes instance level aspects, retrieves them from the target instance through the
99    * <code>HasInstanceLevelAspect</code> interfaces.
100    * <p/>
101    * Use by 'perInstance', 'perThis' and 'perTarget' deployment models.
102    *
103    * @param cv
104    * @param input
105    * @param aspectInfo
106    */

107   void createAndStoreRuntimeAspectInstantiation(final MethodVisitor cv,
108                                                 final CompilerInput input,
109                                                 final AspectInfo aspectInfo);
110
111   /**
112    * Loads the aspect instance on stack.
113    * See loadJoinPointInstance(..) and
114    *
115    * @param cv
116    * @param aspectInfo
117    */

118   void loadAspect(final MethodVisitor cv,
119                   final CompilerInput input,
120                   final AspectInfo aspectInfo);
121
122   /**
123    * Handles the arguments to the around advice.
124    *
125    * @param cv
126    * @param adviceMethodInfo
127    */

128   void createAroundAdviceArgumentHandling(MethodVisitor cv,
129                                           CompilerInput input,
130                                           Type[] joinPointArgumentTypes,
131                                           AdviceMethodInfo adviceMethodInfo);
132
133   /**
134    * Handles the arguments to the before or after (after XXX) advice.
135    *
136    * @param cv
137    * @param input
138    * @param joinPointArgumentTypes
139    * @param adviceMethodInfo
140    * @param specialArgIndex index on the stack of the throwned exception / returned value (makes sense for after advice,
141    * else set to INDEX_NOTAVAILABLE)
142    */

143   public void createBeforeOrAfterAdviceArgumentHandling(MethodVisitor cv,
144                                                         CompilerInput input,
145                                                         Type[] joinPointArgumentTypes,
146                                                         AdviceMethodInfo adviceMethodInfo,
147                                                         int specialArgIndex);
148
149   /**
150    * Should return true if the aspect model requires that Runtime Type Information (RTTI) is build up
151    * for the join point. Needed for reflective systems and systems that does not support f.e. args() binding.
152    *
153    * @return
154    */

155   boolean requiresReflectiveInfo();
156
157   /**
158    * Info about the around closure class or interface for this specific aspect model.
159    *
160    * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
161    */

162   public static class AroundClosureClassInfo {
163
164     private final String JavaDoc m_superClassName;
165
166     private final String JavaDoc[] m_interfaceNames;
167
168     public AroundClosureClassInfo(final String JavaDoc superClassName, final String JavaDoc[] interfaceNames) {
169       if (superClassName != null) {
170         m_superClassName = superClassName.replace('.', '/');
171       } else {
172         m_superClassName = null;
173       }
174       m_interfaceNames = new String JavaDoc[interfaceNames.length];
175       for (int i = 0; i < interfaceNames.length; i++) {
176         m_interfaceNames[i] = interfaceNames[i].replace('.', '/');
177       }
178     }
179
180     public String JavaDoc getSuperClassName() {
181       return m_superClassName;
182     }
183
184     public String JavaDoc[] getInterfaceNames() {
185       return m_interfaceNames;
186     }
187
188     /**
189      * Type safe enum for the around closure class type.
190      */

191     public static class Type {
192       public static final Type INTERFACE = new Type("INTERFACE");
193       public static final Type CLASS = new Type("CLASS");
194       private final String JavaDoc m_name;
195
196       private Type(String JavaDoc name) {
197         m_name = name;
198       }
199
200       public String JavaDoc toString() {
201         return m_name;
202       }
203     }
204
205   }
206 }
207
Popular Tags