dain        2005/06/25 03:00:29

  Modified:    modules/core/src/java/org/openejb/corba CORBAHandle.java
                        CORBAHomeHandle.java StandardServant.java
  Added:       modules/core/src/java/org/openejb/corba
                        CORBAEJBMetaData.java CorbaApplicationServer.java
  Log:

  EJB handles can now be passed over iiop
  Fixed a few more marshalling bugs
  
  Revision  Changes    Path
  1.2       +28 -25    
openejb/modules/core/src/java/org/openejb/corba/CORBAHandle.java
  
  Index: CORBAHandle.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/CORBAHandle.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CORBAHandle.java  8 Mar 2005 04:08:26 -0000       1.1
  +++ CORBAHandle.java  25 Jun 2005 07:00:29 -0000      1.2
  @@ -52,10 +52,11 @@
   import javax.ejb.EJBObject;
   import javax.ejb.Handle;
   import javax.ejb.spi.HandleDelegate;
  -import javax.naming.NamingException;
  +import javax.naming.Context;
  +import javax.naming.InitialContext;
   import javax.rmi.PortableRemoteObject;
   
  -import org.openejb.corba.util.Util;
  +import org.omg.CORBA.ORB;
   
   
   /**
  @@ -71,7 +72,6 @@
    * @version $Revision$ $Date$
    */
   public class CORBAHandle implements Handle, Serializable {
  -
       private String ior;
   
       public CORBAHandle(String ior) {
  @@ -79,43 +79,46 @@
       }
   
       public EJBObject getEJBObject() throws RemoteException {
  -
           try {
  -            return (EJBObject) 
PortableRemoteObject.narrow(Util.getORB().string_to_object(ior), 
EJBObject.class);
  +            return (EJBObject) 
PortableRemoteObject.narrow(getOrb().string_to_object(ior), EJBObject.class);
           } catch (Exception e) {
               throw new RemoteException("Unable to convert IOR into object", 
e);
           }
       }
   
       private void writeObject(ObjectOutputStream out) throws IOException {
  -
  -        HandleDelegate handleDelegate;
  -
  -        try {
  -            handleDelegate = Util.getHandleDelegate();
  -        } catch (NamingException e) {
  -            throw new IOException("Unable to lookup 
java:comp/HandleDelegate");
  -        }
  -
  +        HandleDelegate handleDelegate = getHandleDelegate();
           handleDelegate.writeEJBObject(getEJBObject(), out);
       }
   
       private void readObject(ObjectInputStream in) throws IOException, 
ClassNotFoundException {
  -
  -        HandleDelegate handleDelegate;
  +        HandleDelegate handleDelegate = getHandleDelegate();
  +        EJBObject obj = handleDelegate.readEJBObject(in);
   
           try {
  -            handleDelegate = Util.getHandleDelegate();
  -        } catch (NamingException e) {
  -            throw new IOException("Unable to lookup 
java:comp/HandleDelegate");
  +            ior = getOrb().object_to_string((org.omg.CORBA.Object) obj);
  +        } catch (Exception e) {
  +            throw new RemoteException("Unable to convert object to IOR", e);
           }
  +    }
   
  -        EJBObject obj = handleDelegate.readEJBObject(in);
  +    private static ORB getOrb() {
  +        try {
  +            Context context = new InitialContext();
  +            ORB orb = (ORB) context.lookup("java:comp/ORB");
  +            return orb;
  +        } catch (Throwable e) {
  +            throw new org.omg.CORBA.MARSHAL("Cound not find ORB in jndi at 
java:comp/ORB", 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
  +        }
  +    }
   
  +    private static HandleDelegate getHandleDelegate() {
           try {
  -            ior = Util.getORB().object_to_string((org.omg.CORBA.Object) obj);
  -        } catch (Exception e) {
  -            throw new RemoteException("Unable to convert object to IOR", e);
  +            Context context = new InitialContext();
  +            HandleDelegate handleDelegate = (HandleDelegate) 
context.lookup("java:comp/HandleDelegate");
  +            return handleDelegate;
  +        } catch (Throwable e) {
  +            throw new org.omg.CORBA.MARSHAL("Cound not find handle delegate 
in jndi at java:comp/HandleDelegate", 0, 
org.omg.CORBA.CompletionStatus.COMPLETED_YES);
           }
       }
   }
  
  
  
  1.2       +28 -24    
openejb/modules/core/src/java/org/openejb/corba/CORBAHomeHandle.java
  
  Index: CORBAHomeHandle.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/CORBAHomeHandle.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CORBAHomeHandle.java      8 Mar 2005 04:08:26 -0000       1.1
  +++ CORBAHomeHandle.java      25 Jun 2005 07:00:29 -0000      1.2
  @@ -51,10 +51,11 @@
   import javax.ejb.EJBHome;
   import javax.ejb.HomeHandle;
   import javax.ejb.spi.HandleDelegate;
  -import javax.naming.NamingException;
  +import javax.naming.Context;
  +import javax.naming.InitialContext;
   import javax.rmi.PortableRemoteObject;
   
  -import org.openejb.corba.util.Util;
  +import org.omg.CORBA.ORB;
   
   
   /**
  @@ -70,7 +71,6 @@
    * @version $Revision$ $Date$
    */
   public class CORBAHomeHandle implements HomeHandle, Serializable {
  -
       private String ior;
   
       public CORBAHomeHandle(String ior) {
  @@ -80,7 +80,7 @@
       public EJBHome getEJBHome() throws RemoteException {
   
           try {
  -            return (EJBHome) 
PortableRemoteObject.narrow(Util.getORB().string_to_object(ior), EJBHome.class);
  +            return (EJBHome) 
PortableRemoteObject.narrow(getOrb().string_to_object(ior), EJBHome.class);
           } catch (Exception e) {
               throw new RemoteException("Unable to convert IOR into home", e);
           }
  @@ -88,34 +88,38 @@
       }
   
       private void writeObject(ObjectOutputStream out) throws IOException {
  -
  -        HandleDelegate handleDelegate;
  -
  -        try {
  -            handleDelegate = Util.getHandleDelegate();
  -        } catch (NamingException e) {
  -            throw new IOException("Unable to lookup 
java:comp/HandleDelegate");
  -        }
  -
  +        HandleDelegate handleDelegate = getHandleDelegate();
           handleDelegate.writeEJBHome(getEJBHome(), out);
       }
   
       private void readObject(java.io.ObjectInputStream in) throws 
IOException, ClassNotFoundException {
  -
  -        HandleDelegate handleDelegate;
  +        HandleDelegate handleDelegate = getHandleDelegate();
  +        EJBHome home = handleDelegate.readEJBHome(in);
   
           try {
  -            handleDelegate = Util.getHandleDelegate();
  -        } catch (NamingException e) {
  -            throw new IOException("Cannot get HandleDelegate");
  +            ior = getOrb().object_to_string((org.omg.CORBA.Object) home);
  +        } catch (Exception e) {
  +            throw new RemoteException("Unable to convert object to IOR", e);
           }
  +    }
   
  -        EJBHome home = handleDelegate.readEJBHome(in);
  +    private static ORB getOrb() {
  +        try {
  +            Context context = new InitialContext();
  +            ORB orb = (ORB) context.lookup("java:comp/ORB");
  +            return orb;
  +        } catch (Throwable e) {
  +            throw new org.omg.CORBA.MARSHAL("Cound not find ORB in jndi at 
java:comp/ORB", 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
  +        }
  +    }
   
  +    private static HandleDelegate getHandleDelegate() {
           try {
  -            ior = Util.getORB().object_to_string((org.omg.CORBA.Object) 
home);
  -        } catch (Exception e) {
  -            throw new RemoteException("Unable to convert object to IOR", e);
  +            Context context = new InitialContext();
  +            HandleDelegate handleDelegate = (HandleDelegate) 
context.lookup("java:comp/HandleDelegate");
  +            return handleDelegate;
  +        } catch (Throwable e) {
  +            throw new org.omg.CORBA.MARSHAL("Cound not find handle delegate 
in jndi at java:comp/HandleDelegate", 0, 
org.omg.CORBA.CompletionStatus.COMPLETED_YES);
           }
       }
   }
  
  
  
  1.6       +93 -31    
openejb/modules/core/src/java/org/openejb/corba/StandardServant.java
  
  Index: StandardServant.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/StandardServant.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StandardServant.java      24 Jun 2005 12:32:02 -0000      1.5
  +++ StandardServant.java      25 Jun 2005 07:00:29 -0000      1.6
  @@ -56,14 +56,20 @@
   import java.util.LinkedList;
   import java.util.List;
   import java.util.Map;
  +import javax.ejb.EJBHome;
  +import javax.ejb.EJBObject;
   import javax.ejb.Handle;
   import javax.transaction.InvalidTransactionException;
   import javax.transaction.TransactionRequiredException;
   import javax.transaction.TransactionRolledbackException;
  +import javax.naming.Context;
  +import javax.naming.NamingException;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.core.service.InvocationResult;
  +import org.apache.geronimo.naming.java.SimpleReadOnlyContext;
  +import org.apache.geronimo.naming.java.RootContext;
   import org.omg.CORBA.BAD_OPERATION;
   import org.omg.CORBA.INVALID_TRANSACTION;
   import org.omg.CORBA.MARSHAL;
  @@ -83,21 +89,33 @@
   import org.openejb.EJBInterfaceType;
   import org.openejb.EJBInvocation;
   import org.openejb.EJBInvocationImpl;
  -import org.openejb.client.EJBObjectHandler;
  -import org.openejb.client.EJBObjectProxy;
   import org.openejb.corba.compiler.IiopOperation;
   import org.openejb.corba.compiler.PortableStubCompiler;
  +import org.openejb.corba.util.Util;
   
   /**
    * @version $Revision$ $Date$
    */
   public class StandardServant extends Servant implements InvokeHandler {
       private static final Log log = LogFactory.getLog(StandardServant.class);
  +
  +    private static final Method GETEJBMETADATA = getMethod(EJBHome.class, 
"getEJBMetaData", null);
  +    private static final Method GETHOMEHANDLE = getMethod(EJBHome.class, 
"getHomeHandle", null);
  +    private static final Method REMOVE_W_KEY = getMethod(EJBHome.class, 
"remove", new Class[]{Object.class});
  +    private static final Method REMOVE_W_HAND = getMethod(EJBHome.class, 
"remove", new Class[]{Handle.class});
  +    private static final Method GETEJBHOME = getMethod(EJBObject.class, 
"getEJBHome", null);
  +    private static final Method GETHANDLE = getMethod(EJBObject.class, 
"getHandle", null);
  +    private static final Method GETPRIMARYKEY = getMethod(EJBObject.class, 
"getPrimaryKey", null);
  +    private static final Method ISIDENTICAL = getMethod(EJBObject.class, 
"isIdentical", new Class[]{EJBObject.class});
  +    private static final Method REMOVE = getMethod(EJBObject.class, 
"remove", null);
  +
  +
       private final EJBInterfaceType ejbInterfaceType;
       private final EJBContainer ejbContainer;
       private final Object primaryKey;
       private final String[] typeIds;
       private final Map operations;
  +    private final Context enc;
   
       public StandardServant(EJBInterfaceType ejbInterfaceType, EJBContainer 
ejbContainer) {
           this(ejbInterfaceType, ejbContainer, null);
  @@ -136,6 +154,16 @@
               }
           }
           typeIds = (String[]) ids.toArray(new String[ids.size()]);
  +
  +        // create ReadOnlyContext
  +        Map componentContext = new HashMap(2);
  +        componentContext.put("ORB", Util.getORB());
  +        componentContext.put("HandleDelegate", new CORBAHandleDelegate());
  +        try {
  +            enc = new SimpleReadOnlyContext(componentContext);
  +        } catch (NamingException e) {
  +            throw new RuntimeException(e);
  +        }
       }
   
       public EJBInterfaceType getEjbInterfaceType() {
  @@ -158,22 +186,26 @@
           // get the method object
           Method method = (Method) operations.get(operationName);
           int index = ejbContainer.getMethodIndex(method);
  -        if (index < 0) {
  +        if (index < 0 &&
  +                method.getDeclaringClass() != javax.ejb.EJBObject.class &&
  +                method.getDeclaringClass() != javax.ejb.EJBHome.class) {
               throw new BAD_OPERATION(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(ejbContainer.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] = 
org.openejb.corba.util.Util.readObject(parameterType, in);
  +                arguments[i] = Util.readObject(parameterType, in);
               }
   
               // invoke the method
  @@ -182,32 +214,53 @@
   
                   if (log.isDebugEnabled()) log.debug("Calling " + 
method.getName());
   
  -                // extract the primary key from home ejb remove invocations
  -                Object primaryKey = this.primaryKey;
  -                if (ejbInterfaceType == EJBInterfaceType.HOME && 
method.getName().equals("remove")) {
  -                    primaryKey = arguments[0];
  -                    if (primaryKey instanceof Handle) {
  -                        Handle handle = (Handle) primaryKey;
  -                        EJBObjectProxy ejbObject = (EJBObjectProxy) 
handle.getEJBObject();
  -                        EJBObjectHandler handler = 
ejbObject.getEJBObjectHandler();
  -                        primaryKey = handler.getRegistryId();
  +                if (method.getDeclaringClass() == javax.ejb.EJBObject.class) 
{
  +                    if (method.equals(GETHANDLE)) {
  +                        result = 
ejbContainer.getEjbObject(primaryKey).getHandle();
  +                    } else if (method.equals(GETPRIMARYKEY)) {
  +                        result = 
ejbContainer.getEjbObject(primaryKey).getPrimaryKey();
  +                    } else if (method.equals(ISIDENTICAL)) {
  +                        EJBObject ejbObject = (EJBObject) arguments[0];
  +                        result = new 
Boolean(ejbContainer.getEjbObject(primaryKey).isIdentical(ejbObject));
  +                    } else if (method.equals(GETEJBHOME)) {
  +                        result = ejbContainer.getEjbHome();
  +                    } else if (method.equals(REMOVE)) {
  +                        ejbContainer.getEjbObject(primaryKey).remove();
  +                        result = null;
  +                    } else {
  +                        throw new UnsupportedOperationException("Unkown 
method: " + method);
                       }
  +                } else if (method.getDeclaringClass() == 
javax.ejb.EJBHome.class) {
  +                   if (method.equals(GETEJBMETADATA)) {
  +                        result = ejbContainer.getEjbHome().getEJBMetaData();
  +                    } else if (method.equals(GETHOMEHANDLE)) {
  +                        result = ejbContainer.getEjbHome().getHomeHandle();
  +                    } else if (method.equals(REMOVE_W_HAND)) {
  +                        Handle handle = (Handle) arguments[0];
  +                        ejbContainer.getEjbHome().remove(handle);
  +                        result = null;
  +                    } else if (method.equals(REMOVE_W_KEY)) {
  +                        ejbContainer.getEjbHome().remove(arguments[0]);
  +                        result = null;
  +                    } else {
  +                        throw new UnsupportedOperationException("Unkown 
method: " + method);
  +                    }
  +                } else {
  +                    // create the invocation object
  +                    EJBInvocation invocation = new 
EJBInvocationImpl(ejbInterfaceType, primaryKey, index, arguments);
  +
  +                    // invoke the container
  +                    InvocationResult invocationResult = 
ejbContainer.invoke(invocation);
  +
  +                    // process the result
  +                    if (invocationResult.isException()) {
  +                        // all other exceptions are written to stream
  +                        // if this is an unknown exception type it will
  +                        // be thrown out of writeException
  +                        return Util.writeUserException(method, reply, 
invocationResult.getException());
  +                    }
  +                    result = invocationResult.getResult();
                   }
  -
  -                // create the invocation object
  -                EJBInvocation invocation = new 
EJBInvocationImpl(ejbInterfaceType, primaryKey, index, arguments);
  -
  -                // invoke the container
  -                InvocationResult invocationResult = 
ejbContainer.invoke(invocation);
  -
  -                // process the result
  -                if (invocationResult.isException()) {
  -                    // all other exceptions are written to stream
  -                    // if this is an unknown exception type it will
  -                    // be thrown out of writeException
  -                    return 
org.openejb.corba.util.Util.writeUserException(method, reply, 
invocationResult.getException());
  -                }
  -                result = invocationResult.getResult();
               } catch (TransactionRolledbackException e) {
                   log.debug("TransactionRolledbackException", e);
                   throw new TRANSACTION_ROLLEDBACK(e.toString());
  @@ -246,11 +299,20 @@
               org.omg.CORBA_2_3.portable.OutputStream out = 
(org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
   
               // write the output value
  -            org.openejb.corba.util.Util.writeObject(method.getReturnType(), 
result, out);
  +            Util.writeObject(method.getReturnType(), result, out);
   
               return out;
           } finally {
               Thread.currentThread().setContextClassLoader(oldClassLoader);
  +            RootContext.setComponentContext(oldContext);
  +        }
  +    }
  +
  +    private static Method getMethod(Class c, String method, Class[] params) {
  +        try {
  +            return c.getMethod(method, params);
  +        } catch (NoSuchMethodException e) {
  +            throw (IllegalStateException) new 
IllegalStateException().initCause(e);
           }
       }
   }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/corba/CORBAEJBMetaData.java
  
  Index: CORBAEJBMetaData.java
  ===================================================================
  /**
   * 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: CORBAEJBMetaData.java,v 1.1 2005/06/25 07:00:29 dain Exp $
   */
  package org.openejb.corba;
  
  import javax.ejb.EJBMetaData;
  import javax.ejb.EJBHome;
  import javax.rmi.PortableRemoteObject;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2005/06/25 07:00:29 $
   */
  public class CORBAEJBMetaData implements EJBMetaData, java.io.Serializable {
      public final static byte ENTITY = 1;
      public final static byte STATEFUL = 2;
      public final static byte STATELESS = 3;
  
      /**
       * The Class of the bean's home interface.
       */
      private final Class homeInterface;
  
      /**
       * The Class of the bean's remote interface.
       */
      private final Class remoteInterface;
  
      /**
       * The Class of the bean's primary key or null if the
       * bean is of a type that does not require a primary key.
       */
      private final Class primaryKeyClass;
  
      /**
       * The EJBHome stub/proxy for this bean deployment.
       */
      private final EJBHome ejbHome;
  
      /**
       * The type of bean that this MetaData implementation represents.
       *
       * @see #ENTITY
       * @see #STATEFUL
       * @see #STATELESS
       */
      private final byte ejbType;
  
      public CORBAEJBMetaData(EJBHome ejbHome, byte ejbType, Class 
homeInterface, Class remoteInterface, Class primaryKeyClass) {
          if (homeInterface == null) {
              throw new IllegalArgumentException("Home interface is null");
          }
          if (remoteInterface == null) {
              throw new IllegalArgumentException("Remote interface is null");
          }
          if (ejbType == ENTITY && primaryKeyClass == null) {
              throw new IllegalArgumentException("Entity bean must have a 
primary key class");
          }
          if (ejbType != ENTITY && primaryKeyClass != null) {
              throw new IllegalArgumentException("Session bean must have a 
primary key class");
          }
          this.ejbHome = ejbHome;
          this.ejbType = ejbType;
          this.homeInterface = homeInterface;
          this.remoteInterface = remoteInterface;
          this.primaryKeyClass = primaryKeyClass;
      }
  
      public Class getHomeInterfaceClass() {
          return homeInterface;
      }
  
      public Class getRemoteInterfaceClass() {
          return remoteInterface;
      }
  
      public Class getPrimaryKeyClass() {
          if (ejbType == ENTITY) {
              return primaryKeyClass;
          } else {
              throw new UnsupportedOperationException("Session objects are 
private resources and do not have primary keys");
          }
      }
  
      public boolean isSession() {
          return (ejbType == STATEFUL || ejbType == STATELESS);
      }
  
      public boolean isStatelessSession() {
          return ejbType == STATELESS;
      }
  
      public EJBHome getEJBHome() {
          return (EJBHome) PortableRemoteObject.narrow(ejbHome, EJBHome.class);
      }
  }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/corba/CorbaApplicationServer.java
  
  Index: CorbaApplicationServer.java
  ===================================================================
  /**
   * 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: CorbaApplicationServer.java,v 1.1 2005/06/25 07:00:29 dain Exp $
   */
  package org.openejb.corba;
  
  import javax.ejb.EJBHome;
  import javax.ejb.EJBMetaData;
  import javax.ejb.EJBObject;
  import javax.ejb.Handle;
  import javax.ejb.HomeHandle;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.rmi.PortableRemoteObject;
  
  import org.omg.CORBA.ORB;
  import org.openejb.EJBComponentType;
  import org.openejb.proxy.ProxyInfo;
  import org.openejb.spi.ApplicationServer;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2005/06/25 07:00:29 $
   */
  public class CorbaApplicationServer implements ApplicationServer {
      public EJBObject getEJBObject(ProxyInfo proxyInfo) {
          try {
              RefGenerator refGenerator = 
AdapterWrapper.getRefGenerator(proxyInfo.getContainerID());
              org.omg.CORBA.Object object = 
refGenerator.genObjectReference(proxyInfo);
              EJBObject ejbObject = (EJBObject) 
PortableRemoteObject.narrow(object, EJBObject.class);
              return ejbObject;
          } catch (Throwable e) {
              throw new org.omg.CORBA.MARSHAL(e.getClass().getName() + " thrown 
while marshaling the reply: " + e.getMessage(), 0, 
org.omg.CORBA.CompletionStatus.COMPLETED_YES);
          }
      }
  
      public EJBHome getEJBHome(ProxyInfo proxyInfo) {
          try {
              RefGenerator refGenerator = 
AdapterWrapper.getRefGenerator(proxyInfo.getContainerID());
              org.omg.CORBA.Object home = 
refGenerator.genHomeReference(proxyInfo);
              EJBHome ejbHome = (EJBHome) PortableRemoteObject.narrow(home, 
EJBHome.class);
              return ejbHome;
          } catch (Throwable e) {
              throw new org.omg.CORBA.MARSHAL(e.getClass().getName() + " thrown 
while marshaling the reply: " + e.getMessage(), 0, 
org.omg.CORBA.CompletionStatus.COMPLETED_YES);
          }
      }
  
      public javax.ejb.Handle getHandle(ProxyInfo proxyInfo) {
          org.omg.CORBA.Object ejbObject = (org.omg.CORBA.Object) 
getEJBObject(proxyInfo);
          String ior = getOrb().object_to_string(ejbObject);
          Handle handle = new CORBAHandle(ior);
          return handle;
      }
  
      public javax.ejb.HomeHandle getHomeHandle(ProxyInfo proxyInfo) {
          org.omg.CORBA.Object ejbHome = (org.omg.CORBA.Object) 
getEJBHome(proxyInfo);
          String ior = getOrb().object_to_string(ejbHome);
          HomeHandle homeHandle = new CORBAHomeHandle(ior);
          return homeHandle;
      }
  
      public EJBMetaData getEJBMetaData(ProxyInfo proxyInfo) {
          int componentType = proxyInfo.getComponentType();
          byte ejbType;
          if (componentType != EJBComponentType.STATEFUL) {
              ejbType = CORBAEJBMetaData.STATEFUL;
          } else if (componentType != EJBComponentType.STATELESS) {
              ejbType = CORBAEJBMetaData.STATELESS;
          } else if (componentType != EJBComponentType.BMP_ENTITY || 
componentType == EJBComponentType.CMP_ENTITY) {
              ejbType = CORBAEJBMetaData.ENTITY;
          } else {
              throw new IllegalArgumentException("Unknown component type: " + 
componentType);
          }
  
          CORBAEJBMetaData ejbMetaData = new 
CORBAEJBMetaData(getEJBHome(proxyInfo),
                  ejbType,
                  proxyInfo.getHomeInterface(),
                  proxyInfo.getRemoteInterface(),
                  proxyInfo.getPrimaryKeyClass());
          return ejbMetaData;
      }
  
      private static ORB getOrb() {
          try {
              Context context = new InitialContext();
              ORB orb = (ORB) context.lookup("java:comp/ORB");
              return orb;
          } catch (Throwable e) {
              throw new org.omg.CORBA.MARSHAL("Cound not find ORB in jndi at 
java:comp/ORB", 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
          }
      }
  }
  
  
  

Reply via email to