1 19 package org.objectweb.carol.cmi; 20 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.io.ObjectInputStream ; 24 import java.io.ObjectStreamClass ; 25 import java.io.StreamCorruptedException ; 26 import java.rmi.server.RMIClassLoader ; 27 28 public class CmiInputStream extends ObjectInputStream { 29 public CmiInputStream(InputStream in) 30 throws IOException , StreamCorruptedException { 31 super(in); 32 } 33 34 protected Class resolveClass(ObjectStreamClass classDesc) 35 throws IOException , ClassNotFoundException { 36 Object annotation = readLocation(); 37 String className = classDesc.getName(); 38 39 try { 40 return super.resolveClass(classDesc); 41 } catch (ClassNotFoundException e) { 42 } 43 44 if (annotation != null && (annotation instanceof String )) { 45 String location = (String ) annotation; 46 return RMIClassLoader.loadClass(location, className); 47 } else { 48 return RMIClassLoader.loadClass((String ) null, className); 49 } 50 } 51 52 protected Class resolveProxyClass(String [] interfaces) 53 throws IOException , ClassNotFoundException { 54 Object annotation = readLocation(); 55 56 ClassLoader loader; 57 if (annotation != null && (annotation instanceof String )) { 58 String location = (String ) annotation; 59 loader = RMIClassLoader.getClassLoader(location); 60 } else { 61 loader = RMIClassLoader.getClassLoader(null); 62 } 63 64 Class [] classObjs = new Class [interfaces.length]; 65 for (int i = 0; i < interfaces.length; i++) { 66 classObjs[i] = Class.forName(interfaces[i], false, loader); 67 } 68 return java.lang.reflect.Proxy.getProxyClass(loader, classObjs); 69 } 70 71 protected Object readLocation() 72 throws IOException , ClassNotFoundException { 73 return readObject(); 74 } 75 } 76 | Popular Tags |