User: mnf999  
  Date: 02/03/07 10:25:52

  Modified:    src/main/org/jboss/proxy/ejb ProxyFactory.java
  Added:       src/main/org/jboss/proxy/ejb EntityInterceptor.java
                        GenericEJBInterceptor.java HomeInterceptor.java
                        ListEntityInterceptor.java
                        StatefulSessionInterceptor.java
                        StatelessSessionInterceptor.java
  Log:
  Adaptation to the new interceptor design
  The proxy factory sets the chains on the server side (David, move this to 
externalized when you can see FIXME).
  All the EJB behavior is isolated in their corresponding interceptors
  
  Revision  Changes    Path
  1.9       +161 -9    jboss/src/main/org/jboss/proxy/ejb/ProxyFactory.java
  
  Index: ProxyFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/proxy/ejb/ProxyFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ProxyFactory.java 27 Feb 2002 07:31:39 -0000      1.8
  +++ ProxyFactory.java 7 Mar 2002 18:25:52 -0000       1.9
  @@ -6,6 +6,7 @@
   */
   package org.jboss.proxy.ejb;
   
  +
   import java.lang.reflect.InvocationHandler;
   import java.lang.reflect.Proxy;
   import java.util.ArrayList;
  @@ -29,14 +30,19 @@
   import org.jboss.ejb.ContainerInvoker;
   import org.jboss.ejb.ContainerInvokerContainer;
   import org.jboss.invocation.Invoker;
  +import org.jboss.invocation.InvocationContext;
  +import org.jboss.proxy.Interceptor;
  +import org.jboss.proxy.ClientContainer;
   import org.jboss.proxy.ejb.handle.HomeHandleImpl;
   import org.jboss.metadata.EntityMetaData;
   import org.jboss.metadata.SessionMetaData;
   import org.jboss.system.Registry;
   import org.jboss.ejb.FinderResults;
  +import org.jboss.ejb.ListCacheKey;
   
   import org.jboss.logging.Logger;
   
  +
   /**
   * As we remove the one one association between container STACK and invoker we keep 
this around
   * IN the future the creation of proxies is a task done on a container basis but the 
container
  @@ -49,7 +55,7 @@
   * just implementing the Proxy generation calls. Separation of concern. 
   *
   *  @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  -*  @version $Revision: 1.8 $
  +*  @version $Revision: 1.9 $
   *
   *  <p><b>Revisions:</b><br>
   *  <p><b>2001/12/30: billb</b>
  @@ -58,7 +64,7 @@
   *  </ol>
   */
   public class ProxyFactory
  -   implements ContainerInvoker
  + implements ContainerInvoker
   {
      // Metadata for the proxies
      public EJBMetaData ejbMetaData ;
  @@ -78,7 +84,7 @@
      protected Invoker beanInvoker;
      
      // A pointer to the container this proxy factory is dedicated to
  -   protected Container container;
  +   protected org.jboss.ejb.Container container;
      
      // Container plugin implementation -----------------------------------------
      
  @@ -113,6 +119,7 @@
         boolean statelessSession,
         HomeHandle homeHandle)
         */      
  +      
         if (container.getBeanMetaData() instanceof EntityMetaData)
         {
            Class pkClass;
  @@ -188,6 +195,27 @@
            
            initInvokers();
            
  +         // Create a stack from the description (in the future) for now we hardcode 
it
  +         InvocationContext context = new InvocationContext();
  +      
  +         context.setObjectName(new Integer(objectName));
  +         context.setValue(org.jboss.proxy.ejb.GenericEJBInterceptor.JNDI_NAME, 
jndiName);
  +         // The behavior for home proxying should be isolated in an interceptor 
FIXME
  +         context.setInvoker(homeInvoker);
  +         context.setValue(org.jboss.proxy.ejb.HomeInterceptor.EJB_METADATA, 
ejbMetaData);
  +         
  +         ClientContainer client = new ClientContainer(context);
  +      
  +         // FIXME FIXME FIXME move to externalized XML
  +         client.setNext(new org.jboss.proxy.ejb.HomeInterceptor())
  +         // FIXME FIXME FIXME move to externalized XML
  +         .setNext(new org.jboss.proxy.SecurityInterceptor())
  +         // FIXME FIXME FIXME move to externalized XML
  +         .setNext(new org.jboss.proxy.TransactionInterceptor())
  +         // FIXME FIXME FIXME move to externalized XML
  +         .setNext(new org.jboss.invocation.InvokerInterceptor());
  +         
  +         
            // Create the EJBHome
            this.home = 
            (EJBHome)Proxy.newProxyInstance(
  @@ -196,8 +224,30 @@
               // The classes we want to implement home and handle
               new Class[] { ((ContainerInvokerContainer)container).getHomeClass(), 
Class.forName("javax.ejb.Handle")},
               // The home proxy as invocation handler
  -            new HomeProxy(objectName, jndiName, homeInvoker, ejbMetaData));
  +            client);
  +            
  +            
  +         
  +         // Create a stack from the description (in the future) for now we hardcode 
it
  +         context = new InvocationContext();
  +      
  +         context.setObjectName(new Integer(objectName));
  +         context.setValue(org.jboss.proxy.ejb.GenericEJBInterceptor.JNDI_NAME, 
jndiName);
  +         // The behavior for home proxying should be isolated in an interceptor 
FIXME
  +         context.setInvoker(homeInvoker);
            
  +         client = new ClientContainer(context);
  +      
  +         // FIXME FIXME FIXME move to externalized XML
  +         client.setNext(new org.jboss.proxy.ejb.StatelessSessionInterceptor())
  +         // FIXME FIXME FIXME move to externalized XML
  +         .setNext(new org.jboss.proxy.SecurityInterceptor())
  +         // FIXME FIXME FIXME move to externalized XML
  +         .setNext(new org.jboss.proxy.TransactionInterceptor())
  +         // FIXME FIXME FIXME move to externalized XML
  +         .setNext(new org.jboss.invocation.InvokerInterceptor());
  +            
  +    
            // Create stateless session object
            // Same instance is used for all objects
            if (!(container.getBeanMetaData() instanceof EntityMetaData) &&
  @@ -210,7 +260,7 @@
                  // Interfaces    
                  new Class[] { 
((ContainerInvokerContainer)container).getRemoteClass() } ,
                  // SLSB proxy as invocation handler
  -               new StatelessSessionProxy(objectName, jndiName, beanInvoker)
  +               client
               );
            }
            
  @@ -272,7 +322,34 @@
      
      public Object getStatefulSessionEJBObject(Object id)
      {
  -      // marcf fixme: for the jrmp stuff include this creation on the client side
  +      // Create a stack from the description (in the future) for now we hardcode it
  +      InvocationContext context = new InvocationContext();
  +      
  +      context.setObjectName(new Integer(objectName));
  +      context.setCacheId(id);
  +      context.setValue(org.jboss.proxy.ejb.GenericEJBInterceptor.JNDI_NAME, 
jndiName);
  +      context.setInvoker(beanInvoker);
  +      
  +      ClientContainer client = new ClientContainer(context);
  +      
  +      // FIXME FIXME FIXME move to externalized XML
  +      client.setNext(new org.jboss.proxy.ejb.StatefulSessionInterceptor())
  +      // FIXME FIXME FIXME move to externalized XML
  +      .setNext(new org.jboss.proxy.SecurityInterceptor())
  +      // FIXME FIXME FIXME move to externalized XML
  +      .setNext(new org.jboss.proxy.TransactionInterceptor())
  +      // FIXME FIXME FIXME move to externalized XML
  +      .setNext(new org.jboss.invocation.InvokerInterceptor());
  +      
  +      return (EJBObject)Proxy.newProxyInstance(
  +         // Classloaders
  +         ((ContainerInvokerContainer)container).getRemoteClass().getClassLoader(),
  +         // Interfaces
  +         new Class[] { ((ContainerInvokerContainer)container).getRemoteClass() },
  +         // Proxy as invocation handler
  +         client);
  +         
  +      /*
         return (EJBObject)Proxy.newProxyInstance(
            // Classloaders
            ((ContainerInvokerContainer)container).getRemoteClass().getClassLoader(),
  @@ -280,10 +357,40 @@
            new Class[] { ((ContainerInvokerContainer)container).getRemoteClass() },
            // Proxy as invocation handler
            new StatefulSessionProxy(objectName, jndiName, id, beanInvoker));
  +   
  +      */
      }
      
      public Object getEntityEJBObject(Object id)
      {
  +
  +      // Create a stack from the description (in the future) for now we hardcode it
  +      InvocationContext context = new InvocationContext();
  +      
  +      context.setObjectName(new Integer(objectName));
  +      context.setCacheId(id);
  +      context.setValue(org.jboss.proxy.ejb.GenericEJBInterceptor.JNDI_NAME, 
jndiName);
  +      context.setInvoker(beanInvoker);
  +      
  +      ClientContainer client = new ClientContainer(context);
  +      
  +      // FIXME FIXME FIXME move to externalized XML
  +      client.setNext(new org.jboss.proxy.ejb.EntityInterceptor())
  +      // FIXME FIXME FIXME move to externalized XML
  +      .setNext(new org.jboss.proxy.SecurityInterceptor())
  +      // FIXME FIXME FIXME move to externalized XML
  +      .setNext(new org.jboss.proxy.TransactionInterceptor())
  +      // FIXME FIXME FIXME move to externalized XML
  +      .setNext(new org.jboss.invocation.InvokerInterceptor());
  +
  +      return (EJBObject)Proxy.newProxyInstance(
  +         // Classloaders
  +         ((ContainerInvokerContainer)container).getRemoteClass().getClassLoader(),
  +         // Interfaces
  +         new Class[] { ((ContainerInvokerContainer)container).getRemoteClass() },
  +         // Proxy as invocation handler
  +         client);
  +      /*
         // marcf fixme: for the jrmp stuff include this creation on the client side
         return (EJBObject)Proxy.newProxyInstance(
            // Classloaders
  @@ -292,6 +399,7 @@
            new Class[] { ((ContainerInvokerContainer)container).getRemoteClass() },
            // Proxy as invocation handler
            new EntityProxy(objectName, jndiName, id,beanInvoker));
  +      */
      }
      
      public Collection getEntityCollection(Collection ids)
  @@ -304,17 +412,61 @@
            
            for (int i = 0; idEnum.hasNext(); i++)
            {
  +            
  +            // Create a stack from the description (in the future) for now we 
hardcode it
  +            InvocationContext context = new InvocationContext();
  +      
  +            Object id = idEnum.next();
  +
  +            context.setObjectName(new Integer(objectName));
  +            context.setCacheId(new ListCacheKey(id, listId, i));
  +            context.setValue(org.jboss.proxy.ejb.GenericEJBInterceptor.JNDI_NAME, 
jndiName);
  +            context.setInvoker(beanInvoker);
  +      
  +            ClientContainer client = new ClientContainer(context);
  +      
  +            // FIXME FIXME FIXME move to externalized XML
  +            client.setNext(new org.jboss.proxy.ejb.ListEntityInterceptor(list))
  +            // FIXME FIXME FIXME move to externalized XML
  +            .setNext(new org.jboss.proxy.SecurityInterceptor())
  +            // FIXME FIXME FIXME move to externalized XML
  +            .setNext(new org.jboss.proxy.TransactionInterceptor())
  +            // FIXME FIXME FIXME move to externalized XML
  +            .setNext(new org.jboss.invocation.InvokerInterceptor());
  +            
               
list.add(Proxy.newProxyInstance(((ContainerInvokerContainer)container).getRemoteClass().getClassLoader(),
                     new Class[] { 
((ContainerInvokerContainer)container).getRemoteClass(), ReadAheadBuffer.class },
  -                  new ListEntityProxy(objectName, jndiName, beanInvoker, 
idEnum.next(), list, listId, i)));        
  +                  client));
            }
  -      } 
  +      }
  +      
  +      
         else {
            while(idEnum.hasNext())
            {
  +      
  +            // Create a stack from the description (in the future) for now we 
hardcode it
  +            InvocationContext context = new InvocationContext();
  +      
  +            context.setObjectName(new Integer(objectName));
  +            context.setCacheId(idEnum.next());
  +            context.setValue(org.jboss.proxy.ejb.GenericEJBInterceptor.JNDI_NAME, 
jndiName);
  +            context.setInvoker(beanInvoker);
  +      
  +            ClientContainer client = new ClientContainer(context);
  +      
  +            // FIXME FIXME FIXME move to externalized XML
  +            client.setNext(new org.jboss.proxy.ejb.EntityInterceptor())
  +            // FIXME FIXME FIXME move to externalized XML
  +            .setNext(new org.jboss.proxy.SecurityInterceptor())
  +            // FIXME FIXME FIXME move to externalized XML
  +            .setNext(new org.jboss.proxy.TransactionInterceptor())
  +            // FIXME FIXME FIXME move to externalized XML
  +            .setNext(new org.jboss.invocation.InvokerInterceptor());
  +            
               
list.add(Proxy.newProxyInstance(((ContainerInvokerContainer)container).getRemoteClass().getClassLoader(),
                     new Class[] { 
((ContainerInvokerContainer)container).getRemoteClass() },
  -                  new EntityProxy(objectName, jndiName, idEnum.next(), 
beanInvoker)));
  +                  client));
            }
         }
         return list;
  
  
  
  1.1                  jboss/src/main/org/jboss/proxy/ejb/EntityInterceptor.java
  
  Index: EntityInterceptor.java
  ===================================================================
  /*
  * JBoss, the OpenSource J2EE webOS
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.proxy.ejb;
  
  import java.io.IOException;
  import java.io.ObjectOutput;
  import java.io.ObjectInput;
  
  import java.util.HashMap;
  import java.lang.reflect.Method;
  
  import javax.naming.InitialContext;
  import javax.ejb.EJBObject;
  import javax.ejb.EJBHome;
  
  import org.jboss.ejb.CacheKey;
  import org.jboss.invocation.Invocation;
  import org.jboss.invocation.InvocationContext;
  import org.jboss.invocation.Invoker;
  
  import org.jboss.proxy.ejb.handle.EntityHandleImpl;
  
  /**
  * An EJB entity bean proxy class.
  * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  * @version $Revision: 1.1 $
  *
  * <p><b>2001/11/19: marcf</b>
  * <ol>
  *   <li>Initial checkin
  * </ol>
  */
  public class EntityInterceptor
  extends GenericEJBInterceptor
  {
     // Constants -----------------------------------------------------
     
     /** Serial Version Identifier. */
  //   private static final long serialVersionUID = -1523442773137704949L;
     
     // Attributes ----------------------------------------------------
  
     // Static --------------------------------------------------------
     
     // Constructors --------------------------------------------------
     
     /**
     * No-argument constructor for externalization.
     */
     public EntityInterceptor() {}
     
     // Public --------------------------------------------------------
     
     /**
     * InvocationHandler implementation.
     *
     * @param proxy   The proxy object.
     * @param m       The method being invoked.
     * @param args    The arguments for the method.
     *
     * @throws Throwable    Any exception or error thrown while processing.
     */
     public Object invoke(Invocation invocation) 
     throws Throwable
     {
        InvocationContext ctx = invocation.getInvocationContext();
        
        Method m = invocation.getMethod();
        
        // Implement local methods
        if (m.equals(TO_STRING)) {
           return ctx.getValue(JNDI_NAME).toString() + ":" + 
((CacheKey)ctx.getCacheId()).getId().toString();
        }
        else if (m.equals(EQUALS)) {
          return new Boolean(invocation.getArguments()[0].toString()
          .equals(ctx.getValue(JNDI_NAME).toString() + ":" + 
((CacheKey)ctx.getCacheId()).getId().toString()));
        }
        else if (m.equals(HASH_CODE)) {
           return new Integer(((CacheKey)ctx.getCacheId()).getId().hashCode());
        }
        
        // Implement local EJB calls
        else if (m.equals(GET_HANDLE)) {
           return new EntityHandleImpl((String)ctx.getValue(JNDI_NAME), 
((CacheKey)ctx.getCacheId()).getId());
        }
        else if (m.equals(GET_PRIMARY_KEY)) {
           return ((CacheKey)ctx.getCacheId()).getId();
        }
        else if (m.equals(GET_EJB_HOME)) {
           return getEJBHome(invocation);
        }
        else if (m.equals(IS_IDENTICAL)) {
          return new Boolean(invocation.getArguments()[0].toString()
          .equals(ctx.getValue(JNDI_NAME).toString() + ":" + 
((CacheKey)ctx.getCacheId()).getId().toString()));
        }
        
        // If not taken care of, go on and call the container
        else {
           
           // We are a Remote invocation
           invocation.setType(Invocation.REMOTE);
           // We pertain to this ID (represented by cache ID)
           invocation.setId(ctx.getCacheId());
           
           return getNext().invoke(invocation);
        }
     }
     
     // Package protected ---------------------------------------------
  
     // Protected -----------------------------------------------------//////
     
  }
  
  
  
  
  
  1.1                  jboss/src/main/org/jboss/proxy/ejb/GenericEJBInterceptor.java
  
  Index: GenericEJBInterceptor.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.proxy.ejb;
  
  import org.jboss.proxy.Interceptor;
  import java.io.IOException;
  import java.io.ObjectInput;
  import java.io.ObjectOutput;
  import java.io.Externalizable;
  import java.lang.reflect.Method;
  
  import org.jboss.invocation.Invocation;
  import java.rmi.RemoteException;
  
  import javax.ejb.EJBHome;
  import javax.naming.NamingException;
  
  import javax.ejb.EJBObject;
  import javax.naming.InitialContext;
  
  /*
  
  import java.lang.reflect.InvocationHandler;
  import javax.transaction.TransactionManager;
  import java.security.Principal;
  import javax.transaction.Transaction;
  import javax.transaction.SystemException;
  
  
  import org.jboss.proxy.ejb.ReadAheadBuffer;
  import org.jboss.proxy.ejb.ListEntityProxy;
  import org.jboss.invocation.Invoker;
  import org.jboss.tm.TransactionPropagationContextFactory;
  import org.jboss.security.SecurityAssociation;
  */
  
  /**
   * Generic Proxy 
   *
   * These proxies are independent of the transportation protocol.  Their role is to 
take
   * care of some of the local calls on the client (done in extension like EJB) 
   *      
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
   * @version $Revision: 1.1 $
   *
   * <p><b>2001/11/19: marcf</b>
   * <ol>
   *   <li>Initial checkin
   * </ol>
   */
  public abstract class GenericEJBInterceptor
  extends Interceptor
  implements Externalizable
  {
     
     public static final Integer JNDI_NAME = new Integer(new 
String("JNDI_NAME").hashCode());
     
     // Static method references 
     protected static final Method TO_STRING, HASH_CODE, EQUALS;
     
     // Static method references to EJB
     protected static final Method GET_PRIMARY_KEY, GET_HANDLE, GET_EJB_HOME, 
IS_IDENTICAL;
     
     /** Initialize the static variables. */
     static {
        try {
           
           // Get the methods from Object
           Class[] empty = {};
           Class type = Object.class;
           
           TO_STRING = type.getMethod("toString", empty);
           HASH_CODE = type.getMethod("hashCode", empty);
           EQUALS = type.getMethod("equals", new Class[] { type });
           
           // Get the methods from EJBObject
           type = EJBObject.class;
           
           GET_PRIMARY_KEY = type.getMethod("getPrimaryKey", empty);
           GET_HANDLE = type.getMethod("getHandle", empty);
           GET_EJB_HOME = type.getMethod("getEJBHome", empty);
           IS_IDENTICAL = type.getMethod("isIdentical", new Class[] { type });
        }
        catch (Exception e) {
           e.printStackTrace();
           throw new ExceptionInInitializerError(e);
        }
     }
     
     /**
      *  A public, no-args constructor for externalization to work.
      */
     public GenericEJBInterceptor()
     {
        // For externalization to work
     }
     
     
     /**
      * Test the identitiy of an <tt>EJBObject</tt>.
      *
      * @param a    <tt>EJBObject</tt>.
      * @param b    Object to test identity with.
      * @return     True if objects are identical.
      *
      * @throws RemoteException      Failed to get primary key.
      * @throws ClassCastException   Not an EJBObject instance.
      */
  /*
     protected Boolean isIdentical(final Object a, final Object b)
        throws RemoteException
     {
        if (a == null) return new Boolean(a==b);
           final EJBObject ejb = (EJBObject)a;
        final Object pk = ejb.getPrimaryKey();
        return new Boolean(pk.equals(b));
     }
  */   
     
     protected EJBHome getEJBHome(Invocation invocation) throws NamingException {
        return (EJBHome) new InitialContext().lookup((String) 
invocation.getInvocationContext().getValue(JNDI_NAME));
     }
  }
    
  
  
  1.1                  jboss/src/main/org/jboss/proxy/ejb/HomeInterceptor.java
  
  Index: HomeInterceptor.java
  ===================================================================
  /*
  * JBoss, the OpenSource J2EE webOS
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.proxy.ejb;
  
  import java.lang.reflect.Method;
  
  import org.jboss.invocation.Invocation;
  
  import javax.ejb.EJBHome;
  import javax.ejb.EJBMetaData;
  import javax.ejb.RemoveException;
  import javax.ejb.Handle;
  import javax.ejb.EJBHome;
  import javax.ejb.EJBObject;
  import javax.ejb.HomeHandle;
  
  import org.jboss.proxy.ejb.handle.HomeHandleImpl;
  import org.jboss.invocation.Invocation;
  import org.jboss.invocation.InvocationContext;
  import org.jboss.ejb.CacheKey;
  
  /*
  import java.io.IOException;
  import java.io.ObjectOutput;
  import java.io.ObjectInput;
  
  import java.util.HashMap;
  import java.lang.reflect.Method;
  
  
  import org.jboss.invocation.Invoker;
  import org.jboss.invocation.Invocation;
  */
  
  /*
  import javax.naming.Name;
  import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
  */
  /**
  * The client-side proxy for an EJB Home object.
  *      
  * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  * @version $Revision: 1.1 $
  *
  * <p><b>2001/11/21: marcf</b>
  * <ol>
  *   <li>Initial checkin
  * </ol>
  */
  public class HomeInterceptor
     extends GenericEJBInterceptor
  {
     // Constants -----------------------------------------------------
  
     /** Serial Version Identifier. */
  //   private static final long serialVersionUID = 432426690456622923L;
     
     // Static --------------------------------------------------------
     
     protected static final Object[] EMPTY_ARGS = {};
     
     /** {@link EJBHome#getEJBMetaData} method reference. */
     protected static final Method GET_EJB_META_DATA;
     
     /** {@link EJBHome#getHomeHandle} method reference. */
     protected static final Method GET_HOME_HANDLE;
     
     /** {@link EJBHome#remove(Handle)} method reference. */
     protected static final Method REMOVE_BY_HANDLE;
     
     /** {@link EJBHome#remove(Object)} method reference. */
     protected static final Method REMOVE_BY_PRIMARY_KEY;
     
     /** {@link EJBObject#remove} method reference. */
     protected static final Method REMOVE_OBJECT;
     
     static {
        try {
           final Class empty[] = {};
           final Class type = EJBHome.class;
           
           GET_EJB_META_DATA = type.getMethod("getEJBMetaData", empty);
           GET_HOME_HANDLE = type.getMethod("getHomeHandle", empty);
           REMOVE_BY_HANDLE = type.getMethod("remove", new Class[] { 
                 Handle.class 
              });
           REMOVE_BY_PRIMARY_KEY = type.getMethod("remove", new Class[] { 
                 Object.class 
              });
           
           // Get the "remove" method from the EJBObject
           REMOVE_OBJECT = EJBObject.class.getMethod("remove", empty);
        }
        catch (Exception e) {
           e.printStackTrace();
           throw new ExceptionInInitializerError(e);            
        }
     }
     
     // Attributes ----------------------------------------------------
     
     /** The EJB meta-data for the {@link EJBHome} reference. */    
     public final static Integer EJB_METADATA = new Integer(new 
String("EJB_METADATA").hashCode());
     
     // Constructors --------------------------------------------------
     
     /**
     * No-argument constructor for externalization.
     */
     public HomeInterceptor() {}
     
     // Public --------------------------------------------------------
     
     /**
     * InvocationHandler implementation.
     *
     * @param proxy   The proxy object.
     * @param m       The method being invoked.
     * @param args    The arguments for the method.
     *
     * @throws Throwable    Any exception or error thrown while processing.
     */
     public Object invoke(Invocation invocation)
     throws Throwable
     {
        InvocationContext ctx = invocation.getInvocationContext();
  
        Method m = invocation.getMethod();
  
        // Implement local methods
        if (m.equals(TO_STRING)) {
           return ctx.getValue(JNDI_NAME).toString() + "Home";
        }
        else if (m.equals(EQUALS)) {
           // equality of the proxy home is based on names...
           return new 
Boolean(invocation.getArguments()[0].toString().equals(ctx.getValue(JNDI_NAME).toString()
 + "Home"));
        }
        else if (m.equals(HASH_CODE)) {
           return new Integer(this.hashCode());
        }
        
        // Implement local EJB calls
        else if (m.equals(GET_HOME_HANDLE)) {
           return new HomeHandleImpl((String)ctx.getValue(JNDI_NAME));
        }
        else if (m.equals(GET_EJB_META_DATA)) {
           return ctx.getValue(EJB_METADATA);
        }
        else if (m.equals(REMOVE_BY_HANDLE)) {
           // First get the EJBObject
           EJBObject object = ((Handle) invocation.getArguments()[0]).getEJBObject();
  
           // remove the object from here
           object.remove();
  
           // Return Void
           return Void.TYPE;
        }
        else if (m.equals(REMOVE_BY_PRIMARY_KEY)) {
           // Session beans must throw RemoveException (EJB 1.1, 5.3.2)
           if (((EJBMetaData) ctx.getValue(EJB_METADATA)).isSession())
              throw new RemoveException("Session beans cannot be removed by primary 
key.");
  
           // The trick is simple we trick the container in believe it
           // is a remove() on the instance
           Object id = new CacheKey(invocation.getArguments()[0]);
  
           // Just override the Invocation going out
           invocation.setId(id);
           invocation.setType(Invocation.REMOTE);
           invocation.setMethod(REMOVE_OBJECT);
           invocation.setArguments(EMPTY_ARGS);
           return getNext().invoke(invocation);
        }
  
        // If not taken care of, go on and call the container
        else {
           
           invocation.setType(Invocation.HOME);
        
           // Create an Invocation
           return getNext().invoke(invocation);
       }
     }
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/proxy/ejb/ListEntityInterceptor.java
  
  Index: ListEntityInterceptor.java
  ===================================================================
  /*
  * JBoss, the OpenSource J2EE webOS
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.proxy.ejb;
  
  import java.util.List;
  import java.util.HashMap;
  import java.util.Map;
  
  import java.io.IOException;
  import java.io.ObjectOutput;
  import java.io.ObjectInput;
  
  import java.lang.reflect.InvocationHandler;
  import java.lang.reflect.Method;
  
  import javax.naming.InitialContext;
  import javax.ejb.EJBObject;
  import javax.ejb.EJBHome;
  
  import org.jboss.invocation.Invoker;
  import org.jboss.ejb.ListCacheKey;
  import org.jboss.invocation.Invocation;
  
  /**
  * An EJB CMP entity bean proxy class holds info about the List that the entity 
belongs to,
  * is used for reading ahead.
  *
  * @author <a href="mailto:[EMAIL PROTECTED]";>Oleg Nitz</a>
  * @version $Revision: 1.1 $
  *
  * @todo: (marcf) methinks that this behavior should be moved to a REAL interceptor 
(i.e not as extends)
  */
  public class ListEntityInterceptor
  extends EntityInterceptor
  {
     // Constants -----------------------------------------------------
     
     /** Serial Version Identifier. */
     //   private static final long serialVersionUID = -1523442773137704949L;
     
     protected static final Method GET_READ_AHEAD_VALUES;
     
     // Attributes ----------------------------------------------------
     
     /**
     * A List that this entity belongs to (used for reading ahead).
     */
     private List list;
     
     /**
     * A hash map of read ahead values, maps Methods to values.
     */
     private transient HashMap readAheadValues;
     
     // Static --------------------------------------------------------
     
     static {
        try {
           final Class[] empty = {};
           
           GET_READ_AHEAD_VALUES = 
ReadAheadBuffer.class.getMethod("getReadAheadValues", empty);
        }
        catch (Exception e) {
           e.printStackTrace();
           throw new ExceptionInInitializerError(e);
        }
     }
     
     // Constructors --------------------------------------------------
     
     /**
     * No-argument constructor for externalization.
     */
     public ListEntityInterceptor() {}
     
     /**
     * Construct a <tt>ListEntityProxy</tt>.
     *
     * @param name            The JNDI name of the container that we proxy for.
     * @param container       The remote interface of the invoker for which
     *                        this is a proxy for.
     * @param id              The primary key of the entity.
     * @param optimize        True if the proxy will attempt to optimize
     *                        VM-local calls.
     * @param list            A List that this entity belongs to (used for reading 
ahead).
     * @param listId The list id.
     * @param index The index of this entity in the list.
     *
     * @throws NullPointerException     Id may not be null.
     */
   
     public ListEntityInterceptor(List list) { this.list = list;}
   
     // Public --------------------------------------------------------
     
     public Map getReadAheadValues() {
        if (readAheadValues == null) {
           readAheadValues = new HashMap();
        }
        return readAheadValues;
     }
     
     
     /**
     * InvocationHandler implementation.
     *
     * @param proxy   The proxy object.
     * @param m       The method being invoked.
     * @param args    The arguments for the method.
     *
     * @throws Throwable    Any exception or error thrown while processing.
     */
     public Object invoke(Invocation invocation)
     throws Throwable
     {
        Object result;
        ReadAheadResult raResult;
        Object[] aheadResult;
        int from;
        int to;
        ReadAheadBuffer buf;
     
        Method m = invocation.getMethod();
        
        if (m.equals(GET_READ_AHEAD_VALUES)) {
           return getReadAheadValues();
        }
        
        // have we read ahead the result?
        if (readAheadValues != null) {
           result = readAheadValues.get(m);
           if (readAheadValues.containsKey(m)) {
              return readAheadValues.remove(m);
           }
        }
        
        result = super.invoke(invocation);
        
        // marcf : I think all these will map nicely to the in/out of real 
interceptor, i.e. do not "extend"
        
        if (result instanceof ReadAheadResult) {
           raResult = (ReadAheadResult) result;
           aheadResult = raResult.getAheadResult();
           from = ((ListCacheKey) 
invocation.getInvocationContext().getCacheId()).getIndex() + 1;
           to = Math.min(from + aheadResult.length, list.size());
           for (int i = from; i < to; i++) {
              buf = (ReadAheadBuffer) list.get(i);
              buf.getReadAheadValues().put(m, aheadResult[i - from]);
           }
           return raResult.getMainResult();
        } else {
           return result;
        }
     }
     
     // Package protected ---------------------------------------------
     
     // Protected -----------------------------------------------------
     
     /**
     * Externalization support.
     *
     * @param out
     *
     * @throws IOException
     */
     public void writeExternal(final ObjectOutput out)
     throws IOException
     {
        super.writeExternal(out);
        out.writeObject(list);
     }
     
     /**
     * Externalization support.
     *
     * @param in
     *
     * @throws IOException
     * @throws ClassNotFoundException
     */
     public void readExternal(final ObjectInput in)
     throws IOException, ClassNotFoundException
     {
        super.readExternal(in);
        list = (List)in.readObject();
     }
     
     
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
  }
  
  
  
  
  1.1                  
jboss/src/main/org/jboss/proxy/ejb/StatefulSessionInterceptor.java
  
  Index: StatefulSessionInterceptor.java
  ===================================================================
  /*
  * JBoss, the OpenSource J2EE webOS
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.proxy.ejb;
  
  import java.io.IOException;
  import java.io.ObjectOutput;
  import java.io.ObjectInput;
  
  import java.lang.reflect.Method;
  import java.util.HashMap;
  
  import javax.naming.InitialContext;
  
  import javax.ejb.EJBObject;
  import javax.ejb.EJBHome;
  import javax.naming.Name;
  
  import org.jboss.invocation.Invocation;
  import org.jboss.invocation.InvocationContext;
  import org.jboss.invocation.Invoker;
  
  import org.jboss.proxy.ejb.handle.StatefulHandleImpl;
  
  /**
  * An EJB stateful session bean proxy class.
  *   
  * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  * @version $Revision: 1.1 $
  *
  * <p><b>2001/11/23: marcf</b>
  * <ol>
  *   <li>Initial checkin
  * </ol>
  */
  public class StatefulSessionInterceptor
  extends GenericEJBInterceptor
  {
     // Constants -----------------------------------------------------
     
     /** Serial Version Identifier. */
    // private static final long serialVersionUID = 1379411137308931705L;
     
     // Attributes ----------------------------------------------------
     
     /** JBoss generated identifier. */
     public static final Integer SESSION_ID = new Integer(new String("SESSION_ID"));
  
     // Static --------------------------------------------------------
    
     // Constructors --------------------------------------------------
     
     /**
     * No-argument constructor for externalization.
     */
     public StatefulSessionInterceptor() {}
     
     // Public --------------------------------------------------------
     
     /**
     * InvocationHandler implementation.
     *
     * @throws Throwable    Any exception or error thrown while processing.
     */
     public  Object invoke(Invocation invocation)
     throws Throwable
     {
        InvocationContext ctx = invocation.getInvocationContext();
              
        Method m = invocation.getMethod();
        
        // Implement local methods
        if (m.equals(TO_STRING)) {
           return ctx.getValue(JNDI_NAME) + ":" + ctx.getCacheId().toString();
        }
        else if (m.equals(EQUALS)) {
  
           return new 
Boolean(invocation.getArguments()[0].toString().equals(ctx.getValue(JNDI_NAME).toString()
 + ":" + ctx.getCacheId().toString()));
        }
        else if (m.equals(HASH_CODE)) {
           return new Integer(ctx.getCacheId().hashCode());
        }
  
        // Implement local EJB calls
        else if (m.equals(GET_HANDLE)) {
           
           return new StatefulHandleImpl(((Integer) ctx.getObjectName()).intValue(), 
(String) ctx.getValue(JNDI_NAME), ctx.getInvoker(), ctx.getCacheId());
        }
        else if (m.equals(GET_EJB_HOME)) {
  
           return getEJBHome(invocation);
        }
        else if (m.equals(GET_PRIMARY_KEY)) {
  
           return ctx.getCacheId();
        }
        else if (m.equals(IS_IDENTICAL)) {
  
           return new 
Boolean(invocation.getArguments()[0].toString().equals(ctx.getValue(JNDI_NAME).toString()
 + ":" + ctx.getCacheId().toString()));
        }
  
        // If not taken care of, go on and call the container
        else {
           
           // It is a remote invocation
           invocation.setType(Invocation.REMOTE);
           
           // On this entry in cache
           invocation.setId(ctx.getCacheId());
           
           return getNext().invoke(invocation);
        }
     }
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/proxy/ejb/StatelessSessionInterceptor.java
  
  Index: StatelessSessionInterceptor.java
  ===================================================================
  /*
  * JBoss, the OpenSource J2EE webOS
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.proxy.ejb;
  
  import java.lang.reflect.Method;
  import java.util.HashMap;
  
  import org.jboss.invocation.Invoker;
  import org.jboss.invocation.Invocation;
  import org.jboss.invocation.InvocationContext;
  import org.jboss.proxy.ejb.handle.StatelessHandleImpl;
  
  
  /**
  * An EJB stateless session bean proxy class.
  *   
  * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  * @version $Revision: 1.1 $
  *
  * <p><b>2001/11/23: marcf</b>
  * <ol>
  *   <li>Initial checkin
  * </ol>  
  */
  public class StatelessSessionInterceptor
  extends GenericEJBInterceptor
  {
     // Constants -----------------------------------------------------
     
     /** Serial Version Identifier. */
     //   private static final long serialVersionUID = 2327647224051998978L;
     
     // Attributes ----------------------------------------------------
     
     // Static --------------------------------------------------------
     
     // Constructors --------------------------------------------------
     
     /**
     * No-argument constructor for externalization.
     */
     public StatelessSessionInterceptor() {}
     
     
     // Public --------------------------------------------------------
     
     /**
     * InvocationHandler implementation.
     *
     * @param proxy   The proxy object.
     * @param m       The method being invoked.
     * @param args    The arguments for the method.
     *
     * @throws Throwable    Any exception or error thrown while processing.
     */
     public Object invoke(Invocation invocation)
     throws Throwable
     {
     
        InvocationContext ctx = invocation.getInvocationContext();
        
        Method m = invocation.getMethod();
        
        // Implement local methods
        if (m.equals(TO_STRING)) {
           return ctx.getValue(JNDI_NAME) + ":Stateless";
        }
        else if (m.equals(EQUALS)) {
            
           return new 
Boolean(invocation.getArguments()[0].toString().equals(ctx.getValue(JNDI_NAME).toString()
 + ":Stateless"));
        }
        else if (m.equals(HASH_CODE)) {
           // We base the stateless hash on the hash of the proxy...
           // MF XXX: it could be that we want to return the hash of the name?
           return new Integer(this.hashCode());
        }
        
        // Implement local EJB calls
        else if (m.equals(GET_HANDLE)) {
           return new StatelessHandleImpl((String)ctx.getValue(JNDI_NAME));
        }
        else if (m.equals(GET_PRIMARY_KEY)) {
           
           return ctx.getValue(JNDI_NAME);
        }
        else if (m.equals(GET_EJB_HOME)) {
           return getEJBHome(invocation);
        }
        
        else if (m.equals(IS_IDENTICAL)) {
           // All stateless beans are identical within a home,
           // if the names are equal we are equal
           return new 
Boolean(invocation.getArguments()[0].toString().equals(ctx.getValue(JNDI_NAME).toString()
 + ":Stateless"));
        }
        
        // If not taken care of, go on and call the container
        else {
        
           invocation.setType(Invocation.REMOTE);
           
           return getNext().invoke(invocation);
        }
     }
     
     // Package protected ---------------------------------------------
     
     // Protected -----------------------------------------------------
     
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
  }
  
  

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

Reply via email to