Browse Source

made ProxyFactory.getClassLoader() customizable.


git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@321 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
tags/rel_3_17_1_ga
chiba 18 years ago
parent
commit
ac5eb2dd04
2 changed files with 50 additions and 2 deletions
  1. 1
    1
      src/main/javassist/CtClass.java
  2. 49
    1
      src/main/javassist/util/proxy/ProxyFactory.java

+ 1
- 1
src/main/javassist/CtClass.java View File

@@ -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.

+ 49
- 1
src/main/javassist/util/proxy/ProxyFactory.java View File

@@ -142,6 +142,13 @@ public class ProxyFactory {
superClass = clazz;
}

/**
* Obtains the super class set by <code>setSuperclass()</code>.
*
* @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 <code>setInterfaces</code>.
*
* @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 <code>createClass()</code> for obtaining
* a class loader.
* <code>get()</code> on this <code>ClassLoaderGetter</code> object
* is called to obtain a class loader.
*
* <p>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

Loading…
Cancel
Save