git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@628710 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2008-02-18 12:55:51 +00:00
parent 2747573f66
commit 213c3ae379
1 changed files with 25 additions and 3 deletions

View File

@ -21,11 +21,13 @@ import java.io.InputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectStreamClass; import java.io.ObjectStreamClass;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.util.HashMap;
public class ClassLoadingAwareObjectInputStream extends ObjectInputStream { public class ClassLoadingAwareObjectInputStream extends ObjectInputStream {
private static final ClassLoader FALLBACK_CLASS_LOADER = ClassLoadingAwareObjectInputStream.class.getClassLoader(); private static final ClassLoader FALLBACK_CLASS_LOADER = ClassLoadingAwareObjectInputStream.class.getClassLoader();
/** <p>Maps primitive type names to corresponding class objects.</p> */
private static final HashMap<String, Class> primClasses = new HashMap<String, Class>(8, 1.0F);
public ClassLoadingAwareObjectInputStream(InputStream in) throws IOException { public ClassLoadingAwareObjectInputStream(InputStream in) throws IOException {
super(in); super(in);
} }
@ -49,12 +51,32 @@ public class ClassLoadingAwareObjectInputStream extends ObjectInputStream {
} }
} }
private Class load(String className, ClassLoader cl) throws ClassNotFoundException { private Class load(String className, ClassLoader cl)
throws ClassNotFoundException {
try { try {
return Class.forName(className, false, cl); return Class.forName(className, false, cl);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
final Class clazz = (Class) primClasses.get(className);
if (clazz != null) {
return clazz;
} else {
return Class.forName(className, false, FALLBACK_CLASS_LOADER); return Class.forName(className, false, FALLBACK_CLASS_LOADER);
} }
} }
}
static {
primClasses.put("boolean", boolean.class);
primClasses.put("byte", byte.class);
primClasses.put("char", char.class);
primClasses.put("short", short.class);
primClasses.put("int", int.class);
primClasses.put("long", long.class);
primClasses.put("float", float.class);
primClasses.put("double", double.class);
primClasses.put("void", void.class);
}
} }