1. /*
  2. * @(#)ObjectImpl.java 1.28 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package org.omg.CORBA.portable;
  8. import org.omg.CORBA.Request;
  9. import org.omg.CORBA.NamedValue;
  10. import org.omg.CORBA.NVList;
  11. import org.omg.CORBA.ExceptionList;
  12. import org.omg.CORBA.ContextList;
  13. import org.omg.CORBA.Context;
  14. import org.omg.CORBA.TypeCode;
  15. import org.omg.CORBA.BAD_OPERATION;
  16. import org.omg.CORBA.SystemException;
  17. /** The ObjectImpl class provides default implementations of the
  18. * org.omg.CORBA.Object methods. All method implementations are forwarded to
  19. * a Delegate object stored in the ObjectImpl instance.
  20. * ObjectImpl is the common base class for all stub classes.
  21. * ObjectImpl allows for portable stubs because the Delegate can be
  22. * implemented by a different vendor-specific ORB.
  23. */
  24. abstract public class ObjectImpl implements org.omg.CORBA.Object
  25. {
  26. private transient Delegate __delegate;
  27. /** return the Delegate contained in this ObjectImpl instance. */
  28. public Delegate _get_delegate() {
  29. if (__delegate == null)
  30. throw new BAD_OPERATION("The delegate has not been set!");
  31. return __delegate;
  32. }
  33. /** set the Delegate contained in this ObjectImpl instance. */
  34. public void _set_delegate(Delegate delegate) {
  35. __delegate = delegate;
  36. }
  37. /** return the array of all repository identifiers supported by this
  38. ObjectImpl instance (e.g. For a stub, _ids() will return information
  39. about all interfaces supported by the stub).
  40. */
  41. public abstract String[] _ids();
  42. /** default implementation of the org.omg.CORBA.Object method. */
  43. public org.omg.CORBA.Object _duplicate() {
  44. return _get_delegate().duplicate(this);
  45. }
  46. /** default implementation of the org.omg.CORBA.Object method. */
  47. public void _release() {
  48. _get_delegate().release(this);
  49. }
  50. /** default implementation of the org.omg.CORBA.Object method. */
  51. public boolean _is_a(String repository_id) {
  52. return _get_delegate().is_a(this, repository_id);
  53. }
  54. /** default implementation of the org.omg.CORBA.Object method. */
  55. public boolean _is_equivalent(org.omg.CORBA.Object that) {
  56. return _get_delegate().is_equivalent(this, that);
  57. }
  58. /** default implementation of the org.omg.CORBA.Object method. */
  59. public boolean _non_existent() {
  60. return _get_delegate().non_existent(this);
  61. }
  62. /** default implementation of the org.omg.CORBA.Object method. */
  63. public int _hash(int maximum) {
  64. return _get_delegate().hash(this, maximum);
  65. }
  66. /** default implementation of the org.omg.CORBA.Object method. */
  67. public Request _request(String operation) {
  68. return _get_delegate().request(this, operation);
  69. }
  70. /** default implementation of the org.omg.CORBA.Object method. */
  71. public Request _create_request(Context ctx,
  72. String operation,
  73. NVList arg_list,
  74. NamedValue result) {
  75. return _get_delegate().create_request(this,
  76. ctx,
  77. operation,
  78. arg_list,
  79. result);
  80. }
  81. /** default implementation of the org.omg.CORBA.Object method. */
  82. public Request _create_request(Context ctx,
  83. String operation,
  84. NVList arg_list,
  85. NamedValue result,
  86. ExceptionList exceptions,
  87. ContextList contexts) {
  88. return _get_delegate().create_request(this,
  89. ctx,
  90. operation,
  91. arg_list,
  92. result,
  93. exceptions,
  94. contexts);
  95. }
  96. /** default implementation of the org.omg.CORBA.Object method. */
  97. public org.omg.CORBA.Object _get_interface_def()
  98. {
  99. // First try to call the delegate implementation class's
  100. // "Object get_interface_def(..)" method (will work for JDK1.2 ORBs).
  101. // Else call the delegate implementation class's
  102. // "InterfaceDef get_interface(..)" method using reflection
  103. // (will work for pre-JDK1.2 ORBs).
  104. org.omg.CORBA.portable.Delegate delegate = _get_delegate();
  105. try {
  106. // If the ORB's delegate class does not implement
  107. // "Object get_interface_def(..)", this will call
  108. // get_interface_def(..) on portable.Delegate.
  109. return delegate.get_interface_def(this);
  110. }
  111. catch( org.omg.CORBA.NO_IMPLEMENT ex ) {
  112. // Call "InterfaceDef get_interface(..)" method using reflection.
  113. try {
  114. Class[] argc = { org.omg.CORBA.Object.class };
  115. java.lang.reflect.Method meth =
  116. delegate.getClass().getMethod("get_interface", argc);
  117. Object[] argx = { this };
  118. return (org.omg.CORBA.Object)meth.invoke(delegate, argx);
  119. }
  120. catch( java.lang.reflect.InvocationTargetException exs ) {
  121. Throwable t = exs.getTargetException();
  122. if (t instanceof Error) {
  123. throw (Error) t;
  124. }
  125. else if (t instanceof RuntimeException) {
  126. throw (RuntimeException) t;
  127. }
  128. else {
  129. throw new org.omg.CORBA.NO_IMPLEMENT();
  130. }
  131. } catch( RuntimeException rex ) {
  132. throw rex;
  133. } catch( Exception exr ) {
  134. throw new org.omg.CORBA.NO_IMPLEMENT();
  135. }
  136. }
  137. }
  138. /** return the ORB instance which created the Delegate contained in
  139. * this ObjectImpl.
  140. */
  141. public org.omg.CORBA.ORB _orb() {
  142. return _get_delegate().orb(this);
  143. }
  144. /**
  145. *
  146. */
  147. public org.omg.CORBA.Policy _get_policy(int policy_type) {
  148. return _get_delegate().get_policy(this, policy_type);
  149. }
  150. /**
  151. *
  152. */
  153. public org.omg.CORBA.DomainManager[] _get_domain_managers() {
  154. return _get_delegate().get_domain_managers(this);
  155. }
  156. /**
  157. *
  158. */
  159. public org.omg.CORBA.Object
  160. _set_policy_override(org.omg.CORBA.Policy[] policies,
  161. org.omg.CORBA.SetOverrideType set_add) {
  162. return _get_delegate().set_policy_override(this, policies,
  163. set_add);
  164. }
  165. /**
  166. *
  167. */
  168. public boolean _is_local() {
  169. return _get_delegate().is_local(this);
  170. }
  171. /**
  172. *
  173. */
  174. public ServantObject _servant_preinvoke(String operation,
  175. Class expectedType) {
  176. return _get_delegate().servant_preinvoke(this, operation,
  177. expectedType);
  178. }
  179. /**
  180. *
  181. */
  182. public void _servant_postinvoke(ServantObject servant) {
  183. _get_delegate().servant_postinvoke(this, servant);
  184. }
  185. /*
  186. * The following methods were added by orbos/98-04-03: Java to IDL
  187. * Mapping. These are used by RMI over IIOP.
  188. */
  189. /**
  190. * _request is called by a stub to obtain an OutputStream for
  191. * marshaling arguments. The stub must supply the operation name,
  192. * and indicate if a response is expected (i.e is this a oneway
  193. * call).
  194. */
  195. public OutputStream _request(String operation,
  196. boolean responseExpected) {
  197. return _get_delegate().request(this, operation, responseExpected);
  198. }
  199. /**
  200. * _invoke is called to invoke an operation. The stub provides an
  201. * OutputStream that was previously returned by a _request()
  202. * call. _invoke returns an InputStream which contains the
  203. * marshaled reply. If an exception occurs, _invoke may throw an
  204. * ApplicationException object which contains an InputStream from
  205. * which the user exception state may be unmarshaled.
  206. */
  207. public InputStream _invoke(OutputStream output)
  208. throws ApplicationException, RemarshalException {
  209. return _get_delegate().invoke(this, output);
  210. }
  211. /**
  212. * _releaseReply may optionally be called by a stub to release a
  213. * reply stream back to the ORB when the unmarshaling has
  214. * completed. The stub passes the InputStream returned by
  215. * _invoke() or ApplicationException.getInputStream(). A null
  216. * value may also be passed to _releaseReply, in which case the
  217. * method is a noop.
  218. */
  219. public void _releaseReply(InputStream input) {
  220. _get_delegate().releaseReply(this, input);
  221. }
  222. public String toString() {
  223. if ( __delegate != null )
  224. return __delegate.toString(this);
  225. else
  226. return getClass().getName() + ": no delegate set";
  227. }
  228. public int hashCode() {
  229. if ( __delegate != null )
  230. return __delegate.hashCode(this);
  231. else
  232. return System.identityHashCode(this);
  233. }
  234. public boolean equals(java.lang.Object obj) {
  235. if ( __delegate != null )
  236. return __delegate.equals(this, obj);
  237. else
  238. return (this==obj);
  239. }
  240. }