41 |
import java.io.OutputStream; |
import java.io.OutputStream; |
42 |
import java.io.IOException; |
import java.io.IOException; |
43 |
import java.rmi.server.RMIClassLoader; |
import java.rmi.server.RMIClassLoader; |
44 |
|
import java.rmi.Remote; |
45 |
|
import java.rmi.server.RemoteStub; |
46 |
|
import java.rmi.server.ObjID; |
47 |
|
|
48 |
public class RMIObjectOutputStream |
public class RMIObjectOutputStream |
49 |
extends ObjectOutputStream { |
extends ObjectOutputStream { |
50 |
|
|
51 |
public RMIObjectOutputStream(OutputStream strm) throws IOException { |
public RMIObjectOutputStream(OutputStream strm) throws IOException { |
52 |
super(strm); |
super(strm); |
53 |
|
enableReplaceObject(true); |
54 |
|
} |
55 |
|
|
56 |
|
//Separate it for override by MarshalledObject |
57 |
|
protected void setAnnotation(String annotation) throws IOException{ |
58 |
|
writeObject(annotation); |
59 |
} |
} |
60 |
|
|
61 |
protected void annotateClass(Class cls) throws IOException { |
protected void annotateClass(Class cls) throws IOException { |
62 |
//System.out.println("Annotating class: " + cls); |
setAnnotation(RMIClassLoader.getClassAnnotation(cls)); |
63 |
writeObject(RMIClassLoader.getClassAnnotation(cls)); |
} |
64 |
|
|
65 |
|
protected void annotateProxyClass(Class cls) |
66 |
|
throws IOException |
67 |
|
{ |
68 |
|
annotateClass(cls); |
69 |
|
} |
70 |
|
|
71 |
|
protected Object replaceObject(Object obj) |
72 |
|
throws IOException |
73 |
|
{ |
74 |
|
if((obj instanceof Remote) && !(obj instanceof RemoteStub)){ |
75 |
|
UnicastServerRef ref = new UnicastServerRef(new ObjID(), 0, null); |
76 |
|
try{ |
77 |
|
return ref.exportObject((Remote)obj); |
78 |
|
}catch(Exception e){} |
79 |
|
} |
80 |
|
return obj; |
81 |
|
} |
82 |
|
|
83 |
|
protected void writeValue(Object value, Class valueClass) throws IOException{ |
84 |
|
if(valueClass.isPrimitive()){ |
85 |
|
if(valueClass == Boolean.TYPE) |
86 |
|
writeBoolean(((Boolean)value).booleanValue()); |
87 |
|
else |
88 |
|
if(valueClass == Byte.TYPE) |
89 |
|
writeByte(((Byte)value).byteValue()); |
90 |
|
else |
91 |
|
if(valueClass == Character.TYPE) |
92 |
|
writeChar(((Character)value).charValue()); |
93 |
|
else |
94 |
|
if(valueClass == Short.TYPE) |
95 |
|
writeShort(((Short)value).shortValue()); |
96 |
|
else |
97 |
|
if(valueClass == Integer.TYPE) |
98 |
|
writeInt(((Integer)value).intValue()); |
99 |
|
else |
100 |
|
if(valueClass == Long.TYPE) |
101 |
|
writeLong(((Long)value).longValue()); |
102 |
|
else |
103 |
|
if(valueClass == Float.TYPE) |
104 |
|
writeFloat(((Float)value).floatValue()); |
105 |
|
else |
106 |
|
if(valueClass == Double.TYPE) |
107 |
|
writeDouble(((Double)value).doubleValue()); |
108 |
|
else |
109 |
|
throw new Error("Unsupported primitive class: " + valueClass); |
110 |
|
} else |
111 |
|
writeObject(value); |
112 |
} |
} |
113 |
|
|
114 |
} |
} |