dain        2005/06/24 03:54:15

  Modified:    modules/core/src/java/org/openejb/corba/util
                        ClientContextHolderStub.java
                        DynamicStubClassLoader.java
                        StubMethodInterceptor.java Util.java
                        UtilDelegateImpl.java
  Removed:     modules/core/src/java/org/openejb/corba/util
                        StubDelegateImpl.java
  Log:

  Switched over to StandardServent instead of generating ties
  Fixed client context propigation to objects nested in a graph
  Removed stub delegate
  
  Revision  Changes    Path
  1.4       +60 -59    
openejb/modules/core/src/java/org/openejb/corba/util/ClientContextHolderStub.java
  
  Index: ClientContextHolderStub.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/util/ClientContextHolderStub.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ClientContextHolderStub.java      23 Jun 2005 06:59:19 -0000      1.3
  +++ ClientContextHolderStub.java      24 Jun 2005 07:54:14 -0000      1.4
  @@ -1,67 +1,68 @@
   /**
  -   * Redistribution and use of this software and associated documentation
  -   * ("Software"), with or without modification, are permitted provided
  -   * that the following conditions are met:
  -   *
  -   * 1. Redistributions of source code must retain copyright
  -   *    statements and notices.  Redistributions must also contain a
  -   *    copy of this document.
  -   *
  -   * 2. Redistributions in binary form must reproduce the
  -   *    above copyright notice, this list of conditions and the
  -   *    following disclaimer in the documentation and/or other
  -   *    materials provided with the distribution.
  -   *
  -   * 3. The name "OpenEJB" must not be used to endorse or promote
  -   *    products derived from this Software without prior written
  -   *    permission of The OpenEJB Group.  For written permission,
  -   *    please contact [EMAIL PROTECTED]
  -   *
  -   * 4. Products derived from this Software may not be called "OpenEJB"
  -   *    nor may "OpenEJB" appear in their names without prior written
  -   *    permission of The OpenEJB Group. OpenEJB is a registered
  -   *    trademark of The OpenEJB Group.
  -   *
  -   * 5. Due credit should be given to the OpenEJB Project
  -   *    (http://openejb.org/).
  -   *
  -   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
  -   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
  -   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  -   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
  -   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  -   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  -   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  -   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  -   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  -   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  -   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  -   * OF THE POSSIBILITY OF SUCH DAMAGE.
  -   *
  -   * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
  -   *
  -   * $Id$
  -   */
  -  package org.openejb.corba.util;
  + * Redistribution and use of this software and associated documentation
  + * ("Software"), with or without modification, are permitted provided
  + * that the following conditions are met:
  + *
  + * 1. Redistributions of source code must retain copyright
  + *    statements and notices.  Redistributions must also contain a
  + *    copy of this document.
  + *
  + * 2. Redistributions in binary form must reproduce the
  + *    above copyright notice, this list of conditions and the
  + *    following disclaimer in the documentation and/or other
  + *    materials provided with the distribution.
  + *
  + * 3. The name "OpenEJB" must not be used to endorse or promote
  + *    products derived from this Software without prior written
  + *    permission of The OpenEJB Group.  For written permission,
  + *    please contact [EMAIL PROTECTED]
  + *
  + * 4. Products derived from this Software may not be called "OpenEJB"
  + *    nor may "OpenEJB" appear in their names without prior written
  + *    permission of The OpenEJB Group. OpenEJB is a registered
  + *    trademark of The OpenEJB Group.
  + *
  + * 5. Due credit should be given to the OpenEJB Project
  + *    (http://openejb.org/).
  + *
  + * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
  + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
  + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
  + * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  + * OF THE POSSIBILITY OF SUCH DAMAGE.
  + *
  + * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
  + *
  + * $Id$
  + */
  +package org.openejb.corba.util;
   
  -  import javax.rmi.CORBA.Stub;
  +import javax.rmi.CORBA.Stub;
   
  -  import org.openejb.corba.ClientContext;
  -  import org.openejb.corba.ClientContextHolder;
  +import org.openejb.corba.ClientContext;
  +import org.openejb.corba.ClientContextHolder;
  +import org.openejb.corba.ClientContextManager;
   
  -  /**
  -   * @version $Revision$ $Date$
  -   */
  -  public abstract class ClientContextHolderStub extends Stub implements 
ClientContextHolder {
  -      private ClientContext clientContext;
  +/**
  + * @version $Revision$ $Date$
  + */
  +public abstract class ClientContextHolderStub extends Stub implements 
ClientContextHolder {
  +    private final ClientContext clientContext;
   
  -      public ClientContext getClientContext() {
  -          return clientContext;
  -      }
  +    protected ClientContextHolderStub() {
  +        clientContext = ClientContextManager.getClientContext();
  +    }
   
  -      public void setClientContext(ClientContext clientContext) {
  -          this.clientContext = clientContext;
  -      }
  -  }
  +    public ClientContext getClientContext() {
  +        return clientContext;
  +    }
  +}
   
   
  
  
  
  1.4       +3 -4      
openejb/modules/core/src/java/org/openejb/corba/util/DynamicStubClassLoader.java
  
  Index: DynamicStubClassLoader.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/util/DynamicStubClassLoader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DynamicStubClassLoader.java       23 Jun 2005 06:59:19 -0000      1.3
  +++ DynamicStubClassLoader.java       24 Jun 2005 07:54:14 -0000      1.4
  @@ -66,7 +66,6 @@
   import org.apache.geronimo.gbean.GBeanLifecycle;
   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   import org.openejb.corba.compiler.PortableStubCompiler;
  -import org.openejb.corba.ClientContextHolder;
   
   
   /**
  @@ -113,7 +112,7 @@
           try {
               Enhancer enhancer = new Enhancer();
               enhancer.setSuperclass(ClientContextHolderStub.class);
  -            enhancer.setInterfaces(new Class[]{iface, 
ClientContextHolder.class});
  +            enhancer.setInterfaces(new Class[]{iface});
               enhancer.setCallbackFilter(FILTER);
               enhancer.setCallbackTypes(new Class[]{NoOp.class, 
MethodInterceptor.class, FixedValue.class});
               enhancer.setUseFactory(false);
  
  
  
  1.4       +13 -160   
openejb/modules/core/src/java/org/openejb/corba/util/StubMethodInterceptor.java
  
  Index: StubMethodInterceptor.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/util/StubMethodInterceptor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StubMethodInterceptor.java        23 Jun 2005 06:59:19 -0000      1.3
  +++ StubMethodInterceptor.java        24 Jun 2005 07:54:14 -0000      1.4
  @@ -44,39 +44,30 @@
    */
   package org.openejb.corba.util;
   
  -import java.io.Serializable;
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
  -import java.rmi.Remote;
  -import java.rmi.UnexpectedException;
   import java.util.Collections;
   import java.util.HashMap;
   import java.util.Map;
   import javax.rmi.CORBA.Util;
  -import javax.rmi.CORBA.Stub;
  -import javax.rmi.PortableRemoteObject;
   
   import net.sf.cglib.proxy.MethodInterceptor;
   import net.sf.cglib.proxy.MethodProxy;
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   import org.omg.CORBA.SystemException;
   import org.omg.CORBA.portable.ApplicationException;
   import org.omg.CORBA.portable.RemarshalException;
   import org.omg.CORBA.portable.ServantObject;
   import org.omg.CORBA_2_3.portable.InputStream;
   import org.omg.CORBA_2_3.portable.OutputStream;
  -import org.openejb.corba.compiler.IiopOperation;
  -import org.openejb.corba.compiler.PortableStubCompiler;
   import org.openejb.corba.ClientContext;
   import org.openejb.corba.ClientContextManager;
  -import org.openejb.corba.ClientContextHolder;
  +import org.openejb.corba.compiler.IiopOperation;
  +import org.openejb.corba.compiler.PortableStubCompiler;
   
   /**
    * @version $Revision$ $Date$
    */
   public class StubMethodInterceptor implements MethodInterceptor {
  -    private static final Log log = 
LogFactory.getLog(StubMethodInterceptor.class);
       private final Class type;
       private final Map operations;
   
  @@ -92,7 +83,7 @@
       }
   
       public Object intercept(Object proxy, Method method, Object[] args, 
MethodProxy methodProxy) throws Throwable {
  -        Stub stub = ((Stub) proxy);
  +        ClientContextHolderStub stub = (ClientContextHolderStub) proxy;
   
           // get the operation name object
           String operationName = (String) operations.get(method);
  @@ -101,22 +92,8 @@
           }
           ClientContext oldContext = ClientContextManager.getClientContext();
   
  -        //first try the stub
  -        ClientContextHolder holder = (ClientContextHolder) proxy;
  -        ClientContext context = holder.getClientContext();
  -
  -        //if stub got deserialized rather than looked up via CSSBean, it 
might not have the context
  -        if (context == null) {
  -            StubDelegateImpl delegate = 
StubDelegateImpl.getDelegateForStub(stub);
  -            if (delegate == null) {
  -                throw new IllegalStateException("No StubDelegateImpl for 
stub");
  -            }
  -            context = delegate.getClientContext();
  -            //might as well set it for next time
  -            holder.setClientContext(context);
  -        }
           try {
  -            ClientContextManager.setClientContext(context);
  +            ClientContextManager.setClientContext(stub.getClientContext());
   
               while (true) {
                   // if this is a stub to a remote object we invoke over the 
wire
  @@ -128,18 +105,22 @@
                           OutputStream out = (OutputStream) 
stub._request(operationName, true);
   
                           // write the arguments
  -                        writeArguments(method, args, out);
  +                        Class[] parameterTypes = method.getParameterTypes();
  +                        for (int i = 0; i < parameterTypes.length; i++) {
  +                            Class parameterType = parameterTypes[i];
  +                            
org.openejb.corba.util.Util.writeObject(parameterType, args[i], out);
  +                        }
   
                           // send the invocation
                           in = (InputStream) stub._invoke(out);
   
                           // read the result
  -                        Object result = readResult(method.getReturnType(), 
in, context);
  +                        Object result = 
org.openejb.corba.util.Util.readObject(method.getReturnType(), in);
                           return result;
                       } catch (RemarshalException exception) {
                           continue;
                       } catch (ApplicationException exception) {
  -                        readException(method, (InputStream) 
exception.getInputStream());
  +                        org.openejb.corba.util.Util.throwException(method, 
(InputStream) exception.getInputStream());
                       } catch (SystemException e) {
                           throw Util.mapSystemException(e);
                       } finally {
  @@ -194,132 +175,4 @@
               ClientContextManager.setClientContext(oldContext);
           }
       }
  -
  -    private static void writeArguments(Method method, Object[] args, 
OutputStream out) {
  -        Class[] parameterTypes = method.getParameterTypes();
  -        for (int i = 0; i < parameterTypes.length; i++) {
  -            Class parameterType = parameterTypes[i];
  -            writeArgument(parameterType, args[i], out);
  -        }
  -    }
  -
  -    private static void writeArgument(Class type, Object result, 
OutputStream out) {
  -        if (type == void.class) {
  -            // do nothing for a void
  -        } else if (type == boolean.class) {
  -            out.write_boolean(((Boolean) result).booleanValue());
  -        } else if (type == byte.class) {
  -            out.write_octet(((Byte) result).byteValue());
  -        } else if (type == char.class) {
  -            out.write_wchar(((Character) result).charValue());
  -        } else if (type == double.class) {
  -            out.write_double(((Double) result).doubleValue());
  -        } else if (type == float.class) {
  -            out.write_float(((Float) result).floatValue());
  -        } else if (type == int.class) {
  -            out.write_long(((Integer) result).intValue());
  -        } else if (type == long.class) {
  -            out.write_longlong(((Long) result).longValue());
  -        } else if (type == short.class) {
  -            out.write_short(((Short) result).shortValue());
  -        } else if (type == Object.class || type == Serializable.class) {
  -            Util.writeAny(out, result);
  -        } else if (Remote.class.isAssignableFrom(type)) {
  -            Util.writeRemoteObject(out, result);
  -        } else if (org.omg.CORBA.Object.class.isAssignableFrom(type)) {
  -            out.write_Object((org.omg.CORBA.Object) result);
  -        } else {
  -            out.write_value((Serializable) result, type);
  -        }
  -    }
  -
  -    private static Object readResult(Class type, InputStream in, 
ClientContext context) {
  -        if (type == void.class) {
  -            return null;
  -        } else if (type == boolean.class) {
  -            return new Boolean(in.read_boolean());
  -        } else if (type == byte.class) {
  -            return new Byte(in.read_octet());
  -        } else if (type == char.class) {
  -            return new Character(in.read_wchar());
  -        } else if (type == double.class) {
  -            return new Double(in.read_double());
  -        } else if (type == float.class) {
  -            return new Float(in.read_float());
  -        } else if (type == int.class) {
  -            return new Integer(in.read_long());
  -        } else if (type == long.class) {
  -            return new Long(in.read_longlong());
  -        } else if (type == short.class) {
  -            return new Short(in.read_short());
  -        } else if (type == Object.class || type == Serializable.class) {
  -            return Util.readAny(in);
  -        } else if (Remote.class.isAssignableFrom(type)) {
  -            Object o = PortableRemoteObject.narrow(in.read_Object(), type);
  -            if (o instanceof ClientContextHolder) {
  -                ((ClientContextHolder)o).setClientContext(context);
  -            }
  -            return o;
  -        } else if (org.omg.CORBA.Object.class.isAssignableFrom(type)) {
  -            return in.read_Object();
  -        } else {
  -            return in.read_value(type);
  -        }
  -    }
  -
  -    private void readException(Method method, InputStream in) throws 
Throwable {
  -        // read the exception id
  -        final String id = in.read_string();
  -
  -        // get the class name from the id
  -        if (!id.startsWith("IDL:")) {
  -            log.warn("Malformed exception id: " + id);
  -            return;
  -        }
  -
  -        Class[] exceptionTypes = method.getExceptionTypes();
  -        for (int i = 0; i < exceptionTypes.length; i++) {
  -            Class exceptionType = exceptionTypes[i];
  -//            if (RemoteException.class.isAssignableFrom(exceptionType) ||
  -//                    RuntimeException.class.isAssignableFrom(exceptionType) 
) {
  -//                continue;
  -//            }
  -
  -            // Determine the exception id
  -            String exceptionName = exceptionType.getName().replace('.', '/');
  -            if (exceptionName.endsWith("Exception")) {
  -                exceptionName = exceptionName.substring(0, 
exceptionName.length() - "Exception".length());
  -            }
  -            exceptionName += "Ex";
  -            String exceptionId = "IDL:" + exceptionName + ":1.0";
  -            if (id.equals(exceptionId)) {
  -                throw (Throwable) in.read_value(exceptionType);
  -            }
  -        }
  -        throw new UnexpectedException(id);
  -    }
  -
  -//    private static Object copyResult(Class type, Object result, Stub stub) 
throws RemoteException {
  -//        if (type == boolean.class) {
  -//            return result;
  -//        } else if (type == byte.class) {
  -//            return result;
  -//        } else if (type == char.class) {
  -//            return result;
  -//        } else if (type == double.class) {
  -//            return result;
  -//        } else if (type == float.class) {
  -//            return result;
  -//        } else if (type == int.class) {
  -//            return result;
  -//        } else if (type == long.class) {
  -//            return result;
  -//        } else if (type == short.class) {
  -//            return result;
  -//        } else if (Remote.class.isAssignableFrom(type)) {
  -//            return PortableRemoteObject.narrow(Util.copyObject(result, 
stub._orb()), type);
  -//        } else {
  -//            return Util.copyObject(result, stub._orb());
  -//        }
  -//    }
   }
  
  
  
  1.11      +125 -2    
openejb/modules/core/src/java/org/openejb/corba/util/Util.java
  
  Index: Util.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/util/Util.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Util.java 23 Apr 2005 18:43:49 -0000      1.10
  +++ Util.java 24 Jun 2005 07:54:14 -0000      1.11
  @@ -50,9 +50,15 @@
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
  +import java.io.Serializable;
  +import java.rmi.Remote;
  +import java.rmi.UnexpectedException;
  +import java.rmi.RemoteException;
  +import java.lang.reflect.Method;
   import javax.ejb.spi.HandleDelegate;
   import javax.naming.InitialContext;
   import javax.naming.NamingException;
  +import javax.rmi.PortableRemoteObject;
   
   import org.bouncycastle.asn1.DERInputStream;
   import org.bouncycastle.asn1.DERObjectIdentifier;
  @@ -62,6 +68,7 @@
   import org.omg.CORBA.Any;
   import org.omg.CORBA.ORB;
   import org.omg.CORBA.UserException;
  +import org.omg.CORBA.portable.ResponseHandler;
   import org.omg.GSSUP.GSSUPMechOID;
   import org.omg.GSSUP.InitialContextToken;
   import org.omg.GSSUP.InitialContextTokenHelper;
  @@ -69,6 +76,10 @@
   import org.omg.IOP.CodecFactory;
   import org.omg.IOP.ENCODING_CDR_ENCAPS;
   import org.omg.IOP.Encoding;
  +import org.omg.CORBA_2_3.portable.OutputStream;
  +import org.omg.CORBA_2_3.portable.InputStream;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   
   /**
    * Various utility functions.
  @@ -79,7 +90,7 @@
    * @see UtilInitializer
    */
   public final class Util {
  -
  +    private static final Log log = LogFactory.getLog(Util.class);
       private static final byte ASN_TAG_NT_EXPORTED_NAME1 = 0x04;
       private static final byte ASN_TAG_NT_EXPORTED_NAME2 = 0x01;
       private static final byte ASN_TAG_OID = 0x06;
  @@ -401,4 +412,116 @@
           '0', '1', '2', '3', '4', '5', '6', '7',
           '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
       };
  +
  +    public static void writeObject(Class type, Object object, OutputStream 
out) {
  +        if (type == void.class) {
  +            // do nothing for a void
  +        } else if (type == boolean.class) {
  +            out.write_boolean(((Boolean) object).booleanValue());
  +        } else if (type == byte.class) {
  +            out.write_octet(((Byte) object).byteValue());
  +        } else if (type == char.class) {
  +            out.write_wchar(((Character) object).charValue());
  +        } else if (type == double.class) {
  +            out.write_double(((Double) object).doubleValue());
  +        } else if (type == float.class) {
  +            out.write_float(((Float) object).floatValue());
  +        } else if (type == int.class) {
  +            out.write_long(((Integer) object).intValue());
  +        } else if (type == long.class) {
  +            out.write_longlong(((Long) object).longValue());
  +        } else if (type == short.class) {
  +            out.write_short(((Short) object).shortValue());
  +        } else if (type == Object.class || type == Serializable.class) {
  +            javax.rmi.CORBA.Util.writeAny(out, object);
  +        } else if (Remote.class.isAssignableFrom(type)) {
  +            javax.rmi.CORBA.Util.writeRemoteObject(out, object);
  +        } else if (org.omg.CORBA.Object.class.isAssignableFrom(type)) {
  +            out.write_Object((org.omg.CORBA.Object) object);
  +        } else {
  +            out.write_value((Serializable) object, type);
  +        }
  +    }
  +
  +    public static Object readObject(Class type, InputStream in) {
  +        if (type == void.class) {
  +            return null;
  +        } else if (type == boolean.class) {
  +            return new Boolean(in.read_boolean());
  +        } else if (type == byte.class) {
  +            return new Byte(in.read_octet());
  +        } else if (type == char.class) {
  +            return new Character(in.read_wchar());
  +        } else if (type == double.class) {
  +            return new Double(in.read_double());
  +        } else if (type == float.class) {
  +            return new Float(in.read_float());
  +        } else if (type == int.class) {
  +            return new Integer(in.read_long());
  +        } else if (type == long.class) {
  +            return new Long(in.read_longlong());
  +        } else if (type == short.class) {
  +            return new Short(in.read_short());
  +        } else if (type == Object.class || type == Serializable.class) {
  +            return javax.rmi.CORBA.Util.readAny(in);
  +        } else if (Remote.class.isAssignableFrom(type)) {
  +            return PortableRemoteObject.narrow(in.read_Object(), type);
  +        } else if (org.omg.CORBA.Object.class.isAssignableFrom(type)) {
  +            return in.read_Object();
  +        } else {
  +            return in.read_value(type);
  +        }
  +    }
  +
  +    public static void throwException(Method method, InputStream in) throws 
Throwable {
  +        // read the exception id
  +        final String id = in.read_string();
  +
  +        // get the class name from the id
  +        if (!id.startsWith("IDL:")) {
  +            log.warn("Malformed exception id: " + id);
  +            return;
  +        }
  +
  +        Class[] exceptionTypes = method.getExceptionTypes();
  +        for (int i = 0; i < exceptionTypes.length; i++) {
  +            Class exceptionType = exceptionTypes[i];
  +
  +            String exceptionId = getExceptionId(exceptionType);
  +            if (id.equals(exceptionId)) {
  +                throw (Throwable) in.read_value(exceptionType);
  +            }
  +        }
  +        throw new UnexpectedException(id);
  +    }
  +
  +    public static OutputStream writeException(Method method, ResponseHandler 
reply, Exception exception) throws Throwable {
  +        Class[] exceptionTypes = method.getExceptionTypes();
  +        for (int i = 0; i < exceptionTypes.length; i++) {
  +            Class exceptionType = exceptionTypes[i];
  +            if (RemoteException.class.isAssignableFrom(exceptionType) ||
  +                    RuntimeException.class.isAssignableFrom(exceptionType) ||
  +                    !exceptionType.isInstance(exception)) {
  +                continue;
  +            }
  +
  +            String exceptionId = getExceptionId(exceptionType);
  +
  +            OutputStream out = (OutputStream) reply.createExceptionReply();
  +            out.write_string(exceptionId);
  +            out.write_value(exception);
  +            return out;
  +        }
  +        throw exception;
  +    }
  +
  +    private static String getExceptionId(Class exceptionType) {
  +        String exceptionName = exceptionType.getName().replace('.', '/');
  +        if (exceptionName.endsWith("Exception")) {
  +            exceptionName = exceptionName.substring(0, 
exceptionName.length() - "Exception".length());
  +        }
  +        exceptionName += "Ex";
  +        String exceptionId = "IDL:" + exceptionName + ":1.0";
  +        return exceptionId;
  +    }
   }
  
  
  
  1.10      +26 -2     
openejb/modules/core/src/java/org/openejb/corba/util/UtilDelegateImpl.java
  
  Index: UtilDelegateImpl.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/util/UtilDelegateImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- UtilDelegateImpl.java     29 Mar 2005 01:19:07 -0000      1.9
  +++ UtilDelegateImpl.java     24 Jun 2005 07:54:14 -0000      1.10
  @@ -75,10 +75,12 @@
   import org.openejb.corba.AdapterWrapper;
   import org.openejb.corba.CORBAException;
   import org.openejb.corba.RefGenerator;
  +import org.openejb.corba.StandardServant;
   import org.openejb.proxy.BaseEJB;
   import org.openejb.proxy.EJBHomeImpl;
   import org.openejb.proxy.EJBObjectImpl;
   import org.openejb.proxy.ProxyInfo;
  +import org.openejb.EJBInterfaceType;
   
   
   /**
  @@ -138,6 +140,28 @@
               }
               if (obj instanceof BaseEJB) {
                   obj = convertEJBToCORBAObject((BaseEJB) obj);
  +            }
  +            if (obj instanceof StandardServant) {
  +                StandardServant servant = (StandardServant) obj;
  +                EJBInterfaceType servantType = servant.getEjbInterfaceType();
  +                ProxyInfo proxyInfo = 
servant.getEjbContainer().getProxyInfo();
  +                try {
  +                    RefGenerator refGenerator = 
AdapterWrapper.getRefGenerator(proxyInfo.getContainerID());
  +                    if (refGenerator == null) {
  +                        throw new MARSHAL("Could not find RefGenerator for 
container ID: " + proxyInfo.getContainerID());
  +                    }
  +                    if (EJBInterfaceType.HOME == servantType) {
  +                        obj = refGenerator.genHomeReference(proxyInfo);
  +                    } else if (EJBInterfaceType.REMOTE == servantType) {
  +                        obj = refGenerator.genObjectReference(proxyInfo);
  +                    } else {
  +                        log.error("Encountered unknown local invocation 
handler of type " + servantType + ":" + proxyInfo);
  +                        throw new MARSHAL("Internal server error while 
marshaling the reply", 0, CompletionStatus.COMPLETED_YES);
  +                    }
  +                } catch (CORBAException e) {
  +                    log.error("Encountered unknown local invocation handler 
of type " + servantType + ":" + proxyInfo);
  +                    throw new MARSHAL("Internal server error while 
marshaling the reply", 0, CompletionStatus.COMPLETED_YES);
  +                }
               }
               delegate.writeRemoteObject(out, obj);
           } catch (Throwable e) {
  
  
  

Reply via email to