1 22 package org.jboss.aop.instrument; 23 24 import javassist.CannotCompileException; 25 import javassist.CtClass; 26 import javassist.CtConstructor; 27 import javassist.Modifier; 28 import javassist.NotFoundException; 29 30 36 public class OptimizedConstructorExecutionTransformer extends 37 ConstructorExecutionTransformer 38 { 39 public OptimizedConstructorExecutionTransformer(Instrumentor instrumentor) 40 { 41 super(instrumentor); 42 } 43 44 protected void createWrapper(ConstructorTransformation trans)throws NotFoundException, CannotCompileException 45 { 46 String invocationClass = OptimizedConstructorInvocations.getOptimizedInvocationClassName(trans.getClazz(), trans.getIndex()); 47 if(!Modifier.isPublic(trans.getConstructor().getModifiers())) { 48 invocationClass = invocationClass.substring(invocationClass.lastIndexOf('.') + 1); 49 invocationClass = trans.getClazz().getName() + "$" + invocationClass; 50 } 51 52 String infoName = getConstructorInfoFieldName(trans.getSimpleName(), trans.getIndex()); 53 String code = 54 "{ " + 55 " " + constructorInfoFromWeakReference("info", infoName) + 56 " org.jboss.aop.advice.Interceptor[] interceptors = info.getInterceptors(); " + 57 " if (interceptors != (org.jboss.aop.advice.Interceptor[])null) " + 58 " { " + 59 " " + invocationClass + " invocation = new " + invocationClass + "(interceptors); " + 60 " invocation.setConstructor(info.getConstructor()); " + 61 OptimizedBehaviourInvocations.setArguments(trans.getConstructor().getParameterTypes().length) + 62 " invocation.setAdvisor(" + Instrumentor.HELPER_FIELD_NAME + "); " + 63 " return ($r)invocation.invokeNext(); " + 64 " } " + 65 " return new " + trans.getClazz().getName() + "($$); " + 66 "}"; 67 68 codifier.addPendingCode(trans.getWrapperMethod(), code); 71 } 72 73 protected void generateConstructorInfoField(CtClass clazz, CtConstructor constructor, int index) throws CannotCompileException, NotFoundException 74 { 75 super.generateConstructorInfoField(clazz, constructor, index); 76 OptimizedConstructorInvocations.createOptimizedInvocationClass(getInstrumentor(), constructor.getDeclaringClass(), constructor, index); 77 } 78 79 } 80 | Popular Tags |