1 /* _NamingContextStub.java --
2 Copyright (C) 2005, 2006 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.CosNaming;
41 import org.omg.CORBA.MARSHAL;
42 import org.omg.CORBA.ObjectHelper;
43 import org.omg.CORBA.portable.ApplicationException;
44 import org.omg.CORBA.portable.Delegate;
45 import org.omg.CORBA.portable.InputStream;
46 import org.omg.CORBA.portable.ObjectImpl;
47 import org.omg.CORBA.portable.OutputStream;
48 import org.omg.CORBA.portable.RemarshalException;
49 import org.omg.CosNaming.NamingContextPackage.AlreadyBound;
50 import org.omg.CosNaming.NamingContextPackage.AlreadyBoundHelper;
51 import org.omg.CosNaming.NamingContextPackage.CannotProceed;
52 import org.omg.CosNaming.NamingContextPackage.CannotProceedHelper;
53 import org.omg.CosNaming.NamingContextPackage.InvalidName;
54 import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper;
55 import org.omg.CosNaming.NamingContextPackage.NotEmpty;
56 import org.omg.CosNaming.NamingContextPackage.NotEmptyHelper;
57 import org.omg.CosNaming.NamingContextPackage.NotFound;
58 import org.omg.CosNaming.NamingContextPackage.NotFoundHelper;
61 * The naming context stub (proxy), used on the client side.
62 * The {@link NamingContext} methods contain the code for remote
65 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
67 public class _NamingContextStub
69 implements NamingContext
72 * Use serialVersionUID (v1.4) for interoperability.
74 private static final long serialVersionUID = 6835430958405349379L;
77 * Create the naming context stub.
79 public _NamingContextStub()
85 * Create the naming context stub with the given delegate.
87 _NamingContextStub(Delegate delegate)
90 _set_delegate(delegate);
94 * Return the array of repository ids for this object.
96 public String[] _ids()
98 return new String[] { NamingContextHelper.id() };
102 public void bind(NameComponent[] a_name, org.omg.CORBA.Object an_object)
103 throws NotFound, CannotProceed, InvalidName, AlreadyBound
105 InputStream in = null;
108 OutputStream out = _request("bind", true);
109 NameHelper.write(out, a_name);
110 ObjectHelper.write(out, an_object);
113 catch (ApplicationException ex)
115 in = ex.getInputStream();
117 String id = ex.getId();
120 catch (RemarshalException remarsh)
122 bind(a_name, an_object);
131 public void bind_context(NameComponent[] a_name, NamingContext a_context)
132 throws NotFound, CannotProceed, InvalidName, AlreadyBound
134 InputStream in = null;
137 OutputStream out = _request("bind_context", true);
138 NameHelper.write(out, a_name);
139 NamingContextHelper.write(out, a_context);
142 catch (ApplicationException ex)
144 in = ex.getInputStream();
146 String id = ex.getId();
149 catch (RemarshalException remarsh)
151 bind_context(a_name, a_context);
160 public NamingContext bind_new_context(NameComponent[] a_name)
161 throws NotFound, AlreadyBound, CannotProceed,
164 InputStream in = null;
167 OutputStream out = _request("bind_new_context", true);
168 NameHelper.write(out, a_name);
171 NamingContext __result = NamingContextHelper.read(in);
174 catch (ApplicationException ex)
176 in = ex.getInputStream();
178 String id = ex.getId();
180 throw new InternalError();
182 catch (RemarshalException remarsh)
184 return bind_new_context(a_name);
193 public void destroy()
196 InputStream in = null;
199 OutputStream out = _request("destroy", true);
202 catch (ApplicationException ex)
204 in = ex.getInputStream();
206 String id = ex.getId();
207 if (id.equals(NotEmptyHelper.id()))
208 throw NotEmptyHelper.read(in);
210 throw new MARSHAL(id);
212 catch (RemarshalException remarsh)
223 public void list(int amount, BindingListHolder a_list,
224 BindingIteratorHolder an_iter
227 InputStream in = null;
230 OutputStream out = _request("list", true);
231 out.write_ulong(amount);
233 a_list.value = BindingListHelper.read(in);
234 an_iter.value = BindingIteratorHelper.read(in);
236 catch (ApplicationException ex)
238 in = ex.getInputStream();
239 throw new MARSHAL(ex.getId());
241 catch (RemarshalException remarsh)
243 list(amount, a_list, an_iter);
252 public NamingContext new_context()
254 InputStream in = null;
257 OutputStream out = _request("new_context", true);
260 NamingContext __result = NamingContextHelper.read(in);
263 catch (ApplicationException ex)
265 in = ex.getInputStream();
266 throw new MARSHAL(ex.getId());
268 catch (RemarshalException remarsh)
270 return new_context();
279 public void rebind(NameComponent[] a_name, org.omg.CORBA.Object an_object)
280 throws NotFound, CannotProceed, InvalidName
282 InputStream in = null;
285 OutputStream out = _request("rebind", true);
286 NameHelper.write(out, a_name);
287 ObjectHelper.write(out, an_object);
290 catch (ApplicationException ex)
292 in = ex.getInputStream();
294 String id = ex.getId();
297 catch (RemarshalException remarsh)
299 rebind(a_name, an_object);
308 public void rebind_context(NameComponent[] a_name, NamingContext a_context)
309 throws NotFound, CannotProceed, InvalidName
311 InputStream in = null;
314 OutputStream out = _request("rebind_context", true);
315 NameHelper.write(out, a_name);
316 NamingContextHelper.write(out, a_context);
319 catch (ApplicationException ex)
321 in = ex.getInputStream();
323 String id = ex.getId();
326 catch (RemarshalException remarsh)
328 rebind_context(a_name, a_context);
337 public org.omg.CORBA.Object resolve(NameComponent[] a_name)
338 throws NotFound, CannotProceed, InvalidName
340 InputStream in = null;
343 OutputStream out = _request("resolve", true);
344 NameHelper.write(out, a_name);
347 org.omg.CORBA.Object __result = ObjectHelper.read(in);
350 catch (ApplicationException ex)
352 in = ex.getInputStream();
354 String id = ex.getId();
356 throw new InternalError();
358 catch (RemarshalException remarsh)
360 return resolve(a_name);
369 public void unbind(NameComponent[] a_name)
370 throws NotFound, CannotProceed, InvalidName
372 InputStream in = null;
375 OutputStream out = _request("unbind", true);
376 NameHelper.write(out, a_name);
379 catch (ApplicationException ex)
381 in = ex.getInputStream();
383 String id = ex.getId();
384 if (id.equals(NotFoundHelper.id()))
385 throw NotFoundHelper.read(in);
386 else if (id.equals(CannotProceedHelper.id()))
387 throw CannotProceedHelper.read(in);
388 else if (id.equals(InvalidNameHelper.id()))
389 throw InvalidNameHelper.read(in);
391 throw new MARSHAL(id);
393 catch (RemarshalException remarsh)
404 * Throw one of the three possible exceptions, as specified in
405 * the passed exception repository id.
407 * This method should never return normally.
409 * @param in the stream to read the exception from.
410 * @param id the exception id.
412 * @throws InvalidName if the id matches.
413 * @throws CannotProceed if the id matches.
414 * @throws NotFound if the id matches.
415 * @throws MARSHAL if the id does not match any of the previous 4 exceptions.
417 void throw4(InputStream in, String id)
418 throws MARSHAL, InvalidName, CannotProceed, NotFound
420 if (id.equals(NotFoundHelper.id()))
421 throw NotFoundHelper.read(in);
422 else if (id.equals(CannotProceedHelper.id()))
423 throw CannotProceedHelper.read(in);
424 else if (id.equals(InvalidNameHelper.id()))
425 throw InvalidNameHelper.read(in);
427 throw new MARSHAL(id);
431 * Throw one of the five possible exceptions, as specified in
432 * the passed exception repository id.
434 * This method should never return normally.
436 * @param in the stream to read the exception from.
437 * @param id the exception id.
439 * @throws AlreadyBound if the id matches.
440 * @throws InvalidName if the id matches.
441 * @throws CannotProceed if the id matches.
442 * @throws NotFound if the id matches.
443 * @throws MARSHAL if the id does not match any of the previous 4 exceptions.
445 void throw5(InputStream in, String id)
446 throws MARSHAL, AlreadyBound, InvalidName, CannotProceed,
449 if (id.equals(AlreadyBoundHelper.id()))
450 throw AlreadyBoundHelper.read(in);