User: fleury  
  Date: 00/08/08 14:19:41

  Modified:    src/main/org/jboss/ejb/plugins/jrmp/interfaces
                        EntityProxy.java
  Log:
  Mapping all the EJBobject methods and local handling of them
  
  Revision  Changes    Path
  1.12      +48 -24    
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/EntityProxy.java
  
  Index: EntityProxy.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/EntityProxy.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- EntityProxy.java  2000/08/06 21:36:01     1.11
  +++ EntityProxy.java  2000/08/08 21:19:40     1.12
  @@ -19,7 +19,8 @@
    *      
    *      @see <related>
    *      @author Rickard �berg ([EMAIL PROTECTED])
  - *      @version $Revision: 1.11 $
  + *           @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  + *      @version $Revision: 1.12 $
    */
   public class EntityProxy
      extends GenericProxy
  @@ -30,6 +31,7 @@
      protected Object id;
      
      // Static --------------------------------------------------------
  + 
      static Method getPrimaryKey;
      static Method getHandle;
      static Method isIdentical;
  @@ -41,12 +43,15 @@
      {
         try
         {
  +              // EJB 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 });
  -         toStr = Object.class.getMethod("toString", new Class[0]);
  +         
  +              // 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]);
  +          hash = Object.class.getMethod("hashCode", new Class[0]);
         } catch (Exception e)
         {
            e.printStackTrace();
  @@ -61,7 +66,7 @@
                if (id == null)
                        throw new NullPointerException("Id may not be null");
                        
  -      this.id = id;
  +             this.id = id;
      }
      
      // Public --------------------------------------------------------
  @@ -76,46 +81,65 @@
            args = new Object[0];
         
         // Implement local methods
  -      if (m.equals(getPrimaryKey))
  +      if (m.equals(toStr))
         {
  -         return id;
  +         return name+":"+id.toString();
         }
  -      else if (m.equals(getHandle))
  +      else if (m.equals(eq))
         {
  -         return new EntityHandleImpl(name, id);
  +         return invoke(proxy, isIdentical, args);
         }
  -      else if (m.equals(toStr))
  +      
  +       else if (m.equals(hash))
         {
  -         return name+":"+id.toString();
  +             return new Integer(id.hashCode());
         }
  -      else if (m.equals(eq))
  +      
  +       // Implement local EJB calls
  +        else if (m.equals(getHandle))
         {
  -         return invoke(proxy, isIdentical, args);
  +         return new EntityHandleImpl(name, id);
         }
  -      else if (m.equals(isIdentical))
  +     
  +       else if (m.equals(getPrimaryKey))
         {
  -                     return new 
Boolean(((EJBObject)args[0]).getPrimaryKey().equals(id));
  +         return id;
         }
  -      else if (m.equals(hash))
  +       else if (m.equals(isIdentical))
         {
  -             return new Integer(id.hashCode());
  +                     return new 
Boolean(((EJBObject)args[0]).getPrimaryKey().equals(id));
         }
  -      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.invoke(id, m, args, 
  -                                                                                    
         tm != null ? tm.getTransaction() : null,
  -                                                                                    
         getPrincipal(), getCredential());
  +              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);
  -              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.invoke(new MarshalledObject(rmi));
              }
         }
  
  
  

Reply via email to