LocalObject.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /* LocalObject.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.CORBA;
  32. import org.omg.CORBA.BAD_PARAM;
  33. import org.omg.CORBA.Context;
  34. import org.omg.CORBA.ContextList;
  35. import org.omg.CORBA.DomainManager;
  36. import org.omg.CORBA.ExceptionList;
  37. import org.omg.CORBA.NO_IMPLEMENT;
  38. import org.omg.CORBA.NVList;
  39. import org.omg.CORBA.NamedValue;
  40. import org.omg.CORBA.Policy;
  41. import org.omg.CORBA.Request;
  42. import org.omg.CORBA.SetOverrideType;
  43. import org.omg.CORBA.portable.ApplicationException;
  44. import org.omg.CORBA.portable.InputStream;
  45. import org.omg.CORBA.portable.OutputStream;
  46. import org.omg.CORBA.portable.RemarshalException;
  47. import org.omg.CORBA.portable.ServantObject;
  48. import javax.rmi.CORBA.Util;
  49. /**
  50. * An object, formally implementing the CORBA {@link Object}, but actually
  51. * handling all invocations locally.
  52. * Various calls to the remote object specific methods throw the
  53. * {@link NO_IMPLEMENT}. The explaining message for this exception is
  54. * specified in java API as <code>"This is a locally constrained object."</code>.
  55. * It is not possible to get a stringified reference of the local object, or
  56. * invoke a method using DII (by name via {@link Request} class).
  57. *
  58. * However narrowing and widening methods will work with local objects.
  59. *
  60. * @since 1.4
  61. *
  62. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  63. */
  64. public class LocalObject
  65. implements org.omg.CORBA.Object
  66. {
  67. /**
  68. * The explaining message for the exception, thrown in response to call
  69. * the method, not appropriate for the local object.
  70. */
  71. private static final String INAPPROPRIATE =
  72. "This is a locally constrained object.";
  73. /**
  74. * This method is not appropriate for the local objects and just
  75. * throws an exception.
  76. *
  77. * @throws NO_IMPLEMENT, always.
  78. */
  79. public Request _create_request(Context context, String operation,
  80. NVList parameters, NamedValue returns
  81. )
  82. {
  83. throw new NO_IMPLEMENT(INAPPROPRIATE);
  84. }
  85. /**
  86. * This method is not appropriate for the local objects and just
  87. * throws an exception.
  88. *
  89. * @throws NO_IMPLEMENT, always.
  90. */
  91. public Request _create_request(Context context, String operation,
  92. NVList parameters, NamedValue returns,
  93. ExceptionList exceptions, ContextList ctx_list
  94. )
  95. {
  96. throw new NO_IMPLEMENT(INAPPROPRIATE);
  97. }
  98. /**
  99. * This method is not appropriate for the local objects and just
  100. * throws an exception.
  101. *
  102. * @throws NO_IMPLEMENT, always.
  103. */
  104. public org.omg.CORBA.Object _duplicate()
  105. {
  106. throw new NO_IMPLEMENT(INAPPROPRIATE);
  107. }
  108. /**
  109. * This method is not appropriate for the local objects and just
  110. * throws an exception.
  111. *
  112. * @throws NO_IMPLEMENT, always.
  113. */
  114. public DomainManager[] _get_domain_managers()
  115. {
  116. throw new NO_IMPLEMENT(INAPPROPRIATE);
  117. }
  118. /**
  119. * This method is not appropriate for the local objects and just
  120. * throws an exception.
  121. *
  122. * @throws NO_IMPLEMENT, always.
  123. */
  124. public org.omg.CORBA.Object _get_interface_def()
  125. {
  126. throw new NO_IMPLEMENT(INAPPROPRIATE);
  127. }
  128. /**
  129. * This method is not appropriate for the local objects and just
  130. * throws an exception.
  131. *
  132. * @throws NO_IMPLEMENT, always.
  133. */
  134. public org.omg.CORBA.Object _get_interface()
  135. {
  136. throw new NO_IMPLEMENT(INAPPROPRIATE);
  137. }
  138. /**
  139. * This method is not appropriate for the local objects and just
  140. * throws an exception.
  141. *
  142. * @throws NO_IMPLEMENT, always.
  143. */
  144. public Policy _get_policy(int a_policy_type)
  145. throws BAD_PARAM
  146. {
  147. throw new NO_IMPLEMENT(INAPPROPRIATE);
  148. }
  149. /**
  150. * {@inheritDoc}
  151. */
  152. public int _hash(int maximum)
  153. {
  154. return Math.abs(hashCode()) % maximum;
  155. }
  156. /**
  157. * This method is not appropriate for the local objects and just
  158. * throws an exception.
  159. *
  160. * @throws NO_IMPLEMENT, always.
  161. */
  162. public boolean _is_a(String repositoryIdentifer)
  163. {
  164. throw new NO_IMPLEMENT(INAPPROPRIATE);
  165. }
  166. /**
  167. * Determines if the object is equal to another object, so far as it is
  168. * possible to determine easily.
  169. *
  170. * @param other the other object.
  171. *
  172. * @return true if the pased object is not null and
  173. * java.lang.Object.equals(other) returns true. False otherwise.
  174. */
  175. public boolean _is_equivalent(org.omg.CORBA.Object other)
  176. {
  177. if (other != null)
  178. if (other.equals(this))
  179. return true;
  180. return false;
  181. }
  182. /**
  183. * Always returs false.
  184. *
  185. * @return false, always.
  186. */
  187. public boolean _non_existent()
  188. {
  189. return false;
  190. }
  191. /**
  192. * This method is not appropriate for the local objects and just
  193. * throws an exception.
  194. *
  195. * @throws NO_IMPLEMENT, always.
  196. */
  197. public void _release()
  198. {
  199. throw new NO_IMPLEMENT(INAPPROPRIATE);
  200. }
  201. /**
  202. * This method is not appropriate for the local objects and just
  203. * throws an exception.
  204. *
  205. * @specnote it is possible to implement a local handling of the _request(),
  206. * but the API clearly states that NO_IMPLEMENT
  207. * must be thrown instead.
  208. *
  209. * @throws NO_IMPLEMENT, always.
  210. */
  211. public Request _request(String operation)
  212. {
  213. throw new NO_IMPLEMENT(INAPPROPRIATE);
  214. }
  215. /**
  216. * This method is not appropriate for the local objects and just
  217. * throws an exception.
  218. *
  219. * @throws NO_IMPLEMENT, always.
  220. */
  221. public org.omg.CORBA.Object _set_policy_override(Policy[] policies,
  222. SetOverrideType how
  223. )
  224. {
  225. throw new NO_IMPLEMENT(INAPPROPRIATE);
  226. }
  227. /**
  228. * This method is called from <code>rmic</code> generated stubs if the
  229. * {@link Util#isLocal}, called passing <code>this</code> as parameter,
  230. * returns true. If the method returns null, the requested method is then
  231. * invoked on <code>this</code>. Else it is invoked on the returned object,
  232. * casting it into the interface that the local object implements. In this
  233. * case, the generated stub also later calls
  234. * {@link #_servant_postinvoke(ServantObject)}, passing that returned target
  235. * as parameter.
  236. *
  237. * @param operation the name of the method being invoked.
  238. * @param expectedType the interface that the returned servant
  239. * object must implement.
  240. *
  241. * @throws NO_IMPLEMENT always. If used, the method must be overridden.
  242. */
  243. @SuppressWarnings("rawtypes") // Needed for API compatibility
  244. public ServantObject _servant_preinvoke(String operation, Class expectedType)
  245. {
  246. throw new NO_IMPLEMENT(INAPPROPRIATE);
  247. }
  248. /**
  249. * This method is called from <code>rmic</code> generated stubs if the
  250. * {@link Util#isLocal}, called passing <code>this</code> as parameter,
  251. * returns true, and the {@link #_servant_preinvoke} return non-null object.
  252. * The stub then invokes the requrested method on that returned object and
  253. * later calls _servant_postinvoke, passing that returned target as parameter.
  254. *
  255. * @param servant the object that has served as the invocation target for the
  256. * current operation.
  257. */
  258. public void _servant_postinvoke(ServantObject servant)
  259. {
  260. }
  261. /**
  262. * Invokes the operation. This method takes the OutputStream that was previously
  263. * returned by a {@link #_request(String)} and returns an InputStream which
  264. * contains the reply. Up till jdk 1.5 inclusive this method is marked as
  265. * unimplemented.
  266. *
  267. * @throws NO_IMPLEMENT always.
  268. */
  269. public InputStream _invoke(OutputStream output)
  270. throws ApplicationException, RemarshalException
  271. {
  272. throw new NO_IMPLEMENT(INAPPROPRIATE);
  273. }
  274. /**
  275. * While it may look that this should return true, the jdk 1.5 API states
  276. * that it must throw NO_IMPLEMENT instead. The rmi stubs do not call this
  277. * method to check if the object is local; they call {@link Util#isLocal}
  278. * instead (passing <code>this</code> as parameter).
  279. *
  280. * @return never.
  281. *
  282. * @throws NO_IMPLEMENT always.
  283. */
  284. public boolean _is_local()
  285. {
  286. throw new NO_IMPLEMENT(INAPPROPRIATE);
  287. }
  288. /**
  289. * This method is not appropriate for the local objects and just
  290. * throws an exception.
  291. *
  292. * @throws NO_IMPLEMENT, always.
  293. */
  294. public ORB _orb()
  295. {
  296. throw new NO_IMPLEMENT(INAPPROPRIATE);
  297. }
  298. /**
  299. * This method is not appropriate for the local objects and just
  300. * throws an exception.
  301. *
  302. * @throws NO_IMPLEMENT, always.
  303. */
  304. public void _releaseReply(InputStream input)
  305. {
  306. throw new NO_IMPLEMENT(INAPPROPRIATE);
  307. }
  308. /**
  309. * This method is not appropriate for the local objects and just
  310. * throws an exception.
  311. *
  312. * @throws NO_IMPLEMENT, always.
  313. */
  314. public OutputStream _request(String operation, boolean responseExpected)
  315. {
  316. throw new NO_IMPLEMENT(INAPPROPRIATE);
  317. }
  318. /**
  319. * This method is not appropriate for the local objects and just
  320. * throws an exception.
  321. *
  322. * @throws NO_IMPLEMENT, always.
  323. */
  324. public boolean validate_connection()
  325. {
  326. throw new NO_IMPLEMENT(INAPPROPRIATE);
  327. }
  328. }