1 9 package org.jboss.remoting.loading; 10 11 import java.io.IOException ; 12 import java.io.ObjectInputStream ; 13 import java.io.StreamCorruptedException ; 14 15 16 23 public class ObjectInputStreamWithClassLoader extends ObjectInputStream 24 { 25 private ClassLoader cl; 26 27 40 public ObjectInputStreamWithClassLoader(java.io.InputStream in, ClassLoader cl) 41 throws IOException , StreamCorruptedException 42 { 43 super(in); 44 this.cl = cl; 45 } 46 47 53 public void setClassLoader(ClassLoader cl) 54 { 55 this.cl = cl; 56 } 57 58 64 public ClassLoader getClassLoader() 65 { 66 return cl; 67 } 68 69 97 protected Class resolveClass(java.io.ObjectStreamClass v) 98 throws java.io.IOException , ClassNotFoundException 99 { 100 if(cl == null) 101 { 102 return super.resolveClass(v); 103 } 104 else 105 { 106 return cl.loadClass(v.getName()); 107 } 108 } 109 110 158 protected Class resolveProxyClass(String [] interfaces) 159 throws java.io.IOException , ClassNotFoundException 160 { 161 if(cl == null) 162 { 163 return super.resolveProxyClass(interfaces); 164 } 165 else 166 { 167 Class [] classObjs = new Class [interfaces.length]; 168 for(int i = 0; i < interfaces.length; i++) 169 { 170 classObjs[i] = cl.loadClass(interfaces[i]); 171 } 172 try 173 { 174 return java.lang.reflect.Proxy.getProxyClass(cl, classObjs); 175 } 176 catch(IllegalArgumentException e) 177 { 178 throw new ClassNotFoundException (null, e); 179 } 180 } 181 } 182 } 183 | Popular Tags |