1 22 package org.jboss.aop.standalone; 23 24 import javassist.CannotCompileException; 25 import javassist.ClassPool; 26 import javassist.CtClass; 27 import javassist.NotFoundException; 28 import javassist.scopedpool.ScopedClassPoolRepository; 29 30 import org.jboss.aop.classpool.AOPClassPool; 31 32 39 public class StandaloneClassPool extends AOPClassPool 40 { 41 public StandaloneClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository) 42 { 43 super(cl, src, repository); 44 } 45 46 public StandaloneClassPool(ClassPool src, ScopedClassPoolRepository repository) 47 { 48 super(src, repository); 49 } 50 51 public Class toClass(CtClass ctClass) throws CannotCompileException 54 { 55 try 56 { 57 byte[] b = ctClass.toBytecode(); 58 Class cl = Class.forName("java.lang.ClassLoader"); 59 java.lang.reflect.Method method 60 = cl.getDeclaredMethod("defineClass", 61 new Class []{String .class, byte[].class, 62 int.class, int.class}); 63 method.setAccessible(true); 64 Object [] args = new Object []{ctClass.getName(), b, new Integer (0), 65 new Integer (b.length)}; 66 Class clazz = (Class ) method.invoke(getClassLoader(), args); 67 method.setAccessible(false); 68 return clazz; 69 } 70 catch (RuntimeException e) 71 { 72 throw e; 73 } 74 catch (java.lang.reflect.InvocationTargetException e) 75 { 76 throw new CannotCompileException(e); 77 } 78 catch (Exception e) 79 { 80 throw new CannotCompileException(e); 81 } 82 } 83 84 public synchronized CtClass getLocally(String classname) throws NotFoundException 85 { 86 return super.getLocally(classname); 87 } 88 } 89 | Popular Tags |