1 package org.jgroups.util; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 6 import java.io.IOException ; 7 import java.io.ObjectStreamClass ; 8 import java.io.InputStream ; 9 import java.io.ObjectInputStream ; 10 import java.util.HashMap ; 11 12 18 public class ContextObjectInputStream extends ObjectInputStream { 19 20 21 24 private static final HashMap classCache=new HashMap (); 25 26 private static final HashMap primClasses = new HashMap (8, 1.0F); 27 static { 28 primClasses.put("boolean", boolean.class); 29 primClasses.put("byte", byte.class); 30 primClasses.put("char", char.class); 31 primClasses.put("short", short.class); 32 primClasses.put("int", int.class); 33 primClasses.put("long", long.class); 34 primClasses.put("float", float.class); 35 primClasses.put("double", double.class); 36 primClasses.put("void", void.class); 37 } 38 39 42 public ContextObjectInputStream(InputStream is) throws IOException { 43 super(is); 44 } 45 46 47 protected Class resolveClass(ObjectStreamClass v) throws IOException , ClassNotFoundException { 48 String className=v.getName(); 49 Class resolvedClass=null; 50 if(classCache != null) { 52 synchronized(classCache) { 53 resolvedClass=(Class )classCache.get(className); 54 } 55 } 56 57 if(resolvedClass == null) { 58 ClassLoader loader=Thread.currentThread().getContextClassLoader(); 59 try { 60 resolvedClass=loader.loadClass(className); 61 } 62 catch(ClassNotFoundException e) { 63 68 resolvedClass = (Class ) primClasses.get(className); 69 if (resolvedClass == null) { 70 71 75 resolvedClass=super.resolveClass(v); 76 } 77 } 78 if(classCache != null) { 79 synchronized(classCache) { 80 classCache.put(className, resolvedClass); 81 } 82 } 83 } 84 return resolvedClass; 85 } 86 } 87 88 | Popular Tags |