1 8 package org.codehaus.aspectwerkz.transform.aopalliance; 9 10 import org.codehaus.aspectwerkz.definition.AspectDefinition; 11 import org.codehaus.aspectwerkz.reflect.ClassInfo; 12 import org.codehaus.aspectwerkz.transform.inlining.spi.AspectModel; 13 import org.codehaus.aspectwerkz.transform.inlining.AdviceMethodInfo; 14 import org.codehaus.aspectwerkz.transform.inlining.AspectInfo; 15 import org.codehaus.aspectwerkz.transform.inlining.compiler.AbstractJoinPointCompiler; 16 import org.codehaus.aspectwerkz.transform.TransformationConstants; 17 18 import org.aopalliance.intercept.MethodInterceptor; 19 import org.aopalliance.intercept.ConstructorInterceptor; 20 21 import org.codehaus.aspectwerkz.org.objectweb.asm.CodeVisitor; 24 import org.codehaus.aspectwerkz.org.objectweb.asm.ClassWriter; 25 26 36 public class AopAllianceAspectModel implements AspectModel, TransformationConstants { 37 38 protected static final String ASPECT_MODEL_TYPE = "aop-alliance"; 39 protected static final String AOP_ALLIANCE_CLOSURE_CLASS_NAME = "org/aopalliance/intercept/MethodInvocation"; 40 protected static final String AOP_ALLIANCE_CLOSURE_PROCEED_METHOD_NAME = "invoke"; 41 protected static final String AOP_ALLIANCE_CLOSURE_PROCEED_METHOD_SIGNATURE = "(Lorg/aopalliance/intercept/MethodInvocation;)Ljava/lang/Object;"; 42 protected static final String ASPECT_CONTAINER_CLASS_NAME = AopAllianceAspectContainer.class.getName(); 43 protected static final String GET_METHOD_METHOD_NAME = "getMethod"; 44 protected static final String GET_METHOD_METHOD_SIGNATURE = "()Ljava/lang/reflect/Method;"; 45 protected static final String GET_STATIC_PART_METHOD_NAME = "getStaticPart"; 46 protected static final String GET_STATIC_PART_METHOD_SIGNATURE = "()Ljava/lang/reflect/AccessibleObject;"; 47 protected static final String GET_PARAMETER_VALUES_METHOD_NAME = "getParameterValues"; 48 protected static final String GET_ARGUMENTS_METHOD_SIGNATURE = "()[Ljava/lang/Object;"; 49 protected static final String GET_ARGUMENTS_METHOD_NAME = "getArguments"; 50 51 52 58 public String getAspectModelType() { 59 return ASPECT_MODEL_TYPE; 60 } 61 62 69 public void defineAspect(final ClassInfo classInfo, 70 final AspectDefinition aspectDef, 71 final ClassLoader loader) { 72 ClassInfo[] interfaces = classInfo.getInterfaces(); 73 for (int i = 0; i < interfaces.length; i++) { 74 ClassInfo anInterface = interfaces[i]; 75 if (anInterface.getName().equals(MethodInterceptor.class.getName()) || 76 anInterface.getName().equals(ConstructorInterceptor.class.getName())) { 77 aspectDef.setAspectModel(ASPECT_MODEL_TYPE); 78 aspectDef.setContainerClassName(ASPECT_CONTAINER_CLASS_NAME); 79 return; 80 } 81 } 82 } 83 84 89 public boolean requiresReflectiveInfo() { 90 return true; 91 } 92 93 98 public AroundClosureClassInfo getAroundClosureClassInfo() { 99 return new AspectModel.AroundClosureClassInfo(null, new String [] {AOP_ALLIANCE_CLOSURE_CLASS_NAME}); 100 } 101 102 103 110 public void createMandatoryMethods(final ClassWriter cw, final String className) { 111 CodeVisitor cv; 112 113 { 115 cv = cw.visitMethod( 116 ACC_PUBLIC, 117 AOP_ALLIANCE_CLOSURE_PROCEED_METHOD_NAME, 118 AOP_ALLIANCE_CLOSURE_PROCEED_METHOD_SIGNATURE, 119 new String []{THROWABLE_CLASS_NAME}, 120 null 121 ); 122 cv.visitVarInsn(ALOAD, 0); 123 cv.visitMethodInsn(INVOKEVIRTUAL, className, PROCEED_METHOD_NAME, PROCEED_METHOD_SIGNATURE); 124 cv.visitInsn(ARETURN); 125 cv.visitMaxs(0, 0); 126 } 127 128 { 130 cv = cw.visitMethod( 131 ACC_PUBLIC, 132 GET_STATIC_PART_METHOD_NAME, 133 GET_STATIC_PART_METHOD_SIGNATURE, 134 null, null 135 ); 136 cv.visitFieldInsn(GETSTATIC, className, SIGNATURE_FIELD_NAME, METHOD_SIGNATURE_IMPL_CLASS_SIGNATURE); 137 cv.visitTypeInsn(CHECKCAST, METHOD_SIGNATURE_IMPL_CLASS_NAME); 138 cv.visitMethodInsn( 139 INVOKEVIRTUAL, METHOD_SIGNATURE_IMPL_CLASS_NAME, GET_METHOD_METHOD_NAME, 140 GET_METHOD_METHOD_SIGNATURE 141 ); 142 cv.visitInsn(ARETURN); 143 cv.visitMaxs(1, 1); 144 } 145 146 { 148 cv = 149 cw.visitMethod( 150 ACC_PUBLIC, 151 GET_METHOD_METHOD_NAME, 152 GET_METHOD_METHOD_SIGNATURE, 153 null, null 154 ); 155 cv.visitFieldInsn(GETSTATIC, className, SIGNATURE_FIELD_NAME, METHOD_SIGNATURE_IMPL_CLASS_SIGNATURE); 156 cv.visitTypeInsn(CHECKCAST, METHOD_SIGNATURE_IMPL_CLASS_NAME); 157 cv.visitMethodInsn( 158 INVOKEVIRTUAL, METHOD_SIGNATURE_IMPL_CLASS_NAME, GET_METHOD_METHOD_NAME, 159 GET_METHOD_METHOD_SIGNATURE 160 ); 161 cv.visitInsn(ARETURN); 162 cv.visitMaxs(1, 1); 163 } 164 165 { 167 cv = cw.visitMethod( 168 ACC_PUBLIC, 169 GET_ARGUMENTS_METHOD_NAME, 170 GET_ARGUMENTS_METHOD_SIGNATURE, 171 null, null 172 ); 173 cv.visitVarInsn(ALOAD, 0); 174 cv.visitMethodInsn(INVOKESPECIAL, className, GET_RTTI_METHOD_NAME, GET_RTTI_METHOD_SIGNATURE); 175 cv.visitTypeInsn(CHECKCAST, METHOD_RTTI_IMPL_CLASS_NAME); 176 cv.visitMethodInsn( 177 INVOKEVIRTUAL, 178 METHOD_RTTI_IMPL_CLASS_NAME, 179 GET_PARAMETER_VALUES_METHOD_NAME, 180 GET_ARGUMENTS_METHOD_SIGNATURE 181 ); 182 cv.visitInsn(ARETURN); 183 cv.visitMaxs(1, 1); 184 } 185 186 } 187 188 193 public void createInvocationOfAroundClosureSuperClass(final CodeVisitor cv) { 194 } 195 196 203 public void createAspectReferenceField(final ClassWriter cw, 204 final AspectInfo aspectInfo, 205 final String joinPointClassName) { 206 AbstractJoinPointCompiler.createAspectReferenceField(cw, aspectInfo); 207 } 208 209 216 public void createAspectInstantiation(final CodeVisitor cv, 217 final AspectInfo aspectInfo, 218 final String joinPointClassName) { 219 AbstractJoinPointCompiler.createAspectInstantiation(cv, aspectInfo, joinPointClassName); 220 } 221 222 228 public void createAroundAdviceArgumentHandling(final CodeVisitor cv, final AdviceMethodInfo adviceMethodInfo) { 229 } 230 231 237 public void createBeforeAdviceArgumentHandling(final CodeVisitor cv, final AdviceMethodInfo adviceMethodInfo) { 238 } 239 240 246 public void createAfterAdviceArgumentHandling(final CodeVisitor cv, final AdviceMethodInfo adviceMethodInfo) { 247 } 248 } 249 | Popular Tags |