1 package hudson.remoting; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import java.io.ObjectInputStream ; 6 import java.io.ObjectStreamClass ; 7 import java.lang.reflect.Modifier ; 8 import java.lang.reflect.Proxy ; 9 import java.util.Map ; 10 import java.util.HashMap ; 11 12 15 final class ObjectInputStreamEx extends ObjectInputStream { 16 private final ClassLoader cl; 17 18 public ObjectInputStreamEx(InputStream in, ClassLoader cl) throws IOException { 19 super(in); 20 this.cl = cl; 21 } 22 23 @Override 24 protected Class <?> resolveClass(ObjectStreamClass desc) throws IOException , ClassNotFoundException { 25 String name = desc.getName(); 26 try { 27 return Class.forName(name, false, cl); 28 } catch (ClassNotFoundException ex) { 29 return super.resolveClass(desc); 30 } 31 } 32 33 @Override 34 protected Class <?> resolveProxyClass(String [] interfaces) throws IOException , ClassNotFoundException { 35 ClassLoader latestLoader = cl; 36 ClassLoader nonPublicLoader = null; 37 boolean hasNonPublicInterface = false; 38 39 Class [] classObjs = new Class [interfaces.length]; 41 for (int i = 0; i < interfaces.length; i++) { 42 Class cl = Class.forName(interfaces[i], false, latestLoader); 43 if ((cl.getModifiers() & Modifier.PUBLIC) == 0) { 44 if (hasNonPublicInterface) { 45 if (nonPublicLoader != cl.getClassLoader()) { 46 throw new IllegalAccessError ( 47 "conflicting non-public interface class loaders"); 48 } 49 } else { 50 nonPublicLoader = cl.getClassLoader(); 51 hasNonPublicInterface = true; 52 } 53 } 54 classObjs[i] = cl; 55 } 56 try { 57 return Proxy.getProxyClass( 58 hasNonPublicInterface ? nonPublicLoader : latestLoader, 59 classObjs); 60 } catch (IllegalArgumentException e) { 61 throw new ClassNotFoundException (null, e); 62 } 63 } 64 } 65 | Popular Tags |