/** * 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" ); } }
/** * 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; }
/** * Make an invocation and return a stream from where the results can be read * and throw ApplicationException, where applicable. */ org.omg.CORBA.portable.InputStream s_invoke(InvokeHandler handler) throws ApplicationException { try { poa.m_orb.currents.put(Thread.currentThread(), this); org.omg.CORBA.portable.InputStream input = v_invoke(handler); if (!exceptionReply) { return input; } else { input.mark(500); String id = input.read_string(); try { input.reset(); } catch (IOException ex) { InternalError ierr = new InternalError(); ierr.initCause(ex); throw ierr; } throw new ApplicationException(id, input); } } finally { poa.m_orb.currents.remove(Thread.currentThread()); } }
/** * Return the associated invocation handler. */ public InvokeHandler getHandler(String operation, CookieHolder cookie, boolean forwarding_allowed ) throws gnuForwardRequest { if (servant != null && !noRetain) { 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 ); } } }
/** * Make an invocation and store the result in the fields of this Request. Used * with DII only. */ public void invoke() { InvokeHandler handler = object.getHandler(operation(), cookie, false); if (handler instanceof DynamicImpHandler) { DynamicImplementation dyn = ((DynamicImpHandler) handler).servant; if (serverRequest == null) { serverRequest = new LocalServerRequest(this); } try { poa.m_orb.currents.put(Thread.currentThread(), this); dyn.invoke(serverRequest); } finally { poa.m_orb.currents.remove(Thread.currentThread()); } } else { org.omg.CORBA.portable.InputStream input = v_invoke(handler); if (!exceptionReply) { NamedValue arg; // Read return value, if set. if (m_result != null) { m_result.value().read_value(input, m_result.value().type()); } // Read returned parameters, if set. if (m_args != null) { for (int i = 0; i < m_args.count(); i++) { try { arg = m_args.item(i); // Both ARG_INOUT and ARG_OUT have this binary flag set. if ((arg.flags() & ARG_OUT.value) != 0) { arg.value().read_value(input, arg.value().type()); } } catch (Bounds ex) { Unexpected.error(ex); } } } } else// User exception reply { // Prepare an Any that will hold the exception. gnuAny exc = new gnuAny(); exc.insert_Streamable(new StreamHolder(input)); UnknownUserException unuex = new UnknownUserException(exc); m_environment.exception(unuex); } } }
/** * Return the associated invocation handler. */ public InvokeHandler getHandler(String method, CookieHolder cookie) { return object.getHandler(method, cookie, false); }