1 |
775 |
jeremybenn |
/* Servant.java --
|
2 |
|
|
Copyright (C) 2005 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
5 |
|
|
|
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)
|
9 |
|
|
any later version.
|
10 |
|
|
|
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.
|
15 |
|
|
|
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
|
19 |
|
|
02110-1301 USA.
|
20 |
|
|
|
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
|
24 |
|
|
combination.
|
25 |
|
|
|
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. */
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
package org.omg.PortableServer;
|
40 |
|
|
|
41 |
|
|
import org.omg.CORBA.BAD_OPERATION;
|
42 |
|
|
import org.omg.CORBA.BAD_INV_ORDER;
|
43 |
|
|
import org.omg.CORBA.NO_IMPLEMENT;
|
44 |
|
|
import org.omg.CORBA.OBJECT_NOT_EXIST;
|
45 |
|
|
import org.omg.CORBA.ORB;
|
46 |
|
|
import org.omg.PortableServer.POAPackage.ServantNotActive;
|
47 |
|
|
import org.omg.PortableServer.POAPackage.WrongPolicy;
|
48 |
|
|
import org.omg.PortableServer.portable.Delegate;
|
49 |
|
|
|
50 |
|
|
import gnu.CORBA.Minor;
|
51 |
|
|
import gnu.CORBA.Poa.ORB_1_4;
|
52 |
|
|
import gnu.CORBA.Poa.gnuPOA;
|
53 |
|
|
|
54 |
|
|
/**
|
55 |
|
|
* <p>
|
56 |
|
|
* The servant is responsible for handling the method invocation on the
|
57 |
|
|
* target object. It can be one servant per object, or the same servant can
|
58 |
|
|
* support several (possibly all) objects, associated with the given POA.
|
59 |
|
|
* </p> <p>
|
60 |
|
|
* Till JDK 1.3 inclusive, a typical IDL to java compiler generates an
|
61 |
|
|
* implementation base (name pattern _*ImplBase.java) that is derived from the
|
62 |
|
|
* {@link org.omg.CORBA.portable.ObjectImpl}. Since JDK 1.4 the implementation
|
63 |
|
|
* base is derived from the Servant, also having a different name pattern
|
64 |
|
|
* (*POA.java). This suffix may be confusing, as the servant itself is
|
65 |
|
|
* <i>not</i> POA nor it is derived from it.
|
66 |
|
|
* </p><p>
|
67 |
|
|
* In both cases, the implementation base also inherits an interface, containing
|
68 |
|
|
* definitions of the application specific methods. The application programmer
|
69 |
|
|
* writes a child of the implementation base, implementing these methods
|
70 |
|
|
* for the application-specific functionality. The ObjectImpl is connected
|
71 |
|
|
* directly to the ORB. The Servant is connected to POA that can be obtained
|
72 |
|
|
* from the ORB.
|
73 |
|
|
* </p><p>
|
74 |
|
|
* If the servant is connected to more than one object, the exact object
|
75 |
|
|
* being currently served can be identified with {@link #_object_id}.
|
76 |
|
|
* </p><p>
|
77 |
|
|
* The derivativ of Servant, being directly connected to serve requests,
|
78 |
|
|
* must inherit either from {@link org.omg.CORBA.portable.InvokeHandler}
|
79 |
|
|
* or from {@link org.omg.PortableServer.DynamicImplementation}).
|
80 |
|
|
* </p><p>
|
81 |
|
|
* The Servant type is a CORBA <code>native</code> type.
|
82 |
|
|
* </p>
|
83 |
|
|
*
|
84 |
|
|
* @see POA#servant_to_reference(Servant)
|
85 |
|
|
*
|
86 |
|
|
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
87 |
|
|
*/
|
88 |
|
|
public abstract class Servant
|
89 |
|
|
{
|
90 |
|
|
/**
|
91 |
|
|
* The delegate, where calls to some Servant methods are forwarded.
|
92 |
|
|
*/
|
93 |
|
|
private Delegate delegate;
|
94 |
|
|
|
95 |
|
|
/**
|
96 |
|
|
* Get the repository ids of all interfaces, supported by the
|
97 |
|
|
* CORBA object, identified by the passed Id. In the typical code the
|
98 |
|
|
* passed parameters are ignored, returning an array of repository ids,
|
99 |
|
|
* supported by the servant implementation.
|
100 |
|
|
*
|
101 |
|
|
* @param poa a POA of the given object.
|
102 |
|
|
* @param object_ID the object Id of the given object.
|
103 |
|
|
*
|
104 |
|
|
* @return an array, containing the repository ids.
|
105 |
|
|
*/
|
106 |
|
|
public abstract String[] _all_interfaces(POA poa, byte[] object_ID);
|
107 |
|
|
|
108 |
|
|
/**
|
109 |
|
|
* Get the delegate, where calls to some Servant methods are forwarded.
|
110 |
|
|
*/
|
111 |
|
|
public final Delegate _get_delegate()
|
112 |
|
|
{
|
113 |
|
|
if (delegate == null) {
|
114 |
|
|
throw new BAD_INV_ORDER
|
115 |
|
|
("The Servant has not been associated with an ORBinstance");
|
116 |
|
|
}
|
117 |
|
|
return delegate;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
/**
|
121 |
|
|
* Get the interface repository definition <code>InterfaceDef</code> for this
|
122 |
|
|
* Object. By default, forwards request to the delegate.
|
123 |
|
|
*
|
124 |
|
|
* @specnote The interface repository is officially not implemented up till
|
125 |
|
|
* JDK 1.5 inclusive. The delegate throws NO_IMPLEMENT, always.
|
126 |
|
|
*/
|
127 |
|
|
public org.omg.CORBA.Object _get_interface_def()
|
128 |
|
|
{
|
129 |
|
|
throw new NO_IMPLEMENT();
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
/**
|
133 |
|
|
* Checks if the passed servant is an instance of the given CORBA IDL type.
|
134 |
|
|
* By default, forwards the requet to the delegate.
|
135 |
|
|
*
|
136 |
|
|
* @param repository_id a repository ID, representing an IDL type for that the
|
137 |
|
|
* servant must be checked.
|
138 |
|
|
*
|
139 |
|
|
* @return true if the servant is an instance of the given type, false
|
140 |
|
|
* otherwise.
|
141 |
|
|
*/
|
142 |
|
|
public boolean _is_a(String repository_id)
|
143 |
|
|
{
|
144 |
|
|
return delegate.is_a(this, repository_id);
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
/**
|
148 |
|
|
* Determines if the server object for this reference has already
|
149 |
|
|
* been destroyed. By default, forwards request to the delegate.
|
150 |
|
|
*
|
151 |
|
|
* @return true if the object has been destroyed, false otherwise.
|
152 |
|
|
*/
|
153 |
|
|
public boolean _non_existent()
|
154 |
|
|
{
|
155 |
|
|
return delegate.non_existent(this);
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
/**
|
159 |
|
|
* Returns the ORB that is directly associated with the given servant.
|
160 |
|
|
* In this implementation, the method is overridden to return
|
161 |
|
|
*/
|
162 |
|
|
public final ORB _orb()
|
163 |
|
|
{
|
164 |
|
|
return delegate.orb(this);
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
/**
|
168 |
|
|
* Returns the root POA of the ORB instance, associated with this servant.
|
169 |
|
|
* It is the same POA that would be returned by resolving the initial
|
170 |
|
|
* reference "RootPOA" for that orb. By default, forwards request to the
|
171 |
|
|
* delegate.
|
172 |
|
|
*
|
173 |
|
|
* @see ORB#resolve_initial_references
|
174 |
|
|
*/
|
175 |
|
|
public POA _default_POA()
|
176 |
|
|
{
|
177 |
|
|
return delegate == null ? null : delegate.default_POA(this);
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
/**
|
181 |
|
|
* Return the invocation target object identifier as a byte array.
|
182 |
|
|
* This is typically used when the same servant serves multiple objects,
|
183 |
|
|
* and the object id can encapsulated the whole description of the
|
184 |
|
|
* object.
|
185 |
|
|
*
|
186 |
|
|
* This method returns correct values even when the same
|
187 |
|
|
* servant serves several objects in parallel threads. The ORB maintains the
|
188 |
|
|
* thread to invocation data map for all calls that are currently being
|
189 |
|
|
* processed.
|
190 |
|
|
*/
|
191 |
|
|
public final byte[] _object_id()
|
192 |
|
|
{
|
193 |
|
|
if (delegate != null)
|
194 |
|
|
return delegate.object_id(this);
|
195 |
|
|
else
|
196 |
|
|
throw new OBJECT_NOT_EXIST();
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
/**
|
200 |
|
|
* Get POA that is directly associated with the given servant.
|
201 |
|
|
* By default, forwards request to the delegate.
|
202 |
|
|
*/
|
203 |
|
|
public final POA _poa()
|
204 |
|
|
{
|
205 |
|
|
return delegate.poa(this);
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
/**
|
209 |
|
|
* Set the delegate for this servant.
|
210 |
|
|
*/
|
211 |
|
|
public final void _set_delegate(Delegate a_delegate)
|
212 |
|
|
{
|
213 |
|
|
delegate = a_delegate;
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
/**
|
217 |
|
|
* Obtains the CORBA object reference that is a current invocation target for
|
218 |
|
|
* the given servant. This is important when the same servant serves
|
219 |
|
|
* multiple objects. If the servant is not yet connected to the passed
|
220 |
|
|
* orb, the method will try to connect it to that orb on POA, returned
|
221 |
|
|
* by the method {@link #_default_POA}. That method can be overridden to
|
222 |
|
|
* get poa where the object must be automatically connected when
|
223 |
|
|
* calling this method.
|
224 |
|
|
*
|
225 |
|
|
* @param an_orb the ORB with relate to that the object is requested.
|
226 |
|
|
*/
|
227 |
|
|
public final org.omg.CORBA.Object _this_object(ORB an_orb)
|
228 |
|
|
{
|
229 |
|
|
if (delegate != null)
|
230 |
|
|
return delegate.this_object(this);
|
231 |
|
|
else
|
232 |
|
|
{
|
233 |
|
|
if (an_orb instanceof ORB_1_4)
|
234 |
|
|
{
|
235 |
|
|
ORB_1_4 m_orb = (ORB_1_4) an_orb;
|
236 |
|
|
|
237 |
|
|
gnuPOA dp = (gnuPOA) _default_POA();
|
238 |
|
|
if (dp == null)
|
239 |
|
|
dp = m_orb.rootPOA;
|
240 |
|
|
|
241 |
|
|
try
|
242 |
|
|
{
|
243 |
|
|
return dp.servant_to_reference(this);
|
244 |
|
|
}
|
245 |
|
|
catch (WrongPolicy unexp)
|
246 |
|
|
{
|
247 |
|
|
BAD_OPERATION bad = new BAD_OPERATION();
|
248 |
|
|
bad.minor = Minor.Policy;
|
249 |
|
|
bad.initCause(unexp);
|
250 |
|
|
throw bad;
|
251 |
|
|
}
|
252 |
|
|
catch (ServantNotActive ex)
|
253 |
|
|
{
|
254 |
|
|
try
|
255 |
|
|
{
|
256 |
|
|
return dp.id_to_reference(dp.activate_object(this));
|
257 |
|
|
}
|
258 |
|
|
catch (Exception unexp)
|
259 |
|
|
{
|
260 |
|
|
unexp.initCause(ex);
|
261 |
|
|
|
262 |
|
|
BAD_OPERATION bad = new BAD_OPERATION();
|
263 |
|
|
bad.minor = Minor.Activation;
|
264 |
|
|
bad.initCause(unexp);
|
265 |
|
|
throw bad;
|
266 |
|
|
}
|
267 |
|
|
}
|
268 |
|
|
}
|
269 |
|
|
}
|
270 |
|
|
throw new OBJECT_NOT_EXIST();
|
271 |
|
|
}
|
272 |
|
|
|
273 |
|
|
/**
|
274 |
|
|
* Obtains the CORBA object reference that is a current invocation target for
|
275 |
|
|
* the given servant. This is important when the same servant serves
|
276 |
|
|
* multiple objects. This method required the servant to be connected
|
277 |
|
|
* to a single orb, and a delegate set.
|
278 |
|
|
*
|
279 |
|
|
* This method returns correct values even when the same
|
280 |
|
|
* servant serves several objects in parallel threads. The ORB maintains the
|
281 |
|
|
* thread to invocation data map for all calls that are currently being
|
282 |
|
|
* processed.
|
283 |
|
|
*/
|
284 |
|
|
public final org.omg.CORBA.Object _this_object()
|
285 |
|
|
{
|
286 |
|
|
if (delegate != null)
|
287 |
|
|
return _this_object(_orb());
|
288 |
|
|
else
|
289 |
|
|
{
|
290 |
|
|
POA def = _default_POA();
|
291 |
|
|
if (def instanceof gnuPOA)
|
292 |
|
|
return _this_object(((gnuPOA) def).orb());
|
293 |
|
|
}
|
294 |
|
|
throw new OBJECT_NOT_EXIST();
|
295 |
|
|
}
|
296 |
|
|
}
|