NamingContextExtPOA.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /* NamingContextExtPOA.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.NamingContextExtPackage.InvalidAddress;
  41. import org.omg.CosNaming.NamingContextExtPackage.InvalidAddressHelper;
  42. import org.omg.CosNaming.NamingContextPackage.AlreadyBound;
  43. import org.omg.CosNaming.NamingContextPackage.AlreadyBoundHelper;
  44. import org.omg.CosNaming.NamingContextPackage.CannotProceed;
  45. import org.omg.CosNaming.NamingContextPackage.CannotProceedHelper;
  46. import org.omg.CosNaming.NamingContextPackage.InvalidName;
  47. import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper;
  48. import org.omg.CosNaming.NamingContextPackage.NotEmpty;
  49. import org.omg.CosNaming.NamingContextPackage.NotEmptyHelper;
  50. import org.omg.CosNaming.NamingContextPackage.NotFound;
  51. import org.omg.CosNaming.NamingContextPackage.NotFoundHelper;
  52. import org.omg.PortableServer.POA;
  53. import org.omg.PortableServer.Servant;
  54. /**
  55. * The extended naming service servant. After implementing the abstract methods the
  56. * instance of this class can be connected to an ORB using POA.
  57. *
  58. * @since 1.4
  59. *
  60. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  61. */
  62. public abstract class NamingContextExtPOA
  63. extends Servant
  64. implements NamingContextExtOperations, InvokeHandler
  65. {
  66. /** @inheritDoc */
  67. public String[] _all_interfaces(POA poa, byte[] object_ID)
  68. {
  69. return new String[] { NamingContextExtHelper.id(), NamingContextHelper.id() };
  70. }
  71. /** @inheritDoc */
  72. public OutputStream _invoke(String method, InputStream in, ResponseHandler rh)
  73. {
  74. Integer call_method = _NamingContextExtImplBase._methods.get(method);
  75. if (call_method == null)
  76. // The older methods are handled separately.
  77. return super_invoke(method, in, rh);
  78. OutputStream out = null;
  79. switch (call_method.intValue())
  80. {
  81. case 0: // to_string
  82. {
  83. try
  84. {
  85. NameComponent[] a_name = NameHelper.read(in);
  86. String result = null;
  87. result = this.to_string(a_name);
  88. out = rh.createReply();
  89. out.write_string(result);
  90. }
  91. catch (InvalidName ex)
  92. {
  93. out = rh.createExceptionReply();
  94. InvalidNameHelper.write(out, ex);
  95. }
  96. break;
  97. }
  98. case 1: // to_name
  99. {
  100. try
  101. {
  102. String a_name_string = in.read_string();
  103. NameComponent[] result = to_name(a_name_string);
  104. out = rh.createReply();
  105. NameHelper.write(out, result);
  106. }
  107. catch (InvalidName ex)
  108. {
  109. out = rh.createExceptionReply();
  110. InvalidNameHelper.write(out, ex);
  111. }
  112. break;
  113. }
  114. case 2: // to_url
  115. {
  116. try
  117. {
  118. String an_address = in.read_string();
  119. String a_name_string = in.read_string();
  120. String result = to_url(an_address, a_name_string);
  121. out = rh.createReply();
  122. out.write_string(result);
  123. }
  124. catch (InvalidAddress ex)
  125. {
  126. out = rh.createExceptionReply();
  127. InvalidAddressHelper.write(out, ex);
  128. }
  129. catch (InvalidName ex)
  130. {
  131. out = rh.createExceptionReply();
  132. InvalidNameHelper.write(out, ex);
  133. }
  134. break;
  135. }
  136. case 3: // resolve_str
  137. {
  138. try
  139. {
  140. String a_name_string = in.read_string();
  141. org.omg.CORBA.Object result = resolve_str(a_name_string);
  142. out = rh.createReply();
  143. org.omg.CORBA.ObjectHelper.write(out, result);
  144. }
  145. catch (NotFound ex)
  146. {
  147. out = rh.createExceptionReply();
  148. NotFoundHelper.write(out, ex);
  149. }
  150. catch (CannotProceed ex)
  151. {
  152. out = rh.createExceptionReply();
  153. CannotProceedHelper.write(out, ex);
  154. }
  155. catch (InvalidName ex)
  156. {
  157. out = rh.createExceptionReply();
  158. InvalidNameHelper.write(out, ex);
  159. }
  160. break;
  161. }
  162. }
  163. return out;
  164. }
  165. /**
  166. * Handles calls to the methods from the NamingContext. The classes cannot be
  167. * directly derived from each other; new public methods would appear.
  168. */
  169. OutputStream super_invoke(String method, InputStream in, ResponseHandler rh)
  170. {
  171. OutputStream out = null;
  172. Integer call_method = _NamingContextImplBase.methods.get(method);
  173. if (call_method == null)
  174. throw new BAD_OPERATION(Minor.Method, CompletionStatus.COMPLETED_MAYBE);
  175. switch (call_method.intValue())
  176. {
  177. case 0: // bind
  178. {
  179. try
  180. {
  181. NameComponent[] a_name = NameHelper.read(in);
  182. org.omg.CORBA.Object an_object = ObjectHelper.read(in);
  183. bind(a_name, an_object);
  184. out = rh.createReply();
  185. }
  186. catch (NotFound ex)
  187. {
  188. out = rh.createExceptionReply();
  189. NotFoundHelper.write(out, ex);
  190. }
  191. catch (CannotProceed ex)
  192. {
  193. out = rh.createExceptionReply();
  194. CannotProceedHelper.write(out, ex);
  195. }
  196. catch (InvalidName ex)
  197. {
  198. out = rh.createExceptionReply();
  199. InvalidNameHelper.write(out, ex);
  200. }
  201. catch (AlreadyBound ex)
  202. {
  203. out = rh.createExceptionReply();
  204. AlreadyBoundHelper.write(out, ex);
  205. }
  206. break;
  207. }
  208. case 1: // rebind
  209. {
  210. try
  211. {
  212. NameComponent[] a_name = NameHelper.read(in);
  213. org.omg.CORBA.Object an_object = ObjectHelper.read(in);
  214. rebind(a_name, an_object);
  215. out = rh.createReply();
  216. }
  217. catch (NotFound ex)
  218. {
  219. out = rh.createExceptionReply();
  220. NotFoundHelper.write(out, ex);
  221. }
  222. catch (CannotProceed ex)
  223. {
  224. out = rh.createExceptionReply();
  225. CannotProceedHelper.write(out, ex);
  226. }
  227. catch (InvalidName ex)
  228. {
  229. out = rh.createExceptionReply();
  230. InvalidNameHelper.write(out, ex);
  231. }
  232. break;
  233. }
  234. case 2: // bind_context
  235. {
  236. try
  237. {
  238. NameComponent[] a_name = NameHelper.read(in);
  239. NamingContext a_context = NamingContextHelper.read(in);
  240. bind_context(a_name, a_context);
  241. out = rh.createReply();
  242. }
  243. catch (NotFound ex)
  244. {
  245. out = rh.createExceptionReply();
  246. NotFoundHelper.write(out, ex);
  247. }
  248. catch (CannotProceed ex)
  249. {
  250. out = rh.createExceptionReply();
  251. CannotProceedHelper.write(out, ex);
  252. }
  253. catch (InvalidName ex)
  254. {
  255. out = rh.createExceptionReply();
  256. InvalidNameHelper.write(out, ex);
  257. }
  258. catch (AlreadyBound ex)
  259. {
  260. out = rh.createExceptionReply();
  261. AlreadyBoundHelper.write(out, ex);
  262. }
  263. break;
  264. }
  265. case 3: // rebind_context
  266. {
  267. try
  268. {
  269. NameComponent[] a_name = NameHelper.read(in);
  270. NamingContext a_context = NamingContextHelper.read(in);
  271. rebind_context(a_name, a_context);
  272. out = rh.createReply();
  273. }
  274. catch (NotFound ex)
  275. {
  276. out = rh.createExceptionReply();
  277. NotFoundHelper.write(out, ex);
  278. }
  279. catch (CannotProceed ex)
  280. {
  281. out = rh.createExceptionReply();
  282. CannotProceedHelper.write(out, ex);
  283. }
  284. catch (InvalidName ex)
  285. {
  286. out = rh.createExceptionReply();
  287. InvalidNameHelper.write(out, ex);
  288. }
  289. break;
  290. }
  291. case 4: // resolve
  292. {
  293. try
  294. {
  295. NameComponent[] a_name = NameHelper.read(in);
  296. org.omg.CORBA.Object __result = null;
  297. __result = resolve(a_name);
  298. out = rh.createReply();
  299. ObjectHelper.write(out, __result);
  300. }
  301. catch (NotFound ex)
  302. {
  303. out = rh.createExceptionReply();
  304. NotFoundHelper.write(out, ex);
  305. }
  306. catch (CannotProceed ex)
  307. {
  308. out = rh.createExceptionReply();
  309. CannotProceedHelper.write(out, ex);
  310. }
  311. catch (InvalidName ex)
  312. {
  313. out = rh.createExceptionReply();
  314. InvalidNameHelper.write(out, ex);
  315. }
  316. break;
  317. }
  318. case 5: // unbind
  319. {
  320. try
  321. {
  322. NameComponent[] a_name = NameHelper.read(in);
  323. unbind(a_name);
  324. out = rh.createReply();
  325. }
  326. catch (NotFound ex)
  327. {
  328. out = rh.createExceptionReply();
  329. NotFoundHelper.write(out, ex);
  330. }
  331. catch (CannotProceed ex)
  332. {
  333. out = rh.createExceptionReply();
  334. CannotProceedHelper.write(out, ex);
  335. }
  336. catch (InvalidName ex)
  337. {
  338. out = rh.createExceptionReply();
  339. InvalidNameHelper.write(out, ex);
  340. }
  341. break;
  342. }
  343. case 6: // new_context
  344. {
  345. NamingContext __result = null;
  346. __result = new_context();
  347. out = rh.createReply();
  348. NamingContextHelper.write(out, __result);
  349. break;
  350. }
  351. case 7: // bind_new_context
  352. {
  353. try
  354. {
  355. NameComponent[] a_name = NameHelper.read(in);
  356. NamingContext __result = null;
  357. __result = bind_new_context(a_name);
  358. out = rh.createReply();
  359. NamingContextHelper.write(out, __result);
  360. }
  361. catch (NotFound ex)
  362. {
  363. out = rh.createExceptionReply();
  364. NotFoundHelper.write(out, ex);
  365. }
  366. catch (AlreadyBound ex)
  367. {
  368. out = rh.createExceptionReply();
  369. AlreadyBoundHelper.write(out, ex);
  370. }
  371. catch (CannotProceed ex)
  372. {
  373. out = rh.createExceptionReply();
  374. CannotProceedHelper.write(out, ex);
  375. }
  376. catch (InvalidName ex)
  377. {
  378. out = rh.createExceptionReply();
  379. InvalidNameHelper.write(out, ex);
  380. }
  381. break;
  382. }
  383. case 8: // destroy
  384. {
  385. try
  386. {
  387. destroy();
  388. out = rh.createReply();
  389. }
  390. catch (NotEmpty ex)
  391. {
  392. out = rh.createExceptionReply();
  393. NotEmptyHelper.write(out, ex);
  394. }
  395. break;
  396. }
  397. case 9: // list
  398. {
  399. int amount = in.read_ulong();
  400. BindingListHolder a_list = new BindingListHolder();
  401. BindingIteratorHolder an_iter = new BindingIteratorHolder();
  402. list(amount, a_list, an_iter);
  403. out = rh.createReply();
  404. BindingListHelper.write(out, a_list.value);
  405. BindingIteratorHelper.write(out, an_iter.value);
  406. break;
  407. }
  408. default:
  409. throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
  410. }
  411. return out;
  412. }
  413. /**
  414. * Get the CORBA object that delegates calls to this servant. The servant must
  415. * be already connected to an ORB.
  416. */
  417. public NamingContextExt _this()
  418. {
  419. return NamingContextExtHelper.narrow(super._this_object());
  420. }
  421. /**
  422. * Get the CORBA object that delegates calls to this servant. Connect to the
  423. * given ORB, if needed.
  424. */
  425. public NamingContextExt _this(org.omg.CORBA.ORB orb)
  426. {
  427. return NamingContextExtHelper.narrow(super._this_object(orb));
  428. }
  429. }