2 Copyright (C) 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 org.omg.PortableServer;
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;
50 import gnu.CORBA.Minor;
51 import gnu.CORBA.Poa.ORB_1_4;
52 import gnu.CORBA.Poa.gnuPOA;
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.
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.
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
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}.
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}).
81 * The Servant type is a CORBA <code>native</code> type.
84 * @see POA#servant_to_reference(Servant)
86 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
88 public abstract class Servant
91 * The delegate, where calls to some Servant methods are forwarded.
93 private Delegate delegate;
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.
101 * @param poa a POA of the given object.
102 * @param object_ID the object Id of the given object.
104 * @return an array, containing the repository ids.
106 public abstract String[] _all_interfaces(POA poa, byte[] object_ID);
109 * Get the delegate, where calls to some Servant methods are forwarded.
111 public final Delegate _get_delegate()
113 if (delegate == null) {
114 throw new BAD_INV_ORDER
115 ("The Servant has not been associated with an ORBinstance");
121 * Get the interface repository definition <code>InterfaceDef</code> for this
122 * Object. By default, forwards request to the delegate.
124 * @specnote The interface repository is officially not implemented up till
125 * JDK 1.5 inclusive. The delegate throws NO_IMPLEMENT, always.
127 public org.omg.CORBA.Object _get_interface_def()
129 throw new NO_IMPLEMENT();
133 * Checks if the passed servant is an instance of the given CORBA IDL type.
134 * By default, forwards the requet to the delegate.
136 * @param repository_id a repository ID, representing an IDL type for that the
137 * servant must be checked.
139 * @return true if the servant is an instance of the given type, false
142 public boolean _is_a(String repository_id)
144 return delegate.is_a(this, repository_id);
148 * Determines if the server object for this reference has already
149 * been destroyed. By default, forwards request to the delegate.
151 * @return true if the object has been destroyed, false otherwise.
153 public boolean _non_existent()
155 return delegate.non_existent(this);
159 * Returns the ORB that is directly associated with the given servant.
160 * In this implementation, the method is overridden to return
162 public final ORB _orb()
164 return delegate.orb(this);
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
173 * @see ORB#resolve_initial_references
175 public POA _default_POA()
177 return delegate == null ? null : delegate.default_POA(this);
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
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
191 public final byte[] _object_id()
193 if (delegate != null)
194 return delegate.object_id(this);
196 throw new OBJECT_NOT_EXIST();
200 * Get POA that is directly associated with the given servant.
201 * By default, forwards request to the delegate.
203 public final POA _poa()
205 return delegate.poa(this);
209 * Set the delegate for this servant.
211 public final void _set_delegate(Delegate a_delegate)
213 delegate = a_delegate;
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.
225 * @param an_orb the ORB with relate to that the object is requested.
227 public final org.omg.CORBA.Object _this_object(ORB an_orb)
229 if (delegate != null)
230 return delegate.this_object(this);
233 if (an_orb instanceof ORB_1_4)
235 ORB_1_4 m_orb = (ORB_1_4) an_orb;
237 gnuPOA dp = (gnuPOA) _default_POA();
243 return dp.servant_to_reference(this);
245 catch (WrongPolicy unexp)
247 BAD_OPERATION bad = new BAD_OPERATION();
248 bad.minor = Minor.Policy;
249 bad.initCause(unexp);
252 catch (ServantNotActive ex)
256 return dp.id_to_reference(dp.activate_object(this));
258 catch (Exception unexp)
262 BAD_OPERATION bad = new BAD_OPERATION();
263 bad.minor = Minor.Activation;
264 bad.initCause(unexp);
270 throw new OBJECT_NOT_EXIST();
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.
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
284 public final org.omg.CORBA.Object _this_object()
286 if (delegate != null)
287 return _this_object(_orb());
290 POA def = _default_POA();
291 if (def instanceof gnuPOA)
292 return _this_object(((gnuPOA) def).orb());
294 throw new OBJECT_NOT_EXIST();