_NamingContextExtStub.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* _NamingContextExtStub.java --
  2. Copyright (C) 2005, 2006 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package org.omg.CosNaming;
  32. import gnu.CORBA.NamingService.NameTransformer;
  33. import org.omg.CORBA.MARSHAL;
  34. import org.omg.CORBA.ObjectHelper;
  35. import org.omg.CORBA.portable.ApplicationException;
  36. import org.omg.CORBA.portable.Delegate;
  37. import org.omg.CORBA.portable.InputStream;
  38. import org.omg.CORBA.portable.OutputStream;
  39. import org.omg.CORBA.portable.RemarshalException;
  40. import org.omg.CosNaming.NamingContextExtPackage.AddressHelper;
  41. import org.omg.CosNaming.NamingContextExtPackage.InvalidAddress;
  42. import org.omg.CosNaming.NamingContextExtPackage.InvalidAddressHelper;
  43. import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
  44. import org.omg.CosNaming.NamingContextExtPackage.URLStringHelper;
  45. import org.omg.CosNaming.NamingContextPackage.CannotProceed;
  46. import org.omg.CosNaming.NamingContextPackage.InvalidName;
  47. import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper;
  48. import org.omg.CosNaming.NamingContextPackage.NotFound;
  49. /**
  50. * The extended naming context stub (proxy), used on the client side.
  51. * The most of the {@link NamingContextExt} methods contain the code
  52. * for remote invocaton. However as remote invocation is potencially an
  53. * expensive step, some trivial methods, not requiring access to the
  54. * naming database, are handled locally (see the method descriptions for
  55. * details).
  56. *
  57. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  58. */
  59. public class _NamingContextExtStub
  60. extends _NamingContextStub
  61. implements NamingContextExt
  62. {
  63. /**
  64. * Use serialVersionUID (v1.4) for interoperability.
  65. */
  66. private static final long serialVersionUID = 6333293895664182866L;
  67. /**
  68. * This stub can be the base of the two CORBA objects, so it
  69. * has two repository ids.
  70. */
  71. private static String[] __ids =
  72. { NamingContextExtHelper.id(), NamingContextHelper.id() };
  73. /**
  74. * The local name form converter.
  75. */
  76. private NameTransformer converter = new NameTransformer();
  77. /**
  78. * Create the naming context stub.
  79. */
  80. public _NamingContextExtStub()
  81. {
  82. super();
  83. }
  84. /**
  85. * Create the naming context stub with the given delegate.
  86. */
  87. _NamingContextExtStub(Delegate delegate)
  88. {
  89. super(delegate);
  90. }
  91. /**
  92. * Return the array of repository ids for this object.
  93. * This stub can be the base of the two CORBA objects, so it
  94. * has two repository ids, for {@link NamingContext} and
  95. * for {@link NamingContextExt}.
  96. */
  97. public String[] _ids()
  98. {
  99. return (String[]) __ids.clone();
  100. }
  101. /** {@inheritDoc} */
  102. public org.omg.CORBA.Object resolve_str(String a_name_string)
  103. throws NotFound, CannotProceed, InvalidName
  104. {
  105. InputStream in = null;
  106. try
  107. {
  108. OutputStream _out = _request("resolve_str", true);
  109. StringNameHelper.write(_out, a_name_string);
  110. in = _invoke(_out);
  111. return ObjectHelper.read(in);
  112. }
  113. catch (ApplicationException ex)
  114. {
  115. in = ex.getInputStream();
  116. String id = ex.getId();
  117. throw4(in, id);
  118. // Should never happen.
  119. throw new InternalError();
  120. }
  121. catch (RemarshalException _rm)
  122. {
  123. return resolve_str(a_name_string);
  124. }
  125. finally
  126. {
  127. _releaseReply(in);
  128. }
  129. }
  130. /**
  131. * Converts the string name representation into the array
  132. * name representation.
  133. *
  134. * This method is handled locally.
  135. */
  136. public NameComponent[] to_name(String a_name_string)
  137. throws InvalidName
  138. {
  139. return converter.toName(a_name_string);
  140. }
  141. /**
  142. * Convert the name array representation to the name string
  143. * representation.
  144. *
  145. * This method is handled locally.
  146. */
  147. public String to_string(NameComponent[] a_name)
  148. throws InvalidName
  149. {
  150. return converter.toString(a_name);
  151. }
  152. /** {@inheritDoc} */
  153. public String to_url(String an_address, String a_name_string)
  154. throws InvalidAddress, InvalidName
  155. {
  156. InputStream in = null;
  157. try
  158. {
  159. OutputStream _out = _request("to_url", true);
  160. AddressHelper.write(_out, an_address);
  161. StringNameHelper.write(_out, a_name_string);
  162. in = _invoke(_out);
  163. return URLStringHelper.read(in);
  164. }
  165. catch (ApplicationException ex)
  166. {
  167. in = ex.getInputStream();
  168. String id = ex.getId();
  169. if (id.equals(InvalidAddressHelper.id()))
  170. throw InvalidAddressHelper.read(in);
  171. else if (id.equals(InvalidNameHelper.id()))
  172. throw InvalidNameHelper.read(in);
  173. else
  174. throw new MARSHAL(id);
  175. }
  176. catch (RemarshalException _rm)
  177. {
  178. return to_url(an_address, a_name_string);
  179. }
  180. finally
  181. {
  182. _releaseReply(in);
  183. }
  184. }
  185. }