From ac5eb2dd048fa474e96f5f5786c6d482b674c051 Mon Sep 17 00:00:00 2001 From: chiba Date: Thu, 31 Aug 2006 18:46:24 +0000 Subject: [PATCH] made ProxyFactory.getClassLoader() customizable. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@321 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/CtClass.java | 2 +- .../javassist/util/proxy/ProxyFactory.java | 50 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java index 91ad9968..22219da4 100644 --- a/src/main/javassist/CtClass.java +++ b/src/main/javassist/CtClass.java @@ -52,7 +52,7 @@ public abstract class CtClass { /** * The version number of this release. */ - public static final String version = "3.3"; + public static final String version = "3.4"; /** * Prints the version number and the copyright notice. diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java index fdd397ad..7fe72c77 100644 --- a/src/main/javassist/util/proxy/ProxyFactory.java +++ b/src/main/javassist/util/proxy/ProxyFactory.java @@ -142,6 +142,13 @@ public class ProxyFactory { superClass = clazz; } + /** + * Obtains the super class set by setSuperclass(). + * + * @since 3.4 + */ + public Class getSuperclass() { return superClass; } + /** * Sets the interfaces of a proxy class. */ @@ -149,6 +156,13 @@ public class ProxyFactory { interfaces = ifs; } + /** + * Obtains the interfaces set by setInterfaces. + * + * @since 3.4 + */ + public Class[] getInterfaces() { return interfaces; } + /** * Sets a filter that selects the methods that will be controlled by a handler. */ @@ -177,14 +191,48 @@ public class ProxyFactory { return thisClass; } + /** + * A provider of class loaders. + */ + public static interface ClassLoaderProvider { + /** + * Returns a class loader. + * + * @param pf a proxy factory that is going to obtain a class loader. + */ + public ClassLoader get(ProxyFactory pf); + } + + /** + * A provider used by createClass() for obtaining + * a class loader. + * get() on this ClassLoaderGetter object + * is called to obtain a class loader. + * + *

The value of this field can be updated for changing the default + * implementation. + * + * @since 3.4 + */ + public static ClassLoaderProvider classLoaderProvider + = new ClassLoaderProvider() { + public ClassLoader get(ProxyFactory pf) { + return pf.getClassLoader0(); + } + }; + protected ClassLoader getClassLoader() { + return classLoaderProvider.get(this); + } + + protected ClassLoader getClassLoader0() { // return Thread.currentThread().getContextClassLoader(); ClassLoader loader = null; if (superClass != null && !superClass.getName().equals("java.lang.Object")) loader = superClass.getClassLoader(); else if (interfaces != null && interfaces.length > 0) loader = interfaces[0].getClassLoader(); - + if (loader == null) { loader = getClass().getClassLoader(); // In case javassist is in the endorsed dir -- 2.39.5