2 Copyright (C) 2004, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax
.rmi
.CORBA
;
41 import gnu
.javax
.rmi
.CORBA
.DelegateFactory
;
42 import gnu
.javax
.rmi
.CORBA
.StubDelegateImpl
;
44 import java
.io
.IOException
;
45 import java
.io
.ObjectInputStream
;
46 import java
.io
.ObjectOutputStream
;
47 import java
.io
.Serializable
;
48 import java
.rmi
.RemoteException
;
50 import javax
.rmi
.PortableRemoteObject
;
52 import org
.omg
.CORBA
.ORB
;
53 import org
.omg
.CORBA_2_3
.portable
.ObjectImpl
;
56 * A Stub descendants provide access to the object on the client side. This base
57 * class implements methods, required for remote or local invocation using CORBA
58 * mechanisms. The most of the functionality is forwarded to the stub delegate.
59 * This delegate can be altered by setting the system property
60 * "javax.rmi.CORBA.StubClass" to the name of the alternative class that must
61 * implement {@link StubDelegate}. Hence Stub contains two delegates, one for
62 * Stub-related operations and another inherited from the ObjectImpl.
64 * @specnote GNU Classpath uses separate delegate per each Stub. The delegate
65 * holds information about the ORB and other data, specific for the each Stub.
67 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
69 public abstract class Stub
71 implements Serializable
74 * For compatability with Sun's JDK 1.4.2 rev. 5
76 private static final long serialVersionUID
= 1087775603798577179L;
79 * The hashcode, computed once (expensive operation).
81 transient int m_hash
= Integer
.MIN_VALUE
;
84 * The stringified reference, computed once (expensive operation).
86 transient String m_ior
;
89 * The ORB, where the stub is connected on the client side.
94 * The associated delegate, responsible for the major of the functionality of
97 static StubDelegate delegate
= (StubDelegate
) DelegateFactory
.getInstance(DelegateFactory
.STUB
);
100 * Returns the same hashcode for all stubs that point to the same remote
103 public int hashCode()
105 if (m_hash
== Integer
.MIN_VALUE
)
106 m_hash
= delegate
.hashCode(this);
107 // This should finally result to the IOR comparison.
112 * The stubs are equal if they point to the same remote object.
114 public boolean equals(java
.lang
.Object obj
)
116 return delegate
.equals(this, obj
);
120 * Get the string representation of this Stub.
122 * @return the CORBA IOR reference.
124 public String
toString()
127 m_ior
= delegate
.toString(this);
133 * Finds the suitable {@link Tie} for this Stub and connects it to the given
134 * ORB. The tie is found by the name pattern. If the found tie is derived from
135 * {@link org.omg.CORBA.PortableServer.Servant}, it is connected to the root
136 * POA, also activating it (if not already active).
139 * This method does not allow to specify, to which POA the found Tie must be
140 * connected and requires to use the deprecated method {@link ORB#connect}.
141 * Many useful POA features remain unaccessible. A better alternative it might
142 * be to generate a {@link org.omg.CORBA.PortableServer.Servant} - derived Tie
143 * (-poa key in rmic) and connect it to POA in one of the many ways, listed in
144 * the description of the {@link orb.omg.PortableServer} package). The
145 * obtained CORBA object can be narrowed into stub using
146 * {@link PortableRemoteObject#narrow}.
149 * It is frequently easier to call {@link PortableRemoteObject#connect} rather
153 * @param orb the ORB where the Stub must be connected.
155 * @throws RemoteException if the stub is already connected to some other ORB.
156 * If the stub is already connected to the ORB that was passed as parameter,
157 * the method returns without action.
159 * @throws BAD_PARAM if the name of this stub does not match the stub name
160 * pattern, "_*_Stub" or if the Tie class, "_*Impl_Tie", does not exists or an
161 * instance of this class cannot be instantiated.
163 public void connect(ORB orb
)
164 throws RemoteException
166 if (m_orb
!= null && orb
!= null)
168 if (m_orb
.equals(orb
))
169 throw new RemoteException("Stub " + this
170 + " is connected to another ORB, " + orb
);
175 delegate
.connect(this, orb
);
179 * Required by serialized form of Java API doc.
181 private void readObject(ObjectInputStream input
)
182 throws IOException
, ClassNotFoundException
184 if (delegate
instanceof StubDelegateImpl
)
185 ((StubDelegateImpl
) delegate
).readObject(this, input
, m_orb
);
187 delegate
.readObject(this, input
);
191 * Required by serialized form of Java API doc.
193 private void writeObject(ObjectOutputStream output
)
196 // The m_orb in this case may be either known or not.
197 if (delegate
instanceof StubDelegateImpl
)
198 ((StubDelegateImpl
) delegate
).writeObject(this, output
, m_orb
);
201 delegate
.writeObject(this, output
);