User: fleury  
  Date: 00/08/08 14:21:11

  Modified:    src/main/org/jboss/ejb/plugins/jrmp/interfaces
                        HomeProxy.java
  Log:
  Implementation of the Home Proxy stuff, it has the local stuff now
  
  Revision  Changes    Path
  1.9       +111 -14   
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/HomeProxy.java
  
  Index: HomeProxy.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/HomeProxy.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- HomeProxy.java    2000/08/06 21:36:01     1.8
  +++ HomeProxy.java    2000/08/08 21:21:10     1.9
  @@ -10,6 +10,11 @@
   import java.lang.reflect.Method;
   import java.rmi.MarshalledObject;
   
  +import javax.ejb.EJBHome;
  +import javax.ejb.EJBObject;
  +import javax.ejb.Handle;
  +import javax.ejb.HomeHandle;
  +
   import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
   
   /**
  @@ -17,7 +22,8 @@
    *      
    *      @see <related>
    *      @author Rickard �berg ([EMAIL PROTECTED])
  - *      @version $Revision: 1.8 $
  + *           @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  + *      @version $Revision: 1.9 $
    */
   public class HomeProxy
      extends GenericProxy
  @@ -27,19 +33,35 @@
      // Attributes ----------------------------------------------------
      
      // Static --------------------------------------------------------
  +   static Method getEJBMetaData;
  +   static Method getHomeHandle;
  +   static Method removeByHandle;
  +   static Method removeByPrimaryKey;
      static Method toStr;
  +   static Method eq;
  +   static Method hash;
      
      static
      {
         try
         {
  -         toStr = Object.class.getMethod("toString", new Class[0]);
  +         // EJB methods
  +              getEJBMetaData = EJBHome.class.getMethod("getEJBMetaData", new 
Class[0]);
  +         getHomeHandle = EJBHome.class.getMethod("getHomeHandle", new Class[0]);
  +         removeByHandle = EJBHome.class.getMethod("remove", new Class[] 
{Handle.class});
  +              removeByPrimaryKey = EJBHome.class.getMethod("remove", new Class[] 
{Object.class});
  +              
  +              // Object methods
  +          toStr = Object.class.getMethod("toString", new Class[0]);
  +         eq = Object.class.getMethod("equals", new Class[] { Object.class });
  +          hash = Object.class.getMethod("hashCode", new Class[0]);
         } catch (Exception e)
         {
            e.printStackTrace();
         }
      }
   
  +
      // Constructors --------------------------------------------------
      public HomeProxy(String name, ContainerRemote container, boolean optimize)
      {
  @@ -52,32 +74,107 @@
      public Object invoke(Object proxy, Method m, Object[] args)
         throws Throwable
      {
  -      // Normalize args to always be an array
  +        
  +        
  +       // Normalize args to always be an array
         // Isn't this a bug in the proxy call??
         if (args == null)
            args = new Object[0];
  -                     
  +      
  +      // Implement local methods
         if (m.equals(toStr))
  +      {
  +         return name+"Home";
  +      }
  +      else if (m.equals(eq))
  +      {
  +               // equality of the proxy home is based on names...
  +         return new Boolean(invoke(proxy,toStr, args).equals(name+"Home"));
  +      }
  +      
  +       else if (m.equals(hash))
  +      {
  +             return new Integer(this.hashCode());
  +      }
  +      
  +       // Implement local EJB calls
  +        else if (m.equals(getHomeHandle))
  +      {
  +         return new HomeHandleImpl(name);
  +      }
  +     
  +      /* MF FIXME
  +        We could implement the EJBMetaData on the client
  +      
  +       else if (m.equals(getEJBMetaData))
  +      {
  +         return id;
  +      }
  +       */
  +       
  +       else if (m.equals(removeByHandle))
  +      {
  +               // First get the EJBObject
  +               EJBObject object = ((Handle) args[0]).getEJBObject();
  +               
  +               // remove the object from here
  +               object.remove();
  +             
  +               // Return Void
  +               return Void.TYPE;
  +       }
  +       
  +       // MF FIXME I suspect we can have a much more efficient call on the server
  +       else if (m.equals(removeByPrimaryKey))
         {
  -         return name+" home";
  +               throw new Exception("NYI");
  +               /*
  +               try {
  +               
  +               // Get the metadata
  +               EJBMetaData metaData = invoke(proxy, getEJBMetaData, new Object[0]);
  +               
  +               // Retrieve the find by primary key method
  +               Method findByPrimaryKey = 
(metaData.getHomeInterfaceClass().getMethod(findByPrimaryKey, new Class[] 
{Object.class});
  +               
  +               // Find the Object we are talking about
  +               EJBObject object = invoke(proxy, findByPrimaryKey, args);
  +               
  +               // Remove it from here
  +               return object.remove();
  +               */
         }
  -      else
  +      
  +       // If not taken care of, go on and call the container
  +       else
         {
  -           
              // Delegate to container
              // Optimize if calling another bean in same EJB-application
              if (optimize && isLocal())
              {
  -              return container.invokeHome(m, args, 
  -                                                                                    
 tm != null ? tm.getTransaction() : null,
  -                                                                                    
 getPrincipal(), getCredential());
  +              return container.invokeHome( // The method and arguments for the 
invocation
  +                                                                           m, args,
  +                                                                           // 
Transaction attributes
  +                                                                           tm != 
null ? tm.getTransaction() : null,
  +                                                                           // 
Security attributes
  +                                                                           
getPrincipal(), getCredential());
              } else
              {
  +                      // Create a new MethodInvocation for distribution
                 RemoteMethodInvocation rmi = new RemoteMethodInvocation(null, m, 
args);
  -              if (tm != null)
  -                 rmi.setTransaction(tm.getTransaction());
  -           rmi.setPrincipal(getPrincipal());
  -           rmi.setCredential(getCredential());
  +              
  +                      // Set the transaction context
  +                      rmi.setTransaction(tm != null? tm.getTransaction() : null);
  +              
  +                      // Set the security stuff
  +                      // MF fixme this will need to use "thread local" and 
therefore same construct as above
  +                      // rmi.setPrincipal(sm != null? sm.getPrincipal() : null);
  +              // rmi.setCredential(sm != null? sm.getCredential() : null);
  +              // is the credential thread local? (don't think so... but...)
  +                      rmi.setPrincipal( getPrincipal() );
  +              rmi.setCredential( getCredential() );
  +                      
  +                      // Invoke on the remote server, enforce marshalling
                 return container.invokeHome(new MarshalledObject(rmi));
              }
         }
  
  
  

Reply via email to