From: adrian Date: Wed, 15 Mar 2006 17:46:52 +0000 (+0000) Subject: Allow a ClassPool to override the "guess" at the classloader to use. X-Git-Tag: rel_3_17_1_ga~369 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=163f2ece3197b5222b5967f6ce3a034913c01491;p=javassist.git Allow a ClassPool to override the "guess" at the classloader to use. The default is still the thread context classloader. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@259 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java index 25332d76..cd869285 100644 --- a/src/main/javassist/ClassPool.java +++ b/src/main/javassist/ClassPool.java @@ -754,7 +754,10 @@ public class ClassPool { * To load the class, this method uses the context class loader * of the current thread. If the program is running on some application * server, the context class loader might be inappropriate to load the - * class. + * class.

+ * + * This can be changed by subclassing the pool and changing + * the getClassLoader() method. * *

This method is provided for convenience. If you need more * complex functionality, you should write your own class loader. @@ -762,9 +765,20 @@ public class ClassPool { * @see #toClass(CtClass, java.lang.ClassLoader) */ public Class toClass(CtClass clazz) throws CannotCompileException { - return toClass(clazz, getContextClassLoader()); + return toClass(clazz, getClassLoader()); } + /** + * Get the classloader for this pool.

+ * + * The default is the context class loader. + * + * @return the classloader for the pool + */ + public ClassLoader getClassLoader() { + return getContextClassLoader(); + } + /** * Obtains a class loader that seems appropriate to look up a class * by name. diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java index 86dbf3b2..ed3d9051 100644 --- a/src/main/javassist/CtClassType.java +++ b/src/main/javassist/CtClassType.java @@ -496,7 +496,7 @@ class CtClassType extends CtClass { throws ClassNotFoundException { try { - ClassLoader cl = ClassPool.getContextClassLoader(); + ClassLoader cl = cp.getClassLoader(); return anno.toAnnotationType(cl, cp); } catch (ClassNotFoundException e) {