NamingContextPOA.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /* NamingContextPOA.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 gnu.CORBA.Minor;
  33. import org.omg.CORBA.BAD_OPERATION;
  34. import org.omg.CORBA.CompletionStatus;
  35. import org.omg.CORBA.ObjectHelper;
  36. import org.omg.CORBA.portable.InputStream;
  37. import org.omg.CORBA.portable.InvokeHandler;
  38. import org.omg.CORBA.portable.OutputStream;
  39. import org.omg.CORBA.portable.ResponseHandler;
  40. import org.omg.CosNaming.NamingContextPackage.AlreadyBound;
  41. import org.omg.CosNaming.NamingContextPackage.AlreadyBoundHelper;
  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.NotEmpty;
  47. import org.omg.CosNaming.NamingContextPackage.NotEmptyHelper;
  48. import org.omg.CosNaming.NamingContextPackage.NotFound;
  49. import org.omg.CosNaming.NamingContextPackage.NotFoundHelper;
  50. import org.omg.PortableServer.POA;
  51. import org.omg.PortableServer.Servant;
  52. /**
  53. * The naming service servant. After implementing the abstract methods the
  54. * instance of this class can be connected to an ORB using POA.
  55. *
  56. * @since 1.4
  57. *
  58. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  59. */
  60. public abstract class NamingContextPOA
  61. extends Servant
  62. implements NamingContextOperations, InvokeHandler
  63. {
  64. /** @inheritDoc */
  65. public String[] _all_interfaces(POA poa, byte[] object_ID)
  66. {
  67. return new String[] { NamingContextHelper.id() };
  68. }
  69. /**
  70. * The server calls this method after receiving the request message from
  71. * client. The implementation base calls one of its abstract methods to
  72. * perform the requested operation.
  73. *
  74. * @param method the method being invoked.
  75. * @param in the stream to read parameters from.
  76. * @param rh the handler to get a stream for writing a response.
  77. *
  78. * @return the stream, returned by the handler.
  79. */
  80. public OutputStream _invoke(String method, InputStream in, ResponseHandler rh)
  81. {
  82. OutputStream out = null;
  83. Integer call_method = _NamingContextImplBase.methods.get(method);
  84. if (call_method == null)
  85. throw new BAD_OPERATION(Minor.Method, CompletionStatus.COMPLETED_MAYBE);
  86. switch (call_method.intValue())
  87. {
  88. case 0: // bind
  89. {
  90. try
  91. {
  92. NameComponent[] a_name = NameHelper.read(in);
  93. org.omg.CORBA.Object an_object = ObjectHelper.read(in);
  94. bind(a_name, an_object);
  95. out = rh.createReply();
  96. }
  97. catch (NotFound ex)
  98. {
  99. out = rh.createExceptionReply();
  100. NotFoundHelper.write(out, ex);
  101. }
  102. catch (CannotProceed ex)
  103. {
  104. out = rh.createExceptionReply();
  105. CannotProceedHelper.write(out, ex);
  106. }
  107. catch (InvalidName ex)
  108. {
  109. out = rh.createExceptionReply();
  110. InvalidNameHelper.write(out, ex);
  111. }
  112. catch (AlreadyBound ex)
  113. {
  114. out = rh.createExceptionReply();
  115. AlreadyBoundHelper.write(out, ex);
  116. }
  117. break;
  118. }
  119. case 1: // rebind
  120. {
  121. try
  122. {
  123. NameComponent[] a_name = NameHelper.read(in);
  124. org.omg.CORBA.Object an_object = ObjectHelper.read(in);
  125. rebind(a_name, an_object);
  126. out = rh.createReply();
  127. }
  128. catch (NotFound ex)
  129. {
  130. out = rh.createExceptionReply();
  131. NotFoundHelper.write(out, ex);
  132. }
  133. catch (CannotProceed ex)
  134. {
  135. out = rh.createExceptionReply();
  136. CannotProceedHelper.write(out, ex);
  137. }
  138. catch (InvalidName ex)
  139. {
  140. out = rh.createExceptionReply();
  141. InvalidNameHelper.write(out, ex);
  142. }
  143. break;
  144. }
  145. case 2: // bind_context
  146. {
  147. try
  148. {
  149. NameComponent[] a_name = NameHelper.read(in);
  150. NamingContext a_context = NamingContextHelper.read(in);
  151. bind_context(a_name, a_context);
  152. out = rh.createReply();
  153. }
  154. catch (NotFound ex)
  155. {
  156. out = rh.createExceptionReply();
  157. NotFoundHelper.write(out, ex);
  158. }
  159. catch (CannotProceed ex)
  160. {
  161. out = rh.createExceptionReply();
  162. CannotProceedHelper.write(out, ex);
  163. }
  164. catch (InvalidName ex)
  165. {
  166. out = rh.createExceptionReply();
  167. InvalidNameHelper.write(out, ex);
  168. }
  169. catch (AlreadyBound ex)
  170. {
  171. out = rh.createExceptionReply();
  172. AlreadyBoundHelper.write(out, ex);
  173. }
  174. break;
  175. }
  176. case 3: // rebind_context
  177. {
  178. try
  179. {
  180. NameComponent[] a_name = NameHelper.read(in);
  181. NamingContext a_context = NamingContextHelper.read(in);
  182. rebind_context(a_name, a_context);
  183. out = rh.createReply();
  184. }
  185. catch (NotFound ex)
  186. {
  187. out = rh.createExceptionReply();
  188. NotFoundHelper.write(out, ex);
  189. }
  190. catch (CannotProceed ex)
  191. {
  192. out = rh.createExceptionReply();
  193. CannotProceedHelper.write(out, ex);
  194. }
  195. catch (InvalidName ex)
  196. {
  197. out = rh.createExceptionReply();
  198. InvalidNameHelper.write(out, ex);
  199. }
  200. break;
  201. }
  202. case 4: // resolve
  203. {
  204. try
  205. {
  206. NameComponent[] a_name = NameHelper.read(in);
  207. org.omg.CORBA.Object __result = null;
  208. __result = resolve(a_name);
  209. out = rh.createReply();
  210. ObjectHelper.write(out, __result);
  211. }
  212. catch (NotFound ex)
  213. {
  214. out = rh.createExceptionReply();
  215. NotFoundHelper.write(out, ex);
  216. }
  217. catch (CannotProceed ex)
  218. {
  219. out = rh.createExceptionReply();
  220. CannotProceedHelper.write(out, ex);
  221. }
  222. catch (InvalidName ex)
  223. {
  224. out = rh.createExceptionReply();
  225. InvalidNameHelper.write(out, ex);
  226. }
  227. break;
  228. }
  229. case 5: // unbind
  230. {
  231. try
  232. {
  233. NameComponent[] a_name = NameHelper.read(in);
  234. unbind(a_name);
  235. out = rh.createReply();
  236. }
  237. catch (NotFound ex)
  238. {
  239. out = rh.createExceptionReply();
  240. NotFoundHelper.write(out, ex);
  241. }
  242. catch (CannotProceed ex)
  243. {
  244. out = rh.createExceptionReply();
  245. CannotProceedHelper.write(out, ex);
  246. }
  247. catch (InvalidName ex)
  248. {
  249. out = rh.createExceptionReply();
  250. InvalidNameHelper.write(out, ex);
  251. }
  252. break;
  253. }
  254. case 6: // new_context
  255. {
  256. NamingContext __result = null;
  257. __result = new_context();
  258. out = rh.createReply();
  259. NamingContextHelper.write(out, __result);
  260. break;
  261. }
  262. case 7: // bind_new_context
  263. {
  264. try
  265. {
  266. NameComponent[] a_name = NameHelper.read(in);
  267. NamingContext __result = null;
  268. __result = bind_new_context(a_name);
  269. out = rh.createReply();
  270. NamingContextHelper.write(out, __result);
  271. }
  272. catch (NotFound ex)
  273. {
  274. out = rh.createExceptionReply();
  275. NotFoundHelper.write(out, ex);
  276. }
  277. catch (AlreadyBound ex)
  278. {
  279. out = rh.createExceptionReply();
  280. AlreadyBoundHelper.write(out, ex);
  281. }
  282. catch (CannotProceed ex)
  283. {
  284. out = rh.createExceptionReply();
  285. CannotProceedHelper.write(out, ex);
  286. }
  287. catch (InvalidName ex)
  288. {
  289. out = rh.createExceptionReply();
  290. InvalidNameHelper.write(out, ex);
  291. }
  292. break;
  293. }
  294. case 8: // destroy
  295. {
  296. try
  297. {
  298. destroy();
  299. out = rh.createReply();
  300. }
  301. catch (NotEmpty ex)
  302. {
  303. out = rh.createExceptionReply();
  304. NotEmptyHelper.write(out, ex);
  305. }
  306. break;
  307. }
  308. case 9: // list
  309. {
  310. int amount = in.read_ulong();
  311. BindingListHolder a_list = new BindingListHolder();
  312. BindingIteratorHolder an_iter = new BindingIteratorHolder();
  313. list(amount, a_list, an_iter);
  314. out = rh.createReply();
  315. BindingListHelper.write(out, a_list.value);
  316. BindingIteratorHelper.write(out, an_iter.value);
  317. break;
  318. }
  319. default:
  320. throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
  321. }
  322. return out;
  323. }
  324. /**
  325. * Get the CORBA object that delegates calls to this servant. The servant must
  326. * be already connected to an ORB.
  327. */
  328. public NamingContext _this()
  329. {
  330. return NamingContextHelper.narrow(super._this_object());
  331. }
  332. /**
  333. * Get the CORBA object that delegates calls to this servant. Connect to the
  334. * given ORB, if needed.
  335. */
  336. public NamingContext _this(org.omg.CORBA.ORB orb)
  337. {
  338. return NamingContextHelper.narrow(super._this_object(orb));
  339. }
  340. }