_NamingContextImplBase.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /* _NamingContextImplBase.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.DynamicImplementation;
  36. import org.omg.CORBA.ObjectHelper;
  37. import org.omg.CORBA.ObjectHolder;
  38. import org.omg.CORBA.ServerRequest;
  39. import org.omg.CORBA.portable.InputStream;
  40. import org.omg.CORBA.portable.InvokeHandler;
  41. import org.omg.CORBA.portable.OutputStream;
  42. import org.omg.CORBA.portable.ResponseHandler;
  43. import org.omg.CORBA.portable.Streamable;
  44. import org.omg.CosNaming.NamingContextPackage.AlreadyBound;
  45. import org.omg.CosNaming.NamingContextPackage.AlreadyBoundHelper;
  46. import org.omg.CosNaming.NamingContextPackage.CannotProceed;
  47. import org.omg.CosNaming.NamingContextPackage.CannotProceedHelper;
  48. import org.omg.CosNaming.NamingContextPackage.InvalidName;
  49. import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper;
  50. import org.omg.CosNaming.NamingContextPackage.NotEmpty;
  51. import org.omg.CosNaming.NamingContextPackage.NotEmptyHelper;
  52. import org.omg.CosNaming.NamingContextPackage.NotFound;
  53. import org.omg.CosNaming.NamingContextPackage.NotFoundHelper;
  54. import java.util.Hashtable;
  55. /**
  56. * The naming context implementation base.
  57. *
  58. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  59. */
  60. public abstract class _NamingContextImplBase
  61. extends DynamicImplementation
  62. implements NamingContext, InvokeHandler
  63. {
  64. /**
  65. * Use serialVersionUID (v1.4) for interoperability.
  66. */
  67. private static final long serialVersionUID = -114280294134561035L;
  68. /**
  69. * As there are quite many methods, it may be sensible to use the hashtable.
  70. * This field is also reused in NamingContextPOA.
  71. */
  72. static Hashtable<String,Integer> methods = new Hashtable<String,Integer>();
  73. /**
  74. * Put all methods into the table.
  75. */
  76. static
  77. {
  78. methods.put("bind", new Integer(0));
  79. methods.put("rebind", new Integer(1));
  80. methods.put("bind_context", new Integer(2));
  81. methods.put("rebind_context", new Integer(3));
  82. methods.put("resolve", new Integer(4));
  83. methods.put("unbind", new Integer(5));
  84. methods.put("new_context", new Integer(6));
  85. methods.put("bind_new_context", new Integer(7));
  86. methods.put("destroy", new Integer(8));
  87. methods.put("list", new Integer(9));
  88. }
  89. /**
  90. * Return the array of repository ids.
  91. */
  92. public String[] _ids()
  93. {
  94. return new String[] { NamingContextHelper.id() };
  95. }
  96. /**
  97. * The server calls this method after receiving the request message
  98. * from client. The implementation base calls one of its abstract
  99. * methods to perform the requested operation.
  100. *
  101. * @param method the method being invoked.
  102. * @param in the stream to read parameters from.
  103. * @param rh the handler to get a stream for writing a response.
  104. *
  105. * @return the stream, returned by the handler.
  106. */
  107. public OutputStream _invoke(String method, InputStream in, ResponseHandler rh)
  108. {
  109. OutputStream out = null;
  110. Integer call_method = methods.get(method);
  111. if (call_method == null)
  112. throw new BAD_OPERATION(Minor.Method, CompletionStatus.COMPLETED_MAYBE);
  113. switch (call_method.intValue())
  114. {
  115. case 0 : // bind
  116. {
  117. try
  118. {
  119. NameComponent[] a_name = NameHelper.read(in);
  120. org.omg.CORBA.Object an_object = ObjectHelper.read(in);
  121. bind(a_name, an_object);
  122. out = rh.createReply();
  123. }
  124. catch (NotFound ex)
  125. {
  126. out = rh.createExceptionReply();
  127. NotFoundHelper.write(out, ex);
  128. }
  129. catch (CannotProceed ex)
  130. {
  131. out = rh.createExceptionReply();
  132. CannotProceedHelper.write(out, ex);
  133. }
  134. catch (InvalidName ex)
  135. {
  136. out = rh.createExceptionReply();
  137. InvalidNameHelper.write(out, ex);
  138. }
  139. catch (AlreadyBound ex)
  140. {
  141. out = rh.createExceptionReply();
  142. AlreadyBoundHelper.write(out, ex);
  143. }
  144. break;
  145. }
  146. case 1 : // rebind
  147. {
  148. try
  149. {
  150. NameComponent[] a_name = NameHelper.read(in);
  151. org.omg.CORBA.Object an_object = ObjectHelper.read(in);
  152. rebind(a_name, an_object);
  153. out = rh.createReply();
  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. case 2 : // bind_context
  173. {
  174. try
  175. {
  176. NameComponent[] a_name = NameHelper.read(in);
  177. NamingContext a_context = NamingContextHelper.read(in);
  178. bind_context(a_name, a_context);
  179. out = rh.createReply();
  180. }
  181. catch (NotFound ex)
  182. {
  183. out = rh.createExceptionReply();
  184. NotFoundHelper.write(out, ex);
  185. }
  186. catch (CannotProceed ex)
  187. {
  188. out = rh.createExceptionReply();
  189. CannotProceedHelper.write(out, ex);
  190. }
  191. catch (InvalidName ex)
  192. {
  193. out = rh.createExceptionReply();
  194. InvalidNameHelper.write(out, ex);
  195. }
  196. catch (AlreadyBound ex)
  197. {
  198. out = rh.createExceptionReply();
  199. AlreadyBoundHelper.write(out, ex);
  200. }
  201. break;
  202. }
  203. case 3 : // rebind_context
  204. {
  205. try
  206. {
  207. NameComponent[] a_name = NameHelper.read(in);
  208. NamingContext a_context = NamingContextHelper.read(in);
  209. rebind_context(a_name, a_context);
  210. out = rh.createReply();
  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 4 : // resolve
  230. {
  231. try
  232. {
  233. NameComponent[] a_name = NameHelper.read(in);
  234. org.omg.CORBA.Object __result = null;
  235. __result = resolve(a_name);
  236. out = rh.createReply();
  237. ObjectHelper.write(out, __result);
  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. case 5 : // unbind
  257. {
  258. try
  259. {
  260. NameComponent[] a_name = NameHelper.read(in);
  261. unbind(a_name);
  262. out = rh.createReply();
  263. }
  264. catch (NotFound ex)
  265. {
  266. out = rh.createExceptionReply();
  267. NotFoundHelper.write(out, ex);
  268. }
  269. catch (CannotProceed ex)
  270. {
  271. out = rh.createExceptionReply();
  272. CannotProceedHelper.write(out, ex);
  273. }
  274. catch (InvalidName ex)
  275. {
  276. out = rh.createExceptionReply();
  277. InvalidNameHelper.write(out, ex);
  278. }
  279. break;
  280. }
  281. case 6 : // new_context
  282. {
  283. NamingContext __result = null;
  284. __result = new_context();
  285. out = rh.createReply();
  286. NamingContextHelper.write(out, __result);
  287. break;
  288. }
  289. case 7 : // bind_new_context
  290. {
  291. try
  292. {
  293. NameComponent[] a_name = NameHelper.read(in);
  294. NamingContext __result = null;
  295. __result = bind_new_context(a_name);
  296. out = rh.createReply();
  297. NamingContextHelper.write(out, __result);
  298. }
  299. catch (NotFound ex)
  300. {
  301. out = rh.createExceptionReply();
  302. NotFoundHelper.write(out, ex);
  303. }
  304. catch (AlreadyBound ex)
  305. {
  306. out = rh.createExceptionReply();
  307. AlreadyBoundHelper.write(out, ex);
  308. }
  309. catch (CannotProceed ex)
  310. {
  311. out = rh.createExceptionReply();
  312. CannotProceedHelper.write(out, ex);
  313. }
  314. catch (InvalidName ex)
  315. {
  316. out = rh.createExceptionReply();
  317. InvalidNameHelper.write(out, ex);
  318. }
  319. break;
  320. }
  321. case 8 : // destroy
  322. {
  323. try
  324. {
  325. destroy();
  326. out = rh.createReply();
  327. }
  328. catch (NotEmpty ex)
  329. {
  330. out = rh.createExceptionReply();
  331. NotEmptyHelper.write(out, ex);
  332. }
  333. break;
  334. }
  335. case 9 : // list
  336. {
  337. int amount = in.read_ulong();
  338. BindingListHolder a_list = new BindingListHolder();
  339. BindingIteratorHolder an_iter = new BindingIteratorHolder();
  340. list(amount, a_list, an_iter);
  341. out = rh.createReply();
  342. BindingListHelper.write(out, a_list.value);
  343. BindingIteratorHelper.write(out, an_iter.value);
  344. break;
  345. }
  346. default :
  347. throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
  348. }
  349. return out;
  350. }
  351. /**
  352. * The obsolete invocation using server request. Implemented for
  353. * compatibility reasons, but is it more effectinve to use
  354. * {@link #_invoke}.
  355. *
  356. * @param request a server request.
  357. */
  358. public void invoke(ServerRequest request)
  359. {
  360. Streamable result = null;
  361. // The server request contains no required result type.
  362. Integer call_method = methods.get(request.operation());
  363. if (call_method == null)
  364. throw new BAD_OPERATION(Minor.Method, CompletionStatus.COMPLETED_MAYBE);
  365. switch (call_method.intValue())
  366. {
  367. case 4 : // resolve, object
  368. result = new ObjectHolder();
  369. break;
  370. case 6 : // new_context, NamingContext
  371. case 7 : // bind_new_context, NamingContext
  372. {
  373. result = new NamingContextHolder();
  374. break;
  375. }
  376. default : // void for others.
  377. result = null;
  378. }
  379. gnu.CORBA.ServiceRequestAdapter.invoke(request, this, result);
  380. }
  381. }