45 |
import java.rmi.NoSuchObjectException; |
import java.rmi.NoSuchObjectException; |
46 |
import java.rmi.Remote; |
import java.rmi.Remote; |
47 |
import java.rmi.UnmarshalException; |
import java.rmi.UnmarshalException; |
48 |
|
import java.util.WeakHashMap; |
49 |
|
|
50 |
public abstract class RemoteObject |
public abstract class RemoteObject |
51 |
implements Remote, Serializable { |
implements Remote, Serializable { |
54 |
|
|
55 |
protected transient RemoteRef ref; |
protected transient RemoteRef ref; |
56 |
|
|
57 |
|
private static final WeakHashMap stubs = new WeakHashMap(); |
58 |
|
|
59 |
protected RemoteObject() { |
protected RemoteObject() { |
60 |
this(null); |
this(null); |
61 |
} |
} |
68 |
return (ref); |
return (ref); |
69 |
} |
} |
70 |
|
|
71 |
|
synchronized static void addStub(Remote obj, Remote stub) |
72 |
|
{ |
73 |
|
stubs.put(obj, stub); |
74 |
|
} |
75 |
|
|
76 |
|
synchronized static void deleteStub(Remote obj) |
77 |
|
{ |
78 |
|
stubs.remove(obj); |
79 |
|
} |
80 |
|
|
81 |
public static Remote toStub(Remote obj) throws NoSuchObjectException |
public static Remote toStub(Remote obj) throws NoSuchObjectException |
82 |
{ |
{ |
83 |
Class cls = obj.getClass(); |
Remote stub = (Remote)stubs.get(obj); |
84 |
String classname = cls.getName(); |
|
85 |
ClassLoader cl = cls.getClassLoader(); |
if (stub == null) |
86 |
try |
throw new NoSuchObjectException(obj.getClass().getName()); |
87 |
{ |
|
88 |
Class scls = cl.loadClass(classname + "_Stub"); |
return stub; |
|
// JDK 1.2 stubs |
|
|
Class[] stubprototype = new Class[] { RemoteRef.class }; |
|
|
Constructor con = scls.getConstructor(stubprototype); |
|
|
return (Remote)(con.newInstance(new Object[]{obj})); |
|
|
} |
|
|
catch (Exception e) {} |
|
|
throw new NoSuchObjectException(obj.getClass().getName()); |
|
89 |
} |
} |
90 |
|
|
91 |
public int hashCode() { |
public int hashCode() { |