You are viewing a plain text version of this content. The canonical link for it is here.
Posted to yoko-commits@incubator.apache.org by ri...@apache.org on 2006/12/07 23:11:57 UTC
svn commit: r483726 -
/incubator/yoko/trunk/rmi-spec/src/main/java/javax/rmi/CORBA/Stub.java
Author: rickmcguire
Date: Thu Dec 7 15:11:56 2006
New Revision: 483726
URL: http://svn.apache.org/viewvc?view=rev&rev=483726
Log:
YOKO-235 javax.rmi.CORBA.Stub class not handling serialization properly.
Modified:
incubator/yoko/trunk/rmi-spec/src/main/java/javax/rmi/CORBA/Stub.java
Modified: incubator/yoko/trunk/rmi-spec/src/main/java/javax/rmi/CORBA/Stub.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi-spec/src/main/java/javax/rmi/CORBA/Stub.java?view=diff&rev=483726&r1=483725&r2=483726
==============================================================================
--- incubator/yoko/trunk/rmi-spec/src/main/java/javax/rmi/CORBA/Stub.java (original)
+++ incubator/yoko/trunk/rmi-spec/src/main/java/javax/rmi/CORBA/Stub.java Thu Dec 7 15:11:56 2006
@@ -31,41 +31,68 @@
static final long serialVersionUID = 1087775603798577179L;
private transient StubDelegate delegate = null;
- private final String defaultDelegate = "org.apache.yoko.rmi.impl.StubImpl";
-
- public Stub() {
- super();
+ private static final String defaultDelegate = "org.apache.yoko.rmi.impl.StubImpl";
+ // the class we use to create delegates. This is loaded once,
+ private static Class delegateClass = null;
+ static {
// Initialize delegate
String delegateName = (String)AccessController.doPrivileged(new GetSystemPropertyAction("javax.rmi.CORBA.StubClass", defaultDelegate));
try {
- delegate = (StubDelegate)Util.loadClass(delegateName, null, null).newInstance();
+ delegateClass = Util.loadClass(delegateName, null, null);
} catch (Exception e) {
- throw new org.omg.CORBA.INITIALIZE("Can not create Stub delegate: "+delegateName);
+ throw new org.omg.CORBA.INITIALIZE("Can not create Stub delegate: " + delegateName);
}
}
+ public Stub() {
+ super();
+ initializeDelegate();
+ }
+
public void connect(ORB orb) throws RemoteException {
+ initializeDelegate();
delegate.connect(this, orb);
}
public boolean equals(Object o) {
+ initializeDelegate();
return delegate.equals(this, o);
}
public int hashCode() {
+ initializeDelegate();
return delegate.hashCode(this);
}
public String toString() {
+ initializeDelegate();
return delegate.toString(this);
}
- public void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
+ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
+ initializeDelegate();
delegate.readObject(this, ois);
}
- public void writeObject(ObjectOutputStream oos) throws IOException {
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ initializeDelegate();
delegate.writeObject(this, oos);
+ }
+
+ /**
+ * Lazy initialization routine for the Stub delegate. Normally, you'd do this
+ * in the constructor. Unfortunately, Java serialization will not call the
+ * constructor for Serializable classes, so we need to ensure we have one
+ * regardless of how/when we are called.
+ */
+ private void initializeDelegate() {
+ if (delegate == null) {
+ try {
+ delegate = (StubDelegate)delegateClass.newInstance();
+ } catch (Exception e) {
+ throw new org.omg.CORBA.INITIALIZE("Can not create Stub delegate: " + delegateClass.getName());
+ }
+ }
}
}