001 /* NamingContextPOA.java --
002 Copyright (C) 2005 Free Software Foundation, Inc.
003
004 This file is part of GNU Classpath.
005
006 GNU Classpath is free software; you can redistribute it and/or modify
007 it under the terms of the GNU General Public License as published by
008 the Free Software Foundation; either version 2, or (at your option)
009 any later version.
010
011 GNU Classpath is distributed in the hope that it will be useful, but
012 WITHOUT ANY WARRANTY; without even the implied warranty of
013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 General Public License for more details.
015
016 You should have received a copy of the GNU General Public License
017 along with GNU Classpath; see the file COPYING. If not, write to the
018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019 02110-1301 USA.
020
021 Linking this library statically or dynamically with other modules is
022 making a combined work based on this library. Thus, the terms and
023 conditions of the GNU General Public License cover the whole
024 combination.
025
026 As a special exception, the copyright holders of this library give you
027 permission to link this library with independent modules to produce an
028 executable, regardless of the license terms of these independent
029 modules, and to copy and distribute the resulting executable under
030 terms of your choice, provided that you also meet, for each linked
031 independent module, the terms and conditions of the license of that
032 module. An independent module is a module which is not derived from
033 or based on this library. If you modify this library, you may extend
034 this exception to your version of the library, but you are not
035 obligated to do so. If you do not wish to do so, delete this
036 exception statement from your version. */
037
038
039 package org.omg.CosNaming;
040
041 import gnu.CORBA.Minor;
042
043 import org.omg.CORBA.BAD_OPERATION;
044 import org.omg.CORBA.CompletionStatus;
045 import org.omg.CORBA.ObjectHelper;
046 import org.omg.CORBA.portable.InputStream;
047 import org.omg.CORBA.portable.InvokeHandler;
048 import org.omg.CORBA.portable.OutputStream;
049 import org.omg.CORBA.portable.ResponseHandler;
050 import org.omg.CosNaming.NamingContextPackage.AlreadyBound;
051 import org.omg.CosNaming.NamingContextPackage.AlreadyBoundHelper;
052 import org.omg.CosNaming.NamingContextPackage.CannotProceed;
053 import org.omg.CosNaming.NamingContextPackage.CannotProceedHelper;
054 import org.omg.CosNaming.NamingContextPackage.InvalidName;
055 import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper;
056 import org.omg.CosNaming.NamingContextPackage.NotEmpty;
057 import org.omg.CosNaming.NamingContextPackage.NotEmptyHelper;
058 import org.omg.CosNaming.NamingContextPackage.NotFound;
059 import org.omg.CosNaming.NamingContextPackage.NotFoundHelper;
060 import org.omg.PortableServer.POA;
061 import org.omg.PortableServer.Servant;
062
063 /**
064 * The naming service servant. After implementing the abstract methods the
065 * instance of this class can be connected to an ORB using POA.
066 *
067 * @since 1.4
068 *
069 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
070 */
071 public abstract class NamingContextPOA
072 extends Servant
073 implements NamingContextOperations, InvokeHandler
074 {
075 /** @inheritDoc */
076 public String[] _all_interfaces(POA poa, byte[] object_ID)
077 {
078 return new String[] { NamingContextHelper.id() };
079 }
080
081 /**
082 * The server calls this method after receiving the request message from
083 * client. The implementation base calls one of its abstract methods to
084 * perform the requested operation.
085 *
086 * @param method the method being invoked.
087 * @param in the stream to read parameters from.
088 * @param rh the handler to get a stream for writing a response.
089 *
090 * @return the stream, returned by the handler.
091 */
092 public OutputStream _invoke(String method, InputStream in, ResponseHandler rh)
093 {
094 OutputStream out = null;
095 Integer call_method = _NamingContextImplBase.methods.get(method);
096 if (call_method == null)
097 throw new BAD_OPERATION(Minor.Method, CompletionStatus.COMPLETED_MAYBE);
098
099 switch (call_method.intValue())
100 {
101 case 0: // bind
102 {
103 try
104 {
105 NameComponent[] a_name = NameHelper.read(in);
106 org.omg.CORBA.Object an_object = ObjectHelper.read(in);
107 bind(a_name, an_object);
108 out = rh.createReply();
109 }
110 catch (NotFound ex)
111 {
112 out = rh.createExceptionReply();
113 NotFoundHelper.write(out, ex);
114 }
115 catch (CannotProceed ex)
116 {
117 out = rh.createExceptionReply();
118 CannotProceedHelper.write(out, ex);
119 }
120 catch (InvalidName ex)
121 {
122 out = rh.createExceptionReply();
123 InvalidNameHelper.write(out, ex);
124 }
125 catch (AlreadyBound ex)
126 {
127 out = rh.createExceptionReply();
128 AlreadyBoundHelper.write(out, ex);
129 }
130 break;
131 }
132
133 case 1: // rebind
134 {
135 try
136 {
137 NameComponent[] a_name = NameHelper.read(in);
138 org.omg.CORBA.Object an_object = ObjectHelper.read(in);
139 rebind(a_name, an_object);
140 out = rh.createReply();
141 }
142 catch (NotFound ex)
143 {
144 out = rh.createExceptionReply();
145 NotFoundHelper.write(out, ex);
146 }
147 catch (CannotProceed ex)
148 {
149 out = rh.createExceptionReply();
150 CannotProceedHelper.write(out, ex);
151 }
152 catch (InvalidName ex)
153 {
154 out = rh.createExceptionReply();
155 InvalidNameHelper.write(out, ex);
156 }
157 break;
158 }
159
160 case 2: // bind_context
161 {
162 try
163 {
164 NameComponent[] a_name = NameHelper.read(in);
165 NamingContext a_context = NamingContextHelper.read(in);
166 bind_context(a_name, a_context);
167 out = rh.createReply();
168 }
169 catch (NotFound ex)
170 {
171 out = rh.createExceptionReply();
172 NotFoundHelper.write(out, ex);
173 }
174 catch (CannotProceed ex)
175 {
176 out = rh.createExceptionReply();
177 CannotProceedHelper.write(out, ex);
178 }
179 catch (InvalidName ex)
180 {
181 out = rh.createExceptionReply();
182 InvalidNameHelper.write(out, ex);
183 }
184 catch (AlreadyBound ex)
185 {
186 out = rh.createExceptionReply();
187 AlreadyBoundHelper.write(out, ex);
188 }
189 break;
190 }
191
192 case 3: // rebind_context
193 {
194 try
195 {
196 NameComponent[] a_name = NameHelper.read(in);
197 NamingContext a_context = NamingContextHelper.read(in);
198 rebind_context(a_name, a_context);
199 out = rh.createReply();
200 }
201 catch (NotFound ex)
202 {
203 out = rh.createExceptionReply();
204 NotFoundHelper.write(out, ex);
205 }
206 catch (CannotProceed ex)
207 {
208 out = rh.createExceptionReply();
209 CannotProceedHelper.write(out, ex);
210 }
211 catch (InvalidName ex)
212 {
213 out = rh.createExceptionReply();
214 InvalidNameHelper.write(out, ex);
215 }
216 break;
217 }
218
219 case 4: // resolve
220 {
221 try
222 {
223 NameComponent[] a_name = NameHelper.read(in);
224 org.omg.CORBA.Object __result = null;
225 __result = resolve(a_name);
226 out = rh.createReply();
227 ObjectHelper.write(out, __result);
228 }
229 catch (NotFound ex)
230 {
231 out = rh.createExceptionReply();
232 NotFoundHelper.write(out, ex);
233 }
234 catch (CannotProceed ex)
235 {
236 out = rh.createExceptionReply();
237 CannotProceedHelper.write(out, ex);
238 }
239 catch (InvalidName ex)
240 {
241 out = rh.createExceptionReply();
242 InvalidNameHelper.write(out, ex);
243 }
244 break;
245 }
246
247 case 5: // unbind
248 {
249 try
250 {
251 NameComponent[] a_name = NameHelper.read(in);
252 unbind(a_name);
253 out = rh.createReply();
254 }
255 catch (NotFound ex)
256 {
257 out = rh.createExceptionReply();
258 NotFoundHelper.write(out, ex);
259 }
260 catch (CannotProceed ex)
261 {
262 out = rh.createExceptionReply();
263 CannotProceedHelper.write(out, ex);
264 }
265 catch (InvalidName ex)
266 {
267 out = rh.createExceptionReply();
268 InvalidNameHelper.write(out, ex);
269 }
270 break;
271 }
272
273 case 6: // new_context
274 {
275 NamingContext __result = null;
276 __result = new_context();
277 out = rh.createReply();
278 NamingContextHelper.write(out, __result);
279 break;
280 }
281
282 case 7: // bind_new_context
283 {
284 try
285 {
286 NameComponent[] a_name = NameHelper.read(in);
287 NamingContext __result = null;
288 __result = bind_new_context(a_name);
289 out = rh.createReply();
290 NamingContextHelper.write(out, __result);
291 }
292 catch (NotFound ex)
293 {
294 out = rh.createExceptionReply();
295 NotFoundHelper.write(out, ex);
296 }
297 catch (AlreadyBound ex)
298 {
299 out = rh.createExceptionReply();
300 AlreadyBoundHelper.write(out, ex);
301 }
302 catch (CannotProceed ex)
303 {
304 out = rh.createExceptionReply();
305 CannotProceedHelper.write(out, ex);
306 }
307 catch (InvalidName ex)
308 {
309 out = rh.createExceptionReply();
310 InvalidNameHelper.write(out, ex);
311 }
312 break;
313 }
314
315 case 8: // destroy
316 {
317 try
318 {
319 destroy();
320 out = rh.createReply();
321 }
322 catch (NotEmpty ex)
323 {
324 out = rh.createExceptionReply();
325 NotEmptyHelper.write(out, ex);
326 }
327 break;
328 }
329
330 case 9: // list
331 {
332 int amount = in.read_ulong();
333 BindingListHolder a_list = new BindingListHolder();
334 BindingIteratorHolder an_iter = new BindingIteratorHolder();
335 list(amount, a_list, an_iter);
336 out = rh.createReply();
337 BindingListHelper.write(out, a_list.value);
338 BindingIteratorHelper.write(out, an_iter.value);
339 break;
340 }
341
342 default:
343 throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
344 }
345
346 return out;
347 }
348
349 /**
350 * Get the CORBA object that delegates calls to this servant. The servant must
351 * be already connected to an ORB.
352 */
353 public NamingContext _this()
354 {
355 return NamingContextHelper.narrow(super._this_object());
356 }
357
358 /**
359 * Get the CORBA object that delegates calls to this servant. Connect to the
360 * given ORB, if needed.
361 */
362 public NamingContext _this(org.omg.CORBA.ORB orb)
363 {
364 return NamingContextHelper.narrow(super._this_object(orb));
365 }
366
367 }