48 |
import java.lang.ClassNotFoundException; |
import java.lang.ClassNotFoundException; |
49 |
import java.lang.InstantiationException; |
import java.lang.InstantiationException; |
50 |
import java.lang.IllegalAccessException; |
import java.lang.IllegalAccessException; |
51 |
|
import java.lang.reflect.Constructor; |
52 |
|
|
53 |
public abstract class RemoteObject |
public abstract class RemoteObject |
54 |
implements Remote, Serializable { |
implements Remote, Serializable { |
69 |
return (ref); |
return (ref); |
70 |
} |
} |
71 |
|
|
72 |
public static Remote toStub(Remote obj) throws NoSuchObjectException { |
public static Remote toStub(Remote obj) throws NoSuchObjectException |
73 |
throw new Error("Not implemented"); |
{ |
74 |
} |
Class cls = obj.getClass(); |
75 |
|
String classname = cls.getName(); |
76 |
|
ClassLoader cl = cls.getClassLoader(); |
77 |
|
try |
78 |
|
{ |
79 |
|
Class scls = cl.loadClass(classname + "_Stub"); |
80 |
|
// JDK 1.2 stubs |
81 |
|
Class[] stubprototype = new Class[] { RemoteRef.class }; |
82 |
|
Constructor con = scls.getConstructor(stubprototype); |
83 |
|
return (Remote)(con.newInstance(new Object[]{obj})); |
84 |
|
} |
85 |
|
catch (Exception e) {} |
86 |
|
throw new NoSuchObjectException(obj.getClass().getName()); |
87 |
|
} |
88 |
|
|
89 |
public int hashCode() { |
public int hashCode() { |
90 |
if (ref == null) { |
if (ref == null) { |
100 |
return (this == obj); |
return (this == obj); |
101 |
} |
} |
102 |
|
|
103 |
public String toString() { |
public String toString() |
104 |
return (ref.toString()); |
{ |
105 |
} |
if (ref == null) |
106 |
|
return getClass ().toString (); |
107 |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { |
return (ref.toString ()); |
108 |
String cname = in.readUTF(); |
} |
109 |
if (!cname.equals("")) { |
|
110 |
cname = RemoteRef.packagePrefix + '.' + cname; |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException |
111 |
try { |
{ |
112 |
Class cls = Class.forName(cname); |
String cname = in.readUTF(); |
113 |
ref = (RemoteRef)cls.newInstance(); |
if (!cname.equals("")) |
114 |
} |
{ |
115 |
catch (InstantiationException e1) { |
if (cname.equals ("UnicastRef2")) |
116 |
throw new UnmarshalException("failed to create ref"); |
{ |
117 |
} |
// hack for interoperating with JDK |
118 |
catch (IllegalAccessException e2) { |
cname = "UnicastRef"; |
119 |
throw new UnmarshalException("failed to create ref"); |
in.read (); //some unknown UnicastRef2 field |
120 |
} |
} |
121 |
ref.readExternal(in); |
|
122 |
} |
cname = RemoteRef.packagePrefix + '.' + cname; |
123 |
else { |
try |
124 |
ref = (RemoteRef)in.readObject(); |
{ |
125 |
} |
Class cls = Class.forName(cname); |
126 |
} |
ref = (RemoteRef)cls.newInstance(); |
127 |
|
} |
128 |
|
catch (InstantiationException e1) |
129 |
|
{ |
130 |
|
throw new UnmarshalException("failed to create ref"); |
131 |
|
} |
132 |
|
catch (IllegalAccessException e2) |
133 |
|
{ |
134 |
|
throw new UnmarshalException("failed to create ref"); |
135 |
|
} |
136 |
|
ref.readExternal(in); |
137 |
|
} |
138 |
|
else |
139 |
|
{ |
140 |
|
ref = (RemoteRef)in.readObject(); |
141 |
|
} |
142 |
|
} |
143 |
|
|
144 |
private void writeObject(ObjectOutputStream out) throws IOException, ClassNotFoundException { |
private void writeObject(ObjectOutputStream out) throws IOException, ClassNotFoundException { |
145 |
if (ref == null) { |
if (ref == null) { |