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