44 |
import java.net.URL; |
import java.net.URL; |
45 |
import java.net.MalformedURLException; |
import java.net.MalformedURLException; |
46 |
import java.rmi.server.RMIClassLoader; |
import java.rmi.server.RMIClassLoader; |
47 |
|
import java.lang.ClassNotFoundException; |
48 |
|
import java.lang.reflect.Proxy; |
49 |
|
|
50 |
public class RMIObjectInputStream |
public class RMIObjectInputStream |
51 |
extends ObjectInputStream { |
extends ObjectInputStream { |
58 |
enableResolveObject(true); |
enableResolveObject(true); |
59 |
} |
} |
60 |
|
|
61 |
|
public RMIObjectInputStream(InputStream strm) throws IOException { |
62 |
|
this(strm, UnicastConnectionManager.getInstance(0, null)); |
63 |
|
} |
64 |
|
|
65 |
protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { |
protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { |
66 |
//System.out.println("Resolving class: " + desc.getName()); |
String annotation = (String)getAnnotation(); |
67 |
String annotation = (String)readObject(); |
try{ |
68 |
if (annotation == null) { |
return super.resolveClass(desc); |
69 |
return (super.resolveClass(desc)); |
}catch(ClassNotFoundException _){}; |
70 |
|
|
71 |
|
try { |
72 |
|
if(annotation == null) |
73 |
|
return (RMIClassLoader.loadClass(desc.getName())); |
74 |
|
else |
75 |
|
return (RMIClassLoader.loadClass(annotation, desc.getName())); |
76 |
} |
} |
77 |
else { |
catch (MalformedURLException _) { |
78 |
try { |
throw new ClassNotFoundException(desc.getName()); |
|
return (RMIClassLoader.loadClass(new URL(annotation), desc.getName())); |
|
|
} |
|
|
catch (MalformedURLException _) { |
|
|
throw new ClassNotFoundException(desc.getName()); |
|
|
} |
|
79 |
} |
} |
80 |
} |
} |
81 |
|
|
82 |
|
//Separate it for override by MarshalledObject |
83 |
|
protected Object getAnnotation() |
84 |
|
throws IOException, ClassNotFoundException |
85 |
|
{ |
86 |
|
return readObject(); |
87 |
|
} |
88 |
|
|
89 |
|
protected Class resolveProxyClass(String intfs[]) |
90 |
|
throws IOException, ClassNotFoundException |
91 |
|
{ |
92 |
|
String annotation = (String)getAnnotation(); |
93 |
|
try{ |
94 |
|
return super.resolveProxyClass(intfs); |
95 |
|
}catch(ClassNotFoundException _){}; |
96 |
|
|
97 |
|
Class clss[] = new Class[intfs.length]; |
98 |
|
if(annotation == null) |
99 |
|
clss[0] = RMIClassLoader.loadClass(intfs[0]); |
100 |
|
else |
101 |
|
clss[0] = RMIClassLoader.loadClass(annotation, intfs[0]); |
102 |
|
//assume all interfaces can be loaded by the same classloader |
103 |
|
ClassLoader loader = clss[0].getClassLoader(); |
104 |
|
if(loader == null) |
105 |
|
for(int i = 1; i < intfs.length; i++) |
106 |
|
clss[i] = Class.forName(intfs[i]); |
107 |
|
else |
108 |
|
for(int i = 1; i < intfs.length; i++) |
109 |
|
clss[i] = loader.loadClass(intfs[i]); |
110 |
|
return Proxy.getProxyClass(loader, clss); |
111 |
|
} |
112 |
|
|
113 |
|
protected Object readValue(Class valueClass) throws IOException, ClassNotFoundException { |
114 |
|
if(valueClass.isPrimitive()){ |
115 |
|
if(valueClass == Boolean.TYPE) |
116 |
|
return new Boolean(readBoolean()); |
117 |
|
if(valueClass == Byte.TYPE) |
118 |
|
return new Byte(readByte()); |
119 |
|
if(valueClass == Character.TYPE) |
120 |
|
return new Character(readChar()); |
121 |
|
if(valueClass == Short.TYPE) |
122 |
|
return new Short(readShort()); |
123 |
|
if(valueClass == Integer.TYPE) |
124 |
|
return new Integer(readInt()); |
125 |
|
if(valueClass == Long.TYPE) |
126 |
|
return new Long(readLong()); |
127 |
|
if(valueClass == Float.TYPE) |
128 |
|
return new Float(readFloat()); |
129 |
|
if(valueClass == Double.TYPE) |
130 |
|
return new Double(readDouble()); |
131 |
|
else |
132 |
|
throw new Error("Unsupported primitive class: " + valueClass); |
133 |
|
} else |
134 |
|
return readObject(); |
135 |
} |
} |
136 |
|
|
137 |
|
} |