User: reverbel
  Date: 01/11/21 04:24:22

  Modified:    iiop/src/main/org/jboss/ejb/plugins/iiop/server
                        IIOPContainerInvoker.java
  Log:
  Added special treatment for EJBObject methods getHandle() and getPrimaryKey().
  Added special treatment for  EJBHome method getHomeHandle().
  Bug fix: the creation of CORBA object reference for entity beans now deals
  with the CacheKey issue.
  Inserted alternative (and currently commented out) implementations for the
  methods toByteArray() and toObject().
  
  Revision  Changes    Path
  1.9       +109 -43   
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/IIOPContainerInvoker.java
  
  Index: IIOPContainerInvoker.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/IIOPContainerInvoker.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- IIOPContainerInvoker.java 2001/10/31 21:33:09     1.8
  +++ IIOPContainerInvoker.java 2001/11/21 12:24:22     1.9
  @@ -65,6 +65,7 @@
   import org.omg.CosNaming.NamingContextPackage.NotFound;
   import org.omg.CosNaming.NameComponent;
   
  +import org.jboss.ejb.CacheKey;
   import org.jboss.ejb.Container;
   import org.jboss.ejb.ContainerInvokerContainer;
   import org.jboss.ejb.ContainerInvoker;
  @@ -72,14 +73,15 @@
   import org.jboss.ejb.MethodInvocation;
   import org.jboss.ejb.plugins.iiop.client.StubStrategy;
   import org.jboss.ejb.plugins.iiop.EJBMetaDataImpl;
  +import org.jboss.ejb.plugins.iiop.HandleImpl;
  +import org.jboss.ejb.plugins.iiop.HomeHandleImpl;
   import org.jboss.ejb.plugins.iiop.RmiIdlUtil;
  -import org.jboss.metadata.EntityMetaData;
  -import org.jboss.metadata.MetaData;
  -import org.jboss.metadata.SessionMetaData;
  -import org.w3c.dom.Element;
   import org.jboss.iiop.rmi.AttributeAnalysis;
   import org.jboss.iiop.rmi.OperationAnalysis;
   import org.jboss.iiop.rmi.InterfaceAnalysis;
  +import org.jboss.metadata.EntityMetaData;
  +import org.jboss.metadata.MetaData;
  +import org.jboss.metadata.SessionMetaData;
   import org.jboss.web.WebClassLoader;
   
   /**
  @@ -112,7 +114,7 @@
    * CORBA reference for the corresponding <code>EJBObject</code>.
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Francisco Reverbel</a>
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    */
   public class IIOPContainerInvoker
         extends Servant
  @@ -504,8 +506,7 @@
                        initialContext.lookup("java:/JBossCorbaNaming"));
   
            // Unregister bean home from local CORBA naming context
  -         NameComponent[] name = new NameComponent[1];
  -         name[0] = new NameComponent(jndiName, "");
  +         NameComponent[] name = corbaContext.to_name(jndiName);
            corbaContext.unbind(name);
   
            // Deactivate the EJBHome 
  @@ -570,9 +571,15 @@
      public EJBObject getEntityEJBObject(Object id)
            throws RemoteException 
      {
  +      //System.err.println(">>> getEntityEJBObject(), id class is " +
  +      //                   id.getClass().getName());
  +      //if (id instanceof CacheKey)
  +      //   System.err.println(">>>                       CacheKey contains a " 
  +      //                    + ((CacheKey)id).getId().getClass().getName());    
         try {
  +         id = (id instanceof CacheKey) ? id : new CacheKey(id);
            return (EJBObject)PortableRemoteObject.narrow(
  -               poa.create_reference_with_id(toByteArray(id), 
  +               poa.create_reference_with_id(toByteArray(id),
                                               beanRepositoryIds[0]),
                  EJBObject.class);
         }
  @@ -585,21 +592,14 @@
      public Collection getEntityCollection(Collection ids)
            throws RemoteException 
      {
  -      try {
  -         ArrayList list = new ArrayList(ids.size());
  -         Iterator idEnum = ids.iterator();
  -         while(idEnum.hasNext()) {
  -            list.add((EJBObject)PortableRemoteObject.narrow(
  -                  poa.create_reference_with_id(toByteArray(idEnum.next()), 
  -                                               beanRepositoryIds[0]),
  -                  EJBObject.class));
  -         }
  -         return list;
  -      }
  -      catch (WrongPolicy wrongPolicy) {
  -         throw new ServerException("Wrong POA policy in IIOPContainerInvoker",
  -                                   wrongPolicy);
  +      //System.err.println(">>> entering getEntityCollection()");
  +      ArrayList list = new ArrayList(ids.size());
  +      Iterator idEnum = ids.iterator();
  +      while(idEnum.hasNext()) {
  +         list.add(getEntityEJBObject(idEnum.next()));
         }
  +      //System.err.println(">>> leaving getEntityCollection()");
  +      return list;
      }
   
      // Implementation of the interface InvokeHandler ---------------------------
  @@ -625,7 +625,7 @@
   
         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(container.getClassLoader());
  -
  +      
         try {
            SkeletonStrategy op = 
               (SkeletonStrategy) beanMethodInvokerMap.get(opName);
  @@ -636,24 +636,41 @@
            Object id;
            try {
               id = toObject(poaCurrent.get_object_id());
  +            //System.out.println("                      id class is " 
  +            //                   + id.getClass().getName());
            }
            catch (Exception e) {
               e.printStackTrace(System.err);
               throw new UnknownException(e);
            }
   
  -         Object[] params = 
  -            op.readParams((org.omg.CORBA_2_3.portable.InputStream)in);
  -         MethodInvocation mi =  new MethodInvocation(id, 
  -                                                     op.getMethod(), 
  -                                                     params,
  -                                                     null, /* tx */
  -                                                     null, /* identity */
  -                                                     null  /* credential */);
  -
            org.omg.CORBA_2_3.portable.OutputStream out;
            try {
  -            Object retVal = container.invoke(mi);
  +            Object retVal;
  +            
  +            // The EJBObject methods getHandle() and getPrimaryKey() receive
  +            // special treatment because the container does not implement 
  +            // them. The remaining EJBObject methods (getEJBHome(), remove(),
  +            // and isIdentical()) are forwarded to the container.
  +
  +            if (opName.equals("_get_primaryKey")) {
  +               retVal = (id instanceof CacheKey) ? ((CacheKey)id).getId() : id;
  +            }
  +            else if (opName.equals("_get_handle")) {
  +               retVal = new HandleImpl(_this_object());
  +            }
  +            else {
  +               Object[] params = 
  +                  op.readParams((org.omg.CORBA_2_3.portable.InputStream)in);
  +               MethodInvocation mi =  
  +                  new MethodInvocation(id, 
  +                                       op.getMethod(), 
  +                                       params,
  +                                       null, /* tx */
  +                                       null, /* identity */
  +                                       null  /* credential */);
  +               retVal = container.invoke(mi);
  +            }
               out = (org.omg.CORBA_2_3.portable.OutputStream) 
                     handler.createReply();
               if (op.isNonVoid()) {
  @@ -815,7 +832,26 @@
            throw new ServerException("Object id serialization error", ioe);
         }
      }
  +   /*----------------------------------------------------------------------
  +   protected static byte[] toByteArray(Object obj) 
  +         throws RemoteException 
  +   {
  +      try {
  +         ByteArrayOutputStream os = new ByteArrayOutputStream();
  +         ObjectOutputStream oos = new ObjectOutputStream(os);
   
  +         oos.writeObject(new java.rmi.MarshalledObject(obj));
  +         oos.flush();
  +         byte[] a = os.toByteArray();
  +         os.close();
  +         return a;
  +      }
  +      catch (IOException ioe) {
  +         throw new ServerException("Object id serialization error", ioe);
  +      }
  +   }
  +   ------------------------------------------------------------------------*/
  +
      /**
       * Receives a byte array previously returned by a call to 
       * <code>toByteArray</code> and retrieves an object from it. Used to
  @@ -833,6 +869,20 @@
         is.close();
         return obj;
      }
  +   /*----------------------------------------------------------------------
  +   protected static Object toObject(byte[] a) 
  +         throws IOException, ClassNotFoundException 
  +   {
  +      ByteArrayInputStream is = new ByteArrayInputStream(a);
  +      ObjectInputStream ois = new ObjectInputStream(is);
  +
  +
  +      java.rmi.MarshalledObject mo = 
  +         (java.rmi.MarshalledObject)ois.readObject();
  +      is.close();
  +      return mo.get();
  +   }
  +   ------------------------------------------------------------------------*/
   
      // Inner class for the EJBHome servant--------------------------------------
   
  @@ -864,25 +914,40 @@
            ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(
                  container.getClassLoader());
  +
            try {
  +
               SkeletonStrategy op = 
                  (SkeletonStrategy) homeMethodInvokerMap.get(opName);
               if (op == null) {
                  throw new BAD_OPERATION(opName);
               }
   
  -            Object[] params = 
  -               op.readParams((org.omg.CORBA_2_3.portable.InputStream)in);
  -            MethodInvocation mi =  new MethodInvocation(null, 
  -                                                        op.getMethod(), 
  -                                                        params,
  -                                                        null, /* tx */
  -                                                        null, /* identity */
  -                                                        null  /* credential*/);
  -
               org.omg.CORBA_2_3.portable.OutputStream out;
               try {
  -               Object retVal = container.invokeHome(mi);
  +               Object retVal;
  +               
  +               // The EJBHome method getHomeHandle() receives special 
  +               // treatment because the container does not implement it. 
  +               // The remaining EJBObject methods (getEJBMetaData, 
  +               // remove(java.lang.Object), and remove(javax.ejb.Handle))
  +               // are forwarded to the container.
  +
  +               if (opName.equals("_get_homeHandle")) {
  +                  retVal = new HomeHandleImpl(_this_object());
  +               }
  +               else {
  +                  Object[] params = op.readParams(
  +                                  (org.omg.CORBA_2_3.portable.InputStream)in);
  +                  MethodInvocation mi = new MethodInvocation(
  +                                                       null, 
  +                                                       op.getMethod(), 
  +                                                       params,
  +                                                       null, /* tx */
  +                                                       null, /* identity */
  +                                                       null  /* credential*/);
  +                  retVal = container.invokeHome(mi);
  +               }
                  out = (org.omg.CORBA_2_3.portable.OutputStream) 
                     handler.createReply();
                  if (op.isNonVoid()) {
  @@ -890,6 +955,7 @@
                  }
               }
               catch (Exception e) {
  +               e.printStackTrace(System.err);
                  out = (org.omg.CORBA_2_3.portable.OutputStream) 
                     handler.createExceptionReply();
                  op.writeException(out, e);
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to