_NamingContextExtImplBase.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* _NamingContextExtImplBase.java --
  2. Copyright (C) 2005 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 org.omg.CORBA.ObjectHolder;
  33. import org.omg.CORBA.ServerRequest;
  34. import org.omg.CORBA.StringHolder;
  35. import org.omg.CORBA.portable.InputStream;
  36. import org.omg.CORBA.portable.InvokeHandler;
  37. import org.omg.CORBA.portable.OutputStream;
  38. import org.omg.CORBA.portable.ResponseHandler;
  39. import org.omg.CORBA.portable.Streamable;
  40. import org.omg.CosNaming.NamingContextExtPackage.InvalidAddress;
  41. import org.omg.CosNaming.NamingContextExtPackage.InvalidAddressHelper;
  42. import org.omg.CosNaming.NamingContextPackage.CannotProceed;
  43. import org.omg.CosNaming.NamingContextPackage.CannotProceedHelper;
  44. import org.omg.CosNaming.NamingContextPackage.InvalidName;
  45. import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper;
  46. import org.omg.CosNaming.NamingContextPackage.NotFound;
  47. import org.omg.CosNaming.NamingContextPackage.NotFoundHelper;
  48. import java.util.Hashtable;
  49. /**
  50. * The extended naming context implementation base.
  51. *
  52. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  53. */
  54. public abstract class _NamingContextExtImplBase
  55. extends _NamingContextImplBase
  56. implements NamingContextExt, InvokeHandler
  57. {
  58. static Hashtable<String,Integer> _methods = new Hashtable<String,Integer>();
  59. static
  60. {
  61. _methods.put("to_string", new java.lang.Integer(0));
  62. _methods.put("to_name", new java.lang.Integer(1));
  63. _methods.put("to_url", new java.lang.Integer(2));
  64. _methods.put("resolve_str", new java.lang.Integer(3));
  65. }
  66. /**
  67. * This stub can be the base of the two CORBA objects, so it
  68. * has two repository ids.
  69. */
  70. private static String[] __ids =
  71. { NamingContextExtHelper.id(), NamingContextHelper.id() };
  72. /**
  73. * Return the array of repository ids for this object.
  74. * This stub can be the base of the two CORBA objects, so it
  75. * has two repository ids, for {@link NamingContext} and
  76. * for {@link NamingContextExt}.
  77. */
  78. public String[] _ids()
  79. {
  80. return __ids;
  81. }
  82. public OutputStream _invoke(String method, InputStream in, ResponseHandler rh)
  83. {
  84. Integer call_method = _methods.get(method);
  85. if (call_method == null)
  86. // The older methods are handled by the parent class.
  87. return super._invoke(method, in, rh);
  88. OutputStream out = null;
  89. switch (call_method.intValue())
  90. {
  91. case 0 : // to_string
  92. {
  93. try
  94. {
  95. NameComponent[] a_name = NameHelper.read(in);
  96. String result = null;
  97. result = this.to_string(a_name);
  98. out = rh.createReply();
  99. out.write_string(result);
  100. }
  101. catch (InvalidName ex)
  102. {
  103. out = rh.createExceptionReply();
  104. InvalidNameHelper.write(out, ex);
  105. }
  106. break;
  107. }
  108. case 1 : // to_name
  109. {
  110. try
  111. {
  112. String a_name_string = in.read_string();
  113. NameComponent[] result = to_name(a_name_string);
  114. out = rh.createReply();
  115. NameHelper.write(out, result);
  116. }
  117. catch (InvalidName ex)
  118. {
  119. out = rh.createExceptionReply();
  120. InvalidNameHelper.write(out, ex);
  121. }
  122. break;
  123. }
  124. case 2 : // to_url
  125. {
  126. try
  127. {
  128. String an_address = in.read_string();
  129. String a_name_string = in.read_string();
  130. String result = to_url(an_address, a_name_string);
  131. out = rh.createReply();
  132. out.write_string(result);
  133. }
  134. catch (InvalidAddress ex)
  135. {
  136. out = rh.createExceptionReply();
  137. InvalidAddressHelper.write(out, ex);
  138. }
  139. catch (InvalidName ex)
  140. {
  141. out = rh.createExceptionReply();
  142. InvalidNameHelper.write(out, ex);
  143. }
  144. break;
  145. }
  146. case 3 : // resolve_str
  147. {
  148. try
  149. {
  150. String a_name_string = in.read_string();
  151. org.omg.CORBA.Object result = resolve_str(a_name_string);
  152. out = rh.createReply();
  153. org.omg.CORBA.ObjectHelper.write(out, result);
  154. }
  155. catch (NotFound ex)
  156. {
  157. out = rh.createExceptionReply();
  158. NotFoundHelper.write(out, ex);
  159. }
  160. catch (CannotProceed ex)
  161. {
  162. out = rh.createExceptionReply();
  163. CannotProceedHelper.write(out, ex);
  164. }
  165. catch (InvalidName ex)
  166. {
  167. out = rh.createExceptionReply();
  168. InvalidNameHelper.write(out, ex);
  169. }
  170. break;
  171. }
  172. }
  173. return out;
  174. }
  175. /**
  176. * The obsolete invocation using server request. Implemented for
  177. * compatibility reasons, but is it more effectinve to use
  178. * {@link #_invoke}.
  179. *
  180. * @param request a server request.
  181. */
  182. public void invoke(ServerRequest request)
  183. {
  184. Streamable result = null;
  185. Integer call_method = _methods.get(request.operation());
  186. if (call_method == null)
  187. {
  188. super.invoke(request);
  189. return;
  190. }
  191. switch (call_method.intValue())
  192. {
  193. case 0 : // to_string, String
  194. result = new StringHolder();
  195. break;
  196. case 1 : // to_name, Name
  197. result = new NameHolder();
  198. break;
  199. case 2 : // to_url, String
  200. result = new StringHolder();
  201. break;
  202. case 3 : // resolve_str, Object
  203. result = new ObjectHolder();
  204. break;
  205. }
  206. gnu.CORBA.ServiceRequestAdapter.invoke(request, this, result);
  207. }
  208. }