1 22 package org.jboss.aop.instrument; 23 24 25 import javassist.CannotCompileException; 26 import javassist.CtClass; 27 import javassist.CtConstructor; 28 import javassist.CtNewConstructor; 29 import javassist.NotFoundException; 30 31 import org.jboss.aop.classpool.AOPClassPool; 32 33 39 public abstract class OptimizedInvocations 40 { 41 public static void defrostClassIfExists(AOPClassPool pool, String className) 42 { 43 try 44 { 45 CtClass existing = pool.get(className); 48 existing.defrost(); 49 } 50 catch (NotFoundException e) 51 { 52 } 54 } 55 56 65 public static CtClass makeInvocationClass(AOPClassPool pool, 66 boolean makeInnerClass, 67 CtClass outerClass, 68 String className, 69 CtClass superInvocation)throws CannotCompileException, NotFoundException 70 { 71 72 CtClass invocation = makeInvocationClassNoCtors(pool, makeInnerClass, outerClass, className, superInvocation); 73 74 CtConstructor[] cons = superInvocation.getDeclaredConstructors(); 76 for (int i = 0; i < cons.length; i++) 77 { 78 CtConstructor conTemplate = superInvocation.getDeclaredConstructors()[i]; 79 CtConstructor icon = CtNewConstructor.make(conTemplate.getParameterTypes(), 80 conTemplate.getExceptionTypes(), 81 invocation); 82 invocation.addConstructor(icon); 83 } 84 85 return invocation; 86 } 87 88 public static CtClass makeInvocationClassNoCtors(AOPClassPool pool, 89 boolean makeInnerClass, 90 CtClass outerClass, 91 String className, 92 CtClass superInvocation)throws CannotCompileException, NotFoundException 93 { 94 CtClass untransformable = pool.get("org.jboss.aop.instrument.Untransformable"); 95 96 CtClass invocation; 97 if (makeInnerClass) 98 { 99 String innerClassName = className.substring(className.lastIndexOf('.') + 1); 101 defrostClassIfExists(pool, outerClass.getName() + "$" + innerClassName); 102 103 boolean classStatic = true; 105 invocation = TransformerCommon.makeNestedClass(outerClass, innerClassName, classStatic); 106 invocation.setSuperclass(superInvocation); 107 } 108 else 109 { 110 defrostClassIfExists(pool, className); 111 invocation = TransformerCommon.makeClass(pool, className, superInvocation); 112 } 113 114 invocation.addInterface(untransformable); 115 return invocation; 116 } 117 } 118 | Popular Tags |