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