src/share/classes/org/omg/PortableServer/Servant.java

Thu, 17 Jun 2010 16:27:56 -0700

author
mikejwre
date
Thu, 17 Jun 2010 16:27:56 -0700
changeset 171
95db968660e7
parent 158
91006f157c46
child 748
6845b95cba6b
permissions
-rw-r--r--

Added tag jdk7-b98 for changeset 3b99409057e4

duke@1 1 /*
ohair@158 2 * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@158 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@158 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@158 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@158 22 * or visit www.oracle.com if you need additional information or have any
ohair@158 23 * questions.
duke@1 24 */
duke@1 25 package org.omg.PortableServer;
duke@1 26
duke@1 27 import org.omg.CORBA.ORB;
duke@1 28 import org.omg.PortableServer.portable.Delegate;
duke@1 29
duke@1 30 /**
duke@1 31 * Defines the native <code>Servant</code> type. In Java, the
duke@1 32 * <code>Servant</code> type is mapped to the Java
duke@1 33 * <code>org.omg.PortableServer.Servant</code> class.
duke@1 34 * It serves as the base class for all POA servant
duke@1 35 * implementations and provides a number of methods that may
duke@1 36 * be invoked by the application programmer, as well as methods
duke@1 37 * which are invoked by the POA itself and may be overridden by
duke@1 38 * the user to control aspects of servant behavior.
duke@1 39 * Based on IDL to Java spec. (CORBA V2.3.1) ptc/00-01-08.pdf.
duke@1 40 */
duke@1 41
duke@1 42 abstract public class Servant {
duke@1 43
duke@1 44 private transient Delegate _delegate = null;
duke@1 45 /**
duke@1 46 * Gets the ORB vendor-specific implementation of
duke@1 47 * <code>PortableServer::Servant</code>.
duke@1 48 * @return <code>_delegate</code> the ORB vendor-specific
duke@1 49 * implementation of <code>PortableServer::Servant</code>.
duke@1 50 */
duke@1 51 final public Delegate _get_delegate() {
duke@1 52 if (_delegate == null) {
duke@1 53 throw
duke@1 54 new
duke@1 55 org.omg.CORBA.BAD_INV_ORDER
duke@1 56 ("The Servant has not been associated with an ORB instance");
duke@1 57 }
duke@1 58 return _delegate;
duke@1 59 }
duke@1 60
duke@1 61 /**
duke@1 62 * Supports the Java ORB portability
duke@1 63 * interfaces by providing a method for classes that support
duke@1 64 * ORB portability through delegation to set their delegate.
duke@1 65 * @param delegate ORB vendor-specific implementation of
duke@1 66 * the <code>PortableServer::Servant</code>.
duke@1 67 */
duke@1 68 final public void _set_delegate(Delegate delegate) {
duke@1 69 _delegate = delegate;
duke@1 70 }
duke@1 71
duke@1 72 /**
duke@1 73 * Allows the servant to obtain the object reference for
duke@1 74 * the target CORBA object it is incarnating for that request.
duke@1 75 * @return <code>this_object</code> <code>Object</code> reference
duke@1 76 * associated with the request.
duke@1 77 */
duke@1 78 final public org.omg.CORBA.Object _this_object() {
duke@1 79 return _get_delegate().this_object(this);
duke@1 80 }
duke@1 81
duke@1 82 /**
duke@1 83 * Allows the servant to obtain the object reference for
duke@1 84 * the target CORBA Object it is incarnating for that request.
duke@1 85 * @param orb ORB with which the servant is associated.
duke@1 86 * @return <code>_this_object</code> reference associated with the request.
duke@1 87 */
duke@1 88 final public org.omg.CORBA.Object _this_object(ORB orb) {
duke@1 89 try {
duke@1 90 ((org.omg.CORBA_2_3.ORB)orb).set_delegate(this);
duke@1 91 }
duke@1 92 catch(ClassCastException e) {
duke@1 93 throw
duke@1 94 new
duke@1 95 org.omg.CORBA.BAD_PARAM
duke@1 96 ("POA Servant requires an instance of org.omg.CORBA_2_3.ORB");
duke@1 97 }
duke@1 98 return _this_object();
duke@1 99 }
duke@1 100
duke@1 101 /**
duke@1 102 * Returns the instance of the ORB
duke@1 103 * currently associated with the <code>Servant</code> (convenience method).
duke@1 104 * @return <code>orb</code> the instance of the ORB currently
duke@1 105 * associated with the <code>Servant</code>.
duke@1 106 */
duke@1 107 final public ORB _orb() {
duke@1 108 return _get_delegate().orb(this);
duke@1 109 }
duke@1 110
duke@1 111 /**
duke@1 112 * Allows easy execution of common methods, equivalent to
duke@1 113 * <code>PortableServer::Current:get_POA</code>.
duke@1 114 * @return <code>poa</code> POA associated with the servant.
duke@1 115 */
duke@1 116 final public POA _poa() {
duke@1 117 return _get_delegate().poa(this);
duke@1 118 }
duke@1 119
duke@1 120 /**
duke@1 121 * Allows easy execution of
duke@1 122 * common methods, equivalent
duke@1 123 * to calling <code>PortableServer::Current::get_object_id</code>.
duke@1 124 * @return <code>object_id</code> the <code>Object</code> ID associated
duke@1 125 * with this servant.
duke@1 126 */
duke@1 127 final public byte[] _object_id() {
duke@1 128 return _get_delegate().object_id(this);
duke@1 129 }
duke@1 130
duke@1 131 /**
duke@1 132 * Returns the
duke@1 133 * root POA from the ORB instance associated with the servant.
duke@1 134 * Subclasses may override this method to return a different POA.
duke@1 135 * @return <code>default_POA</code> the POA associated with the
duke@1 136 * <code>Servant</code>.
duke@1 137 */
duke@1 138 public POA _default_POA() {
duke@1 139 return _get_delegate().default_POA(this);
duke@1 140 }
duke@1 141
duke@1 142 /**
duke@1 143 * Checks to see if the specified <code>repository_id</code> is present
duke@1 144 * on the list returned by <code>_all_interfaces()</code> or is the
duke@1 145 * <code>repository_id</code> for the generic CORBA Object.
duke@1 146 * @param repository_id the <code>repository_id</code>
duke@1 147 * to be checked in the repository list or against the id
duke@1 148 * of generic CORBA objects.
duke@1 149 * @return <code>is_a</code> boolean indicating whether the specified
duke@1 150 * <code>repository_id</code> is
duke@1 151 * in the repository list or is same as a generic CORBA
duke@1 152 * object.
duke@1 153 */
duke@1 154 public boolean _is_a(String repository_id) {
duke@1 155 return _get_delegate().is_a(this, repository_id);
duke@1 156 }
duke@1 157
duke@1 158 /**
duke@1 159 * Checks for the existence of an
duke@1 160 * <code>Object</code>.
duke@1 161 * The <code>Servant</code> provides a default implementation of
duke@1 162 * <code>_non_existent()</code> that can be overridden by derived servants.
duke@1 163 * @return <code>non_existent</code> <code>true</code> if that object does
duke@1 164 * not exist, <code>false</code> otherwise.
duke@1 165 */
duke@1 166 public boolean _non_existent() {
duke@1 167 return _get_delegate().non_existent(this);
duke@1 168 }
duke@1 169
duke@1 170 // Ken and Simon will ask about editorial changes
duke@1 171 // needed in IDL to Java mapping to the following
duke@1 172 // signature.
duke@1 173 /**
duke@1 174 * Returns an object in the Interface Repository
duke@1 175 * which provides type information that may be useful to a program.
duke@1 176 * <code>Servant</code> provides a default implementation of
duke@1 177 * <code>_get_interface()</code>
duke@1 178 * that can be overridden by derived servants if the default
duke@1 179 * behavior is not adequate.
duke@1 180 * @return <code>get_interface</code> type information that corresponds to this servant.
duke@1 181 */
duke@1 182 /*
duke@1 183 public org.omg.CORBA.Object _get_interface() {
duke@1 184 return _get_delegate().get_interface(this);
duke@1 185 }
duke@1 186 */
duke@1 187
duke@1 188 // _get_interface_def() replaces the _get_interface() method
duke@1 189
duke@1 190 /**
duke@1 191 * Returns an <code>InterfaceDef</code> object as a
duke@1 192 * <code>CORBA::Object</code> that defines the runtime type of the
duke@1 193 * <code>CORBA::Object</code> implemented by the <code>Servant</code>.
duke@1 194 * The invoker of <code>_get_interface_def</code>
duke@1 195 * must narrow the result to an <code>InterfaceDef</code> in order
duke@1 196 * to use it.
duke@1 197 * <P>This default implementation of <code>_get_interface_def()</code>
duke@1 198 * can be overridden
duke@1 199 * by derived servants if the default behavior is not adequate.
duke@1 200 * As defined in the CORBA 2.3.1 specification, section 11.3.1, the
duke@1 201 * default behavior of <code>_get_interface_def()</code> is to use
duke@1 202 * the most derived
duke@1 203 * interface of a static servant or the most derived interface retrieved
duke@1 204 * from a dynamic servant to obtain the <code>InterfaceDef</code>.
duke@1 205 * This behavior must
duke@1 206 * be supported by the <code>Delegate</code> that implements the
duke@1 207 * <code>Servant</code>.
duke@1 208 * @return <code>get_interface_def</code> an <code>InterfaceDef</code>
duke@1 209 * object as a
duke@1 210 * <code>CORBA::Object</code> that defines the runtime type of the
duke@1 211 * <code>CORBA::Object</code> implemented by the <code>Servant</code>.
duke@1 212 */
duke@1 213 public org.omg.CORBA.Object _get_interface_def()
duke@1 214 {
duke@1 215 // First try to call the delegate implementation class's
duke@1 216 // "Object get_interface_def(..)" method (will work for ORBs
duke@1 217 // whose delegates implement this method).
duke@1 218 // Else call the delegate implementation class's
duke@1 219 // "InterfaceDef get_interface(..)" method using reflection
duke@1 220 // (will work for ORBs that were built using an older version
duke@1 221 // of the Delegate interface with a get_interface method
duke@1 222 // but not a get_interface_def method).
duke@1 223
duke@1 224 org.omg.PortableServer.portable.Delegate delegate = _get_delegate();
duke@1 225 try {
duke@1 226 // If the ORB's delegate class does not implement
duke@1 227 // "Object get_interface_def(..)", this will throw
duke@1 228 // an AbstractMethodError.
duke@1 229 return delegate.get_interface_def(this);
duke@1 230 } catch( AbstractMethodError aex ) {
duke@1 231 // Call "InterfaceDef get_interface(..)" method using reflection.
duke@1 232 try {
duke@1 233 Class[] argc = { org.omg.PortableServer.Servant.class };
duke@1 234 java.lang.reflect.Method meth =
duke@1 235 delegate.getClass().getMethod("get_interface", argc);
duke@1 236 Object[] argx = { this };
duke@1 237 return (org.omg.CORBA.Object)meth.invoke(delegate, argx);
duke@1 238 } catch( java.lang.reflect.InvocationTargetException exs ) {
duke@1 239 Throwable t = exs.getTargetException();
duke@1 240 if (t instanceof Error) {
duke@1 241 throw (Error) t;
duke@1 242 } else if (t instanceof RuntimeException) {
duke@1 243 throw (RuntimeException) t;
duke@1 244 } else {
duke@1 245 throw new org.omg.CORBA.NO_IMPLEMENT();
duke@1 246 }
duke@1 247 } catch( RuntimeException rex ) {
duke@1 248 throw rex;
duke@1 249 } catch( Exception exr ) {
duke@1 250 throw new org.omg.CORBA.NO_IMPLEMENT();
duke@1 251 }
duke@1 252 }
duke@1 253 }
duke@1 254
duke@1 255 // methods for which the user must provide an
duke@1 256 // implementation
duke@1 257 /**
duke@1 258 * Used by the ORB to obtain complete type
duke@1 259 * information from the servant.
duke@1 260 * @param poa POA with which the servant is associated.
duke@1 261 * @param objectId is the id corresponding to the object
duke@1 262 * associated with this servant.
duke@1 263 * @return list of type information for the object.
duke@1 264 */
duke@1 265 abstract public String[] _all_interfaces( POA poa, byte[] objectId);
duke@1 266 }

mercurial