📄 gnuservantobject.java
字号:
/* gnuServantObject.java -- Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package gnu.CORBA.Poa;import gnu.CORBA.GIOP.ReplyHeader;import gnu.CORBA.IorDelegate;import gnu.CORBA.IorObject;import gnu.CORBA.Interceptor.gnuServerRequestInfo;import gnu.CORBA.typecodes.RecordTypeCode;import gnu.CORBA.IOR;import gnu.CORBA.IorProvider;import gnu.CORBA.Minor;import gnu.CORBA.ObjectCreator;import gnu.CORBA.Unexpected;import gnu.CORBA.ResponseHandlerImpl;import gnu.CORBA.StreamHolder;import org.omg.CORBA.Any;import org.omg.CORBA.BAD_OPERATION;import org.omg.CORBA.BAD_PARAM;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.OBJECT_NOT_EXIST;import org.omg.CORBA.OBJ_ADAPTER;import org.omg.CORBA.ORB;import org.omg.CORBA.SystemException;import org.omg.CORBA.TCKind;import org.omg.CORBA.TRANSIENT;import org.omg.CORBA.UserException;import org.omg.CORBA.portable.InputStream;import org.omg.CORBA.portable.InvokeHandler;import org.omg.CORBA.portable.ObjectImpl;import org.omg.CORBA.portable.OutputStream;import org.omg.CORBA.portable.ResponseHandler;import org.omg.PortableInterceptor.ForwardRequest;import org.omg.PortableInterceptor.ServerRequestInterceptorOperations;import org.omg.PortableServer.CurrentOperations;import org.omg.PortableServer.DynamicImplementation;import org.omg.PortableServer.ImplicitActivationPolicyValue;import org.omg.PortableServer.POA;import org.omg.PortableServer.POAManager;import org.omg.PortableServer.POAManagerPackage.State;import org.omg.PortableServer.Servant;import org.omg.PortableServer.ServantLocatorPackage.CookieHolder;import org.omg.PortableServer.ServantRetentionPolicyValue;import org.omg.PortableServer.portable.Delegate;import java.io.IOException;import java.util.Arrays;/** * Represents a CORBA object, being locally served by the associated servant. * The calls to the object are forwarded to the calls to the servant. * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */public class gnuServantObject extends ObjectImpl implements org.omg.CORBA.Object, InvokeHandler, CurrentOperations, IorProvider{ /** * The associated servant that must also implement the {@link InvokeHandler} * interface. This value can be temporary null if the object was created using * POA.create_reference or POA.create_reference_with_id, private to force * always to use {@link setServant}. */ private Servant servant; /** * The Id of this object. */ public final byte[] Id; /** * The poa that takes care about this object. */ public final gnuPOA poa; /** * The POA manager, used to control the work of this object. */ public final POAManager manager; /** * The orb. */ public final ORB_1_4 orb; /** * The object repository ids, if they were specified separately. Normally, the * ids are requested from the servant. */ public final String[] repository_ids; /** * Create an object with no connected servant. The servant must be set later. * * @param a_repository_ids an array of repository ids, can be null (then ids * will be requested from the servant). * @param an_id the object id. * @param a_poa the POA. */ public gnuServantObject(String[] a_repository_ids, byte[] an_id, gnuPOA a_poa, ORB_1_4 an_orb ) { repository_ids = a_repository_ids; Id = an_id; manager = a_poa.the_POAManager(); poa = a_poa; orb = an_orb; } /** * Get the IOR as it would be for this object. */ public IOR getIor() { return orb.getLocalIor(this); } /** * Create a servant object, associated with the passed servant. * * @param a_servant a servant, serving this object. * @param an_id an Object Id for this object. * * @throws BAD_PARAM if the passed servant is not an {@link InvokeHandler}. */ public gnuServantObject(Servant a_servant, byte[] an_id, ORB_1_4 an_orb, gnuPOA a_poa ) { Id = an_id; setServant(a_servant); poa = a_poa; if (poa != null) { manager = poa.the_POAManager(); } else { manager = null; } repository_ids = null; orb = an_orb; } /** * Set a servant, if it has not been previously set. * * @param a_servant a servant to set, can be null to indicate the necessity * for the subsequent activation. * * @throws BAD_PARAM if the passed servant is not an {@link InvokeHandler} or * {@link DynamicImplementation} and also not null. */ public void setServant(Servant a_servant) { if (a_servant != null && !(a_servant instanceof InvokeHandler) && !(a_servant instanceof DynamicImplementation) ) { throw new BAD_PARAM("Must be either InvokeHandler or " + "DynamicImplementation, but is " + a_servant ); } servant = a_servant; } /** * Returns the associated servant. */ public Servant getServant() { return servant; } /** * Return the associated invocation handler. */ public InvokeHandler getHandler(String operation, CookieHolder cookie, boolean forwarding_allowed ) throws gnuForwardRequest { if (servant != null) { return servantToHandler(servant); } else { // Use servant locator to locate the servant. if (poa.servant_locator != null) { try { servant = poa.servant_locator.preinvoke(Id, poa, operation, cookie); return servantToHandler(servant); } catch (org.omg.PortableServer.ForwardRequest forw_ex) { if (forwarding_allowed) { throw new gnuForwardRequest(forw_ex.forward_reference); } else { servant = ForwardedServant.create(forw_ex.forward_reference); return servantToHandler(servant); } } } else // Use servant activator to locate the servant. if (poa.applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) && poa.applies(ServantRetentionPolicyValue.RETAIN) ) { try { poa.activate_object_with_id(Id, servant, forwarding_allowed); servant = poa.id_to_servant(Id); return servantToHandler(servant); } catch (gnuForwardRequest forwarded) { throw forwarded; } catch (Exception ex) { BAD_OPERATION bad = new BAD_OPERATION("Unable to activate", Minor.Activation, CompletionStatus.COMPLETED_NO ); bad.initCause(ex); throw bad; } } else if (poa.default_servant != null) { servant = poa.default_servant; return servantToHandler(servant); } // No servant and no servant manager - throw exception. else { throw new BAD_OPERATION("Unable to activate", Minor.Activation, CompletionStatus.COMPLETED_NO ); } } } /** * Convert the servant to invocation handler. */ public InvokeHandler servantToHandler(Servant a_servant) { if (a_servant instanceof InvokeHandler) { return (InvokeHandler) a_servant; } else if (a_servant instanceof DynamicImplementation) { return new DynamicImpHandler((DynamicImplementation) a_servant); } else { throw new BAD_OPERATION(a_servant + " must be either InvokeHandler or " + "POA DynamicImplementation" ); } } /** * Create a servant object, associated with the passed servant. Requests the * object id from the servant. Depending on the policies of the servants POA, * the calls are eithe not synchronized or synchronized on POA or ORB. * * @param a_servant a servant, serving this object. * @param an_id an Object Id for this object. */ public gnuServantObject(Servant a_servant, gnuPOA a_poa) { this(a_servant, a_servant._object_id(), (ORB_1_4) a_servant._orb(), a_poa); } /** * Delegates call to servant, passing the poa and Id. */ public String[] _ids() { if (repository_ids == null) { return getServant()._all_interfaces(poa, Id); } else { return repository_ids; } } /** * Gets a string representation. */ public String toString() { StringBuffer b = new StringBuffer("Servant object ("); for (int i = 0; i < Id.length; i++) { b.append(Integer.toHexString(Id [ i ] & 0xFF)); b.append(' '); } b.append(')'); return b.toString(); } /** * Always returns true. */ public boolean _is_local() { return true; } /** * Check if this object could be named by the given repository id. * * @param idl_id the repository id to check. * * @return true if it is one of the possible repository ids of this object. */ public boolean _is_a(String idl_id) { String[] maybe = _ids(); for (int i = 0; i < maybe.length; i++) { if (maybe [ i ].equals(idl_id)) { return true; } } return false; } /** * Get an ORB, associated with the servant of this object. * * @return */ public ORB _orb() { return getServant()._orb(); } /** * Handle the invocation (delegates to servant). * * @throws TRANSIENT minor 0x535503e9 if the POA is in discarding mode. * @throws OBJ_ADAPTER minor 0x535503ea if the POA is inactivated. * @throws OBJECT_NOT_EXISTS minor 0x535503ec if this object is inactivated. * * @specnote see {@link POAManagerOperations} for specnotes about the minor * codes.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -