User: fleury  
  Date: 00/08/08 14:27:27

  Modified:    src/main/org/jboss/ejb/plugins/jrmp/interfaces
                        StatefulSessionProxy.java
  Log:
  Local calls implemented EJBcalls implemented Handle stuff implemented
  
  Revision  Changes    Path
  1.11      +114 -24   
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/StatefulSessionProxy.java
  
  Index: StatefulSessionProxy.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/StatefulSessionProxy.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- StatefulSessionProxy.java 2000/08/06 21:36:01     1.10
  +++ StatefulSessionProxy.java 2000/08/08 21:27:27     1.11
  @@ -10,6 +10,7 @@
   import java.lang.reflect.Method;
   import java.rmi.MarshalledObject;
   
  +import javax.ejb.EJBObject;
   import javax.naming.Name;
   
   import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
  @@ -19,7 +20,8 @@
    *      
    *      @see <related>
    *      @author Rickard �berg ([EMAIL PROTECTED])
  - *      @version $Revision: 1.10 $
  + *           @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  + *      @version $Revision: 1.11 $
    */
   public class StatefulSessionProxy
      extends GenericProxy
  @@ -27,16 +29,43 @@
      // Constants -----------------------------------------------------
       
      // Attributes ----------------------------------------------------
  +   // Stateful beans come with a jboss generated identifier
      protected Object id;
      
      // Static --------------------------------------------------------
   
  +   static Method getPrimaryKey;
  +   static Method getHandle;
  +   static Method isIdentical;
  +   static Method toStr;
  +   static Method eq;
  +   static Method hash;
  +   
  +   static
  +   {
  +      try
  +      {
  +              // EJBObject methods
  +         getPrimaryKey = EJBObject.class.getMethod("getPrimaryKey", new Class[0]);
  +         getHandle = EJBObject.class.getMethod("getHandle", new Class[0]);
  +         isIdentical = EJBObject.class.getMethod("isIdentical", new Class[] { 
EJBObject.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 StatefulSessionProxy(String name, ContainerRemote container, Object id, 
boolean optimize)
      {
                super(name, container, optimize);
  -             
  -      this.id = id;
  +     
  +             this.id = id;
      }
      
      // Public --------------------------------------------------------
  @@ -45,28 +74,89 @@
      public final Object invoke(Object proxy, Method m, Object[] args)
         throws Throwable
      {
  -        // Normalize args to always be an array
  -        // Isn't this a bug in the proxy call??
  -        if (args == null)
  -           args = new Object[0];
  -        
  -        // Delegate to container
  -        // Optimize if calling another bean in same EJB-application
  -        if (optimize && isLocal())
  -        {
  -           return container.invoke(id, m, args, 
  -                                                                     tm != null ? 
tm.getTransaction() : null,
  -                                                                     
getPrincipal(), getCredential());
  -        } else
  -        {
  -           RemoteMethodInvocation rmi = new RemoteMethodInvocation(id, m, args);
  -           if (tm != null)
  -              rmi.setTransaction(tm.getTransaction());
  -        rmi.setPrincipal(getPrincipal());
  -        rmi.setCredential(getCredential());
  +       // 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+":"+id.toString();
  +      }
  +      else if (m.equals(eq))
  +      {
  +         return invoke(proxy, isIdentical, args);
  +      }
  +      
  +       else if (m.equals(hash))
  +      {
  +             return new Integer(id.hashCode());
  +      }
  +      
  +       // Implement local EJB calls
  +        else if (m.equals(getHandle))
  +      {
  +         return new StatefulHandleImpl(name, id);
  +      }
  +     
  +       else if (m.equals(getPrimaryKey))
  +      {
  +               // MF FIXME 
  +               // The spec says that SSB PrimaryKeys should not be returned and the 
call should throw an exception
  +               // However we need to expose the field *somehow* so we can check for 
"isIdentical"
  +               // For now we use a non-spec compliant implementation and just 
return the key as is
  +               // See jboss1.0 for the PKHolder and the hack to be spec-compliant 
and yet solve the problem
  +               
  +               // This should be the following call 
  +               //throw new RemoteException("Session Beans do not expose their keys, 
RTFS");
  +      
  +               // This is how it was solved in jboss1.0
  +               // throw new PKHolder("RTFS", id);
  +               
  +               // This is non-spec compliant but will do for now
  +               return id;
  +       }
  +       else if (m.equals(isIdentical))
  +      {
  +                 // MF FIXME
  +                     // See above, this is not correct but works for now (do 
jboss1.0 PKHolder hack in here)
  +                     return new 
Boolean(((EJBObject)args[0]).getPrimaryKey().equals(id));
  +      }
  +      
  +       // 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.invoke( // The entity id, method and arguments for 
the invocation
  +                                                                       id, m, args,
  +                                                                       // 
Transaction attributes
  +                                                                       tm != null ? 
tm.getTransaction() : null,
  +                                                                       // Security 
attributes
  +                                                                       
getPrincipal(), getCredential());
  +           } else
  +           {
  +                      // Create a new MethodInvocation for distribution
  +              RemoteMethodInvocation rmi = new RemoteMethodInvocation(id, m, args);
  +              
  +                      // 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() );
                         
  -           return container.invoke(new MarshalledObject(rmi));
  -        }
  +                      // Invoke on the remote server, enforce marshalling
  +              return container.invoke(new MarshalledObject(rmi));
  +           }
  +      }
      }
   
      // Package protected ---------------------------------------------
  
  
  

Reply via email to