public OutputStream _invoke()

in plugins/corba/geronimo-corba/src/main/java/org/apache/geronimo/corba/StandardServant.java [148:310]


    public OutputStream _invoke(String operationName, InputStream _in, ResponseHandler reply) throws SystemException {
        // get the method object
        Method method = (Method) operations.get(operationName);

        org.omg.CORBA_2_3.portable.InputStream in = (org.omg.CORBA_2_3.portable.InputStream) _in;

        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        Context oldContext = RootContext.getComponentContext();
        try {
            Thread.currentThread().setContextClassLoader(ejbDeployment.getClassLoader());
            RootContext.setComponentContext(enc);

            // read in all of the arguments
            Class[] parameterTypes = method.getParameterTypes();
            Object[] arguments = new Object[parameterTypes.length];
            for (int i = 0; i < parameterTypes.length; i++) {
                Class parameterType = parameterTypes[i];
                arguments[i] = Util.readObject(parameterType, in);
            }

            // invoke the method
            Object result = null;
            try {

                if (log.isDebugEnabled()) log.debug("Calling " + method.getName());

                if (method.getDeclaringClass() == javax.ejb.EJBObject.class) {
                    if (method.equals(GETHANDLE)) {
                        result = ejbDeployment.getEjbObject(primaryKey).getHandle();
                    } else if (method.equals(GETPRIMARYKEY)) {
                        result = ejbDeployment.getEjbObject(primaryKey).getPrimaryKey();
                    } else if (method.equals(ISIDENTICAL)) {
                        org.omg.CORBA.Object thisObject = this._this_object();
                        org.omg.CORBA.Object otherObject = (org.omg.CORBA.Object)arguments[0];
                        result = new Boolean(thisObject._is_equivalent(otherObject));
                    } else if (method.equals(GETEJBHOME)) {
                        result = ejbDeployment.getEJBHome();
                    } else if (method.equals(REMOVE)) {
                        try {
                            ejbDeployment.getEjbObject(primaryKey).remove();
                            result = null;
                        } catch (RemoveException e) {
                            return Util.writeUserException(method, reply, e);
                        }
                    } else {
                        throw new UnsupportedOperationException("unknown method: " + method);
                    }
                } else if (method.getDeclaringClass() == javax.ejb.EJBHome.class) {
                   if (method.equals(GETEJBMETADATA)) {
                        result = ejbDeployment.getEJBHome().getEJBMetaData();
                    } else if (method.equals(GETHOMEHANDLE)) {
                        result = ejbDeployment.getEJBHome().getHomeHandle();
                    } else if (method.equals(REMOVE_W_HAND)) {
                        CORBAHandle handle = (CORBAHandle) arguments[0];
                        try {
                            if (ejbDeployment.getComponentType() == BeanType.STATELESS) {
                                if (handle == null) {
                                    throw new RemoveException("Handle is null");
                                }
                                Class remoteInterface = ejbDeployment.getRemoteInterface();


                                try {
                                    EJBObject narrowed = (EJBObject)PortableRemoteObject.narrow(handle.getEJBObject(), remoteInterface);
                                    if (narrowed == null) {
                                        throw new RemoteException("Handle does not hold a " + remoteInterface.getName());
                                    }
                                } catch (ClassCastException e) {
                                    throw new RemoteException("Handle does not hold a " + remoteInterface.getName(), e);
                                }
                            } else {
                                try {
                                    Object handleKey = handle.getPrimaryKey();
                                    RpcContainer container = (RpcContainer) ejbDeployment.getContainer();
                                    result = container.invoke(ejbDeployment.getDeploymentId(), interfaceType, method.getDeclaringClass(), method, arguments, handleKey);
                                } catch (OpenEJBException e) {
                                    Throwable cause = e.getCause();
                                    if (cause instanceof Exception) {
                                        Exception exception = (Exception) cause;
                                        return Util.writeUserException(method, reply, exception);
                                    }
                                    throw cause;
                                }
                            }
                        } catch (RemoveException e) {

                            return Util.writeUserException(method, reply, e);
                        }
                        result = null;
                    } else if (method.equals(REMOVE_W_KEY)) {
                        try {
                            ejbDeployment.getEJBHome().remove(arguments[0]);
                            result = null;
                        } catch (RemoveException e) {
                            return Util.writeUserException(method, reply, e);
                        }
                    } else {
                        throw new UnsupportedOperationException("unknown method: " + method);
                    }
                } else {
                    try {
                        RpcContainer container = (RpcContainer) ejbDeployment.getContainer();
                        result = container.invoke(ejbDeployment.getDeploymentId(), interfaceType, method.getDeclaringClass(), method, arguments, primaryKey);
                        // some methods like create() or find* return ProxyInfo objects.  We need to
                        // turn those into real EJB remote references.
                        if (result instanceof ProxyInfo || method.getName().startsWith("find")) {
                            result = createProxy(result);
                        }
                    } catch (OpenEJBException e) {
                        Throwable cause = e.getCause();
                        if (cause instanceof Exception) {
                            Exception exception = (Exception) cause;
                            return Util.writeUserException(method, reply, exception);
                        }
                        throw cause;
                    }
                }
            } catch (TransactionRolledbackException e) {
                log.debug("TransactionRolledbackException", e);
                throw (SystemException)new TRANSACTION_ROLLEDBACK(e.toString()).initCause(e);
            } catch (TransactionRequiredException e) {
                log.debug("TransactionRequiredException", e);
                throw (SystemException)new TRANSACTION_REQUIRED(e.toString()).initCause(e);
            } catch (InvalidTransactionException e) {
                log.debug("InvalidTransactionException", e);
                throw (SystemException)new INVALID_TRANSACTION(e.toString()).initCause(e);
            } catch (NoSuchObjectException e) {
                log.debug("NoSuchObjectException", e);
                throw (SystemException)new OBJECT_NOT_EXIST(e.toString()).initCause(e);
            } catch (AccessException e) {
                log.debug("AccessException", e);
                throw (SystemException)new NO_PERMISSION(e.toString()).initCause(e);
            } catch (MarshalException e) {
                log.debug("MarshalException", e);
                throw (SystemException)new MARSHAL(e.toString()).initCause(e);
            } catch (RemoteException e) {
                log.debug("RemoteException", e);
                throw (SystemException)new UnknownException(e).initCause(e);
            } catch (RuntimeException e) {
                log.debug("RuntimeException", e);
                RemoteException remoteException = new RemoteException(e.getClass().getName() + " thrown from " + ejbDeployment.getDeploymentId() + ": " + e.getMessage(), e);
                throw new UnknownException(remoteException);
            } catch (Error e) {
                log.debug("Error", e);
                RemoteException remoteException = new RemoteException(e.getClass().getName() + " thrown from " + ejbDeployment.getDeploymentId() + ": " + e.getMessage(), e);
                throw new UnknownException(remoteException);
            } catch (Throwable e) {
                log.warn("Unexpected throwable", e);
                throw (SystemException)new UNKNOWN("Unknown exception type " + e.getClass().getName() + ": " + e.getMessage()).initCause(e);
            }

            // creat the output stream
            org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();

            // write the output value
            Util.writeObject(method.getReturnType(), result, out);

            return out;
        } finally {
            Thread.currentThread().setContextClassLoader(oldClassLoader);
            RootContext.setComponentContext(oldContext);
        }
    }