aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/rmi/CORBA/Stub.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/rmi/CORBA/Stub.java')
-rw-r--r--libjava/classpath/javax/rmi/CORBA/Stub.java170
1 files changed, 125 insertions, 45 deletions
diff --git a/libjava/classpath/javax/rmi/CORBA/Stub.java b/libjava/classpath/javax/rmi/CORBA/Stub.java
index a35a08fa9d3..190b10dad57 100644
--- a/libjava/classpath/javax/rmi/CORBA/Stub.java
+++ b/libjava/classpath/javax/rmi/CORBA/Stub.java
@@ -1,5 +1,5 @@
-/* Stub.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+/* Stub.java --
+ Copyright (C) 2004, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,7 +39,7 @@ exception statement from your version. */
package javax.rmi.CORBA;
import gnu.javax.rmi.CORBA.DelegateFactory;
-import gnu.javax.rmi.CORBA.GetDelegateInstanceException;
+import gnu.javax.rmi.CORBA.StubDelegateImpl;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -47,7 +47,27 @@ import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.rmi.RemoteException;
-public abstract class Stub extends ObjectImpl
+import javax.rmi.PortableRemoteObject;
+
+import org.omg.CORBA.ORB;
+import org.omg.CORBA_2_3.portable.ObjectImpl;
+
+/**
+ * A Stub descendants provide access to the object on the client side. This base
+ * class implements methods, required for remote or local invocation using CORBA
+ * mechanisms. The most of the functionality is forwarded to the stub delegate.
+ * This delegate can be altered by setting the system property
+ * "javax.rmi.CORBA.StubClass" to the name of the alternative class that must
+ * implement {@link StubDelegate}. Hence Stub contains two delegates, one for
+ * Stub-related operations and another inherited from the ObjectImpl.
+ *
+ * @specnote GNU Classpath uses separate delegate per each Stub. The delegate
+ * holds information about the ORB and other data, specific for the each Stub.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public abstract class Stub
+ extends ObjectImpl
implements Serializable
{
/**
@@ -55,69 +75,129 @@ public abstract class Stub extends ObjectImpl
*/
private static final long serialVersionUID = 1087775603798577179L;
- private transient StubDelegate delegate;
-
- protected Stub()
- {
- try
- {
- delegate = (StubDelegate)DelegateFactory.getInstance("Stub");
- }
- catch(GetDelegateInstanceException e)
- {
- delegate = null;
- }
- }
+ /**
+ * The hashcode, computed once (expensive operation).
+ */
+ transient int m_hash = Integer.MIN_VALUE;
+
+ /**
+ * The stringified reference, computed once (expensive operation).
+ */
+ transient String m_ior;
+
+ /**
+ * The ORB, where the stub is connected on the client side.
+ */
+ transient ORB m_orb;
+ /**
+ * The associated delegate, responsible for the major of the functionality of
+ * this stub.
+ */
+ static StubDelegate delegate = (StubDelegate) DelegateFactory.getInstance(DelegateFactory.STUB);
+
+ /**
+ * Returns the same hashcode for all stubs that point to the same remote
+ * object.
+ */
public int hashCode()
{
- if(delegate != null)
- return delegate.hashCode(this);
- else
- return 0;
+ if (m_hash == Integer.MIN_VALUE)
+ m_hash = delegate.hashCode(this);
+ // This should finally result to the IOR comparison.
+ return m_hash;
}
- public boolean equals(Object obj)
+ /**
+ * The stubs are equal if they point to the same remote object.
+ */
+ public boolean equals(java.lang.Object obj)
{
- if(delegate != null)
- return delegate.equals(this, obj);
- else
- return false;
+ return delegate.equals(this, obj);
}
+ /**
+ * Get the string representation of this Stub.
+ *
+ * @return the CORBA IOR reference.
+ */
public String toString()
{
- String s = null;
- if(delegate != null)
- s = delegate.toString(this);
- if(s == null)
- s = super.toString();
- return s;
+ if (m_ior == null)
+ m_ior = delegate.toString(this);
+ return m_ior;
}
- // XXX javax.rmi.ORB -> org.omg.CORBA.ORB
- public void connect(javax.rmi.ORB orb)
+ /**
+ * <p>
+ * Finds the suitable {@link Tie} for this Stub and connects it to the given
+ * ORB. The tie is found by the name pattern. If the found tie is derived from
+ * {@link org.omg.CORBA.PortableServer.Servant}, it is connected to the root
+ * POA, also activating it (if not already active).
+ * </p>
+ * <p>
+ * This method does not allow to specify, to which POA the found Tie must be
+ * connected and requires to use the deprecated method {@link ORB#connect}.
+ * Many useful POA features remain unaccessible. A better alternative it might
+ * be to generate a {@link org.omg.CORBA.PortableServer.Servant} - derived Tie
+ * (-poa key in rmic) and connect it to POA in one of the many ways, listed in
+ * the description of the {@link orb.omg.PortableServer} package). The
+ * obtained CORBA object can be narrowed into stub using
+ * {@link PortableRemoteObject#narrow}.
+ * </p>
+ * <p>
+ * It is frequently easier to call {@link PortableRemoteObject#connect} rather
+ * than this method.
+ * </p>
+ *
+ * @param orb the ORB where the Stub must be connected.
+ *
+ * @throws RemoteException if the stub is already connected to some other ORB.
+ * If the stub is already connected to the ORB that was passed as parameter,
+ * the method returns without action.
+ *
+ * @throws BAD_PARAM if the name of this stub does not match the stub name
+ * pattern, "_*_Stub" or if the Tie class, "_*Impl_Tie", does not exists or an
+ * instance of this class cannot be instantiated.
+ */
+ public void connect(ORB orb)
throws RemoteException
{
- if(delegate != null)
- delegate.connect(this, orb);
+ if (m_orb != null && orb != null)
+ {
+ if (m_orb.equals(orb))
+ throw new RemoteException("Stub " + this
+ + " is connected to another ORB, " + orb);
+ else
+ return;
+ }
+ m_orb = orb;
+ delegate.connect(this, orb);
}
/**
- * The following two routines are required by serialized form of Java API doc.
+ * Required by serialized form of Java API doc.
*/
- private void readObject(ObjectInputStream stream)
+ private void readObject(ObjectInputStream input)
throws IOException, ClassNotFoundException
{
- if(delegate != null)
- delegate.readObject(this, stream);
+ if (delegate instanceof StubDelegateImpl)
+ ((StubDelegateImpl) delegate).readObject(this, input, m_orb);
+ else
+ delegate.readObject(this, input);
}
- private void writeObject(ObjectOutputStream stream)
+ /**
+ * Required by serialized form of Java API doc.
+ */
+ private void writeObject(ObjectOutputStream output)
throws IOException
{
- if(delegate != null)
- delegate.writeObject(this, stream);
- }
+ // The m_orb in this case may be either known or not.
+ if (delegate instanceof StubDelegateImpl)
+ ((StubDelegateImpl) delegate).writeObject(this, output, m_orb);
+ else
-}
+ delegate.writeObject(this, output);
+ }
+} \ No newline at end of file