GNU Classpath (0.18) | ||
Frames | No Frames |
1: /* Servant.java -- 2: Copyright (C) 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package org.omg.PortableServer; 40: 41: import org.omg.CORBA.BAD_OPERATION; 42: import org.omg.CORBA.NO_IMPLEMENT; 43: import org.omg.CORBA.OBJECT_NOT_EXIST; 44: import org.omg.CORBA.ORB; 45: import org.omg.PortableServer.POAPackage.ServantNotActive; 46: import org.omg.PortableServer.POAPackage.WrongPolicy; 47: import org.omg.PortableServer.portable.Delegate; 48: import gnu.CORBA.Poa.ORB_1_4; 49: import gnu.CORBA.Poa.gnuPOA; 50: 51: /** 52: * <p> 53: * The servant is responsible for handling the method invocation on the 54: * target object. It can be one servant per object, or the same servant can 55: * support several (possibly all) objects, associated with the given POA. 56: * </p> <p> 57: * Till JDK 1.3 inclusive, a typical IDL to java compiler generates an 58: * implementation base (name pattern _*ImplBase.java) that is derived from the 59: * {@link org.omg.CORBA.portable.ObjectImpl}. Since JDK 1.4 the implementation 60: * base is derived from the Servant, also having a different name pattern 61: * (*POA.java). This suffix may be confusing, as the servant itself is 62: * <i>not</i> POA nor it is derived from it. 63: * </p><p> 64: * In both cases, the implementation base also inherits an interface, containing 65: * definitions of the application specific methods. The application programmer 66: * writes a child of the implementation base, implementing these methods 67: * for the application-specific functionality. The ObjectImpl is connected 68: * directly to the ORB. The Servant is connected to POA that can be obtained 69: * from the ORB. 70: * </p><p> 71: * If the servant is connected to more than one object, the exact object 72: * being currently served can be identified with {@link #_object_id}. 73: * </p><p> 74: * The derivativ of Servant, being directly connected to serve requests, 75: * must inherit either from {@link org.omg.CORBA.portable.InvokeHandler} 76: * or from {@link org.omg.PortableServer.DynamicImplementation}). 77: * </p><p> 78: * The Servant type is a CORBA <code>native</code> type. 79: * </p> 80: * 81: * @see POA.servant_to_reference(Servant) 82: * 83: * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) 84: */ 85: public abstract class Servant 86: { 87: /** 88: * The delegate, where calls to some Servant methods are forwarded. 89: */ 90: private Delegate delegate; 91: 92: /** 93: * Get the repository ids of all interfaces, supported by the 94: * CORBA object, identified by the passed Id. In the typical code the 95: * passed parameters are ignored, returning an array of repository ids, 96: * supported by the servant implementation. 97: * 98: * @param poa a POA of the given object. 99: * @param object_ID the object Id of the given object. 100: * 101: * @return an array, containing the repository ids. 102: */ 103: public abstract String[] _all_interfaces(POA poa, byte[] object_ID); 104: 105: /** 106: * Get the delegate, where calls to some Servant methods are forwarded. 107: */ 108: public final Delegate _get_delegate() 109: { 110: return delegate; 111: } 112: 113: /** 114: * Get the interface repository definition <code>InterfaceDef</code> for this 115: * Object. By default, forwards request to the delegate. 116: * 117: * @specnote The interface repository is officially not implemented up till 118: * JDK 1.5 inclusive. The delegate throws NO_IMPLEMENT, always. 119: */ 120: public org.omg.CORBA.Object _get_interface_def() 121: { 122: throw new NO_IMPLEMENT(); 123: } 124: 125: /** 126: * Checks if the passed servant is an instance of the given CORBA IDL type. 127: * By default, forwards the requet to the delegate. 128: * 129: * @param a_servant a servant to check. 130: * @param an_id a repository ID, representing an IDL type for that the 131: * servant must be checked. 132: * 133: * @return true if the servant is an instance of the given type, false 134: * otherwise. 135: */ 136: public boolean _is_a(String repository_id) 137: { 138: return delegate.is_a(this, repository_id); 139: } 140: 141: /** 142: * Determines if the server object for this reference has already 143: * been destroyed. By default, forwards request to the delegate. 144: * 145: * @return true if the object has been destroyed, false otherwise. 146: */ 147: public boolean _non_existent() 148: { 149: return delegate.non_existent(this); 150: } 151: 152: /** 153: * Returns the ORB that is directly associated with the given servant. 154: * In this implementation, the method is overridden to return 155: */ 156: public final ORB _orb() 157: { 158: return delegate.orb(this); 159: } 160: 161: /** 162: * Returns the root POA of the ORB instance, associated with this servant. 163: * It is the same POA that would be returned by resolving the initial 164: * reference "RootPOA" for that orb. By default, forwards request to the 165: * delegate. 166: * 167: * @see ORB.resolve_initial_references 168: */ 169: public POA _default_POA() 170: { 171: return delegate == null ? null : delegate.default_POA(this); 172: } 173: 174: /** 175: * Return the invocation target object identifier as a byte array. 176: * This is typically used when the same servant serves multiple objects, 177: * and the object id can encapsulated the whole description of the 178: * object. 179: * 180: * This method returns correct values even when the same 181: * servant serves several objects in parallel threads. The ORB maintains the 182: * thread to invocation data map for all calls that are currently being 183: * processed. 184: */ 185: public final byte[] _object_id() 186: { 187: if (delegate != null) 188: return delegate.object_id(this); 189: else 190: throw new OBJECT_NOT_EXIST(); 191: } 192: 193: /** 194: * Get POA that is directly associated with the given servant. 195: * By default, forwards request to the delegate. 196: */ 197: public final POA _poa() 198: { 199: return delegate.poa(this); 200: } 201: 202: /** 203: * Set the delegate for this servant. 204: */ 205: public final void _set_delegate(Delegate a_delegate) 206: { 207: delegate = a_delegate; 208: } 209: 210: /** 211: * Obtains the CORBA object reference that is a current invocation target for 212: * the given servant. This is important when the same servant serves 213: * multiple objects. If the servant is not yet connected to the passed 214: * orb, the method will try to connect it to that orb on POA, returned 215: * by the method {@link _default_POA}. That method can be overridden to 216: * get poa where the object must be automatically connected when 217: * calling this method. 218: * 219: * @param an_orb the ORB with relate to that the object is requested. 220: */ 221: public final org.omg.CORBA.Object _this_object(ORB an_orb) 222: { 223: if (delegate != null) 224: return delegate.this_object(this); 225: else 226: { 227: if (an_orb instanceof ORB_1_4) 228: { 229: ORB_1_4 m_orb = (ORB_1_4) an_orb; 230: 231: gnuPOA dp = (gnuPOA) _default_POA(); 232: if (dp == null) 233: dp = m_orb.rootPOA; 234: 235: try 236: { 237: return dp.servant_to_reference(this); 238: } 239: catch (WrongPolicy unexp) 240: { 241: BAD_OPERATION bad = new BAD_OPERATION(); 242: bad.initCause(unexp); 243: throw bad; 244: } 245: catch (ServantNotActive ex) 246: { 247: try 248: { 249: return dp.id_to_reference(dp.activate_object(this)); 250: } 251: catch (Exception unexp) 252: { 253: unexp.initCause(ex); 254: 255: BAD_OPERATION bad = new BAD_OPERATION(); 256: bad.initCause(unexp); 257: throw bad; 258: } 259: } 260: } 261: } 262: throw new OBJECT_NOT_EXIST(); 263: } 264: 265: /** 266: * Obtains the CORBA object reference that is a current invocation target for 267: * the given servant. This is important when the same servant serves 268: * multiple objects. This method required the servant to be connected 269: * to a single orb, and a delegate set. 270: * 271: * This method returns correct values even when the same 272: * servant serves several objects in parallel threads. The ORB maintains the 273: * thread to invocation data map for all calls that are currently being 274: * processed. 275: */ 276: public final org.omg.CORBA.Object _this_object() 277: { 278: if (delegate != null) 279: return _this_object(_orb()); 280: else 281: { 282: POA def = _default_POA(); 283: if (def instanceof gnuPOA) 284: return _this_object(((gnuPOA) def).orb()); 285: } 286: throw new OBJECT_NOT_EXIST(); 287: }
GNU Classpath (0.18) |