User: mnf999  
  Date: 01/12/18 23:20:36

  Added:       src/main/org/jboss/proxy/ejb EntityProxy.java
                        GenericProxy.java HomeProxy.java
                        StatefulSessionProxy.java
                        StatelessSessionProxy.java
  Log:
  Adaptation of the old proxy package in ejb.
  
  These proxies are not aware of the transport protocols and just talk to the delegate 
invoker...
  
  Revision  Changes    Path
  1.1                  jboss/src/main/org/jboss/proxy/ejb/EntityProxy.java
  
  Index: EntityProxy.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.rmi.MarshalledObject;
  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.Invoker;
  
  import org.jboss.proxy.ejb.handle.EntityHandleImpl;
  import org.jboss.util.FinderResults;
  
  
  /**
  * 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 EntityProxy
  extends GenericProxy
  {
     // Constants -----------------------------------------------------
     
     /** Serial Version Identifier. */
  //   private static final long serialVersionUID = -1523442773137704949L;
     
     // Attributes ----------------------------------------------------
     
     /** The primary key of the entity bean. */
     protected CacheKey cacheKey;
     
     // Static --------------------------------------------------------
     
     // Constructors --------------------------------------------------
     
     /**
     * No-argument constructor for externalization.
     */
     public EntityProxy() {}
     
     /**
     * Construct a <tt>EntityProxy</tt>.
     *
     * @param name          The JNDI name of the container that we proxy for.
     * @param id            The primary key of the entity.
     * @param invoker       An invoker
     *
     * @throws NullPointerException     Id may not be null.
     */
     public EntityProxy(String jndiName, Object id, Invoker invoker)
     {
        super(jndiName, invoker);
        
        if (id == null)
           throw new NullPointerException("Id may not be null");
        
        // make sure that our id is a CacheKey
        if (id instanceof CacheKey) {
           this.cacheKey = (CacheKey)id;
        }
        else {
           // In case we pass the Object or anything else we encapsulate
           cacheKey = new CacheKey(id);
        }
     }
     
     // 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(final Object proxy,
        final Method m,
        Object[] args)
     throws Throwable
     {
        // Normalize args to always be an array
        if (args == null)
           args = EMPTY_ARGS;
        
        // Implement local methods
        if (m.equals(TO_STRING)) {
           return jndiName + ":" + cacheKey.getId().toString();
        }
        else if (m.equals(EQUALS)) {
           return invoke(proxy, IS_IDENTICAL, args);
        }
        else if (m.equals(HASH_CODE)) {
           return new Integer(cacheKey.getId().hashCode());
        }
        
        // Implement local EJB calls
        else if (m.equals(GET_HANDLE)) {
           return new EntityHandleImpl(jndiName, cacheKey.getId());
        }
        else if (m.equals(GET_PRIMARY_KEY)) {
           return cacheKey.getId();
        }
        else if (m.equals(GET_EJB_HOME)) {
           return getEJBHome();
        }
        else if (m.equals(IS_IDENTICAL)) {
           return isIdentical(args[0], cacheKey.getId());
        }
        
        // If not taken care of, go on and call the container
        else {
           return invoke(createInvocation(cacheKey, m, args));
        }
     }
     public Invocation createInvocation(CacheKey id, Method m, Object[] args)
     {
        Invocation invocation = new Invocation(new HashMap());
        
        invocation.setContainer(objectName);
        invocation.setType("remote");
        invocation.setId(id);
        invocation.setMethod(m);
        invocation.setArguments(args);    
        
        return invocation;
     }
     // Package protected ---------------------------------------------
     
     // Protected -----------------------------------------------------
     
     /**
     * Externalization support.
     *
     * @param out
     *
     * @throws IOException
     */
     public void writeExternal(final ObjectOutput out)
     throws IOException
     {
        super.writeExternal(out);
        out.writeObject(cacheKey);
     }
     
     /**
     * Externalization support.
     *
     * @param in
     *
     * @throws IOException
     * @throws ClassNotFoundException
     */
     public void readExternal(final ObjectInput in)
     throws IOException, ClassNotFoundException
     {
        super.readExternal(in);
        cacheKey = (CacheKey)in.readObject();
        
        // Private -------------------------------------------------------
        
        // Inner classes -------------------------------------------------
     }
  }
     
     
  
  
  1.1                  jboss/src/main/org/jboss/proxy/ejb/GenericProxy.java
  
  Index: GenericProxy.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.ObjectInput;
  import java.io.ObjectOutput;
  import java.io.Externalizable;
  import java.lang.reflect.Method;
  import java.lang.reflect.InvocationHandler;
  import javax.transaction.TransactionManager;
  import java.security.Principal;
  import javax.transaction.Transaction;
  import javax.transaction.SystemException;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  
  import javax.ejb.EJBObject;
  import javax.ejb.EJBHome;
  import java.rmi.RemoteException;
  
  import org.jboss.proxy.ejb.ReadAheadBuffer;
  import org.jboss.proxy.ejb.ListEntityProxy;
  import org.jboss.invocation.Invocation;
  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) and to 
  * delegate the calls to a "delegate invoker". 
  *      
  * 
  * @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 GenericProxy
  implements Externalizable, InvocationHandler
  {
     // Constants -----------------------------------------------------
     
     /** Serial Version Identifier. */
     //   private static final long serialVersionUID = 1870461898442160570L;
     
     // Attributes ----------------------------------------------------
     
     // Invoker to the delegate
     protected Invoker invoker;
     
     // A proxy is associated with a given container, we identify the container by any 
object
     // in RH 3.0 this is for example a simple MBean identifying the container in the 
future 
     // we should give just an abstract key into a metadata container repository in 
the server
     protected transient String objectName;
     protected String jndiName;
     
     // An empty method parameter list.
     protected static final Object[] EMPTY_ARGS = {};
     
     // 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);
        }
     }
     
     /**
     *  Our transaction manager.
     *
     *  When set to a non-null value, this is used for getting the
     *  transaction to use for optimized local method invocations.
     *  If <code>null</code>, transactions are not propagated on
     *  optimized local method invocations.
     */
     protected static TransactionManager tm = null;
     
     // Get and set methods
     
     // Transaction manager
     public static void setTransactionManager(TransactionManager txm) { tm = txm; }
     
     // Constructors --------------------------------------------------
     
     /**
     *  A public, no-args constructor for externalization to work.
     */
     public GenericProxy()
     {
        // For externalization to work
     }
     
     /**
     *  Create a new GenericProxy.
     *
     *  @param container
     *  @param invoker
     */
     protected GenericProxy(String jndiName, Invoker invoker)
     {
        this.jndiName = jndiName;
        
        this.objectName = "J2EE:service=EJB,jndiName="+jndiName;
        
        this.invoker = invoker;
     }
     
     // Package protected ---------------------------------------------
     
     /**
     * 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));
     }
     
     // Get Principal and credentials 
     protected Principal getPrincipal() { return SecurityAssociation.getPrincipal(); }
     protected Object getCredential() { return SecurityAssociation.getCredential(); }
     
     /**
     *  Return the transaction associated with the current thread.
     *  Returns <code>null</code> if the transaction manager was never
     *  set, or if no transaction is associated with the current thread.
     */
     protected Transaction getTransaction()
     throws SystemException
     {
        return (tm == null) ? null : tm.getTransaction();
     }
     
     // Protected -----------------------------------------------------
     
     protected EJBHome getEJBHome() throws NamingException {
        
        return (EJBHome) new InitialContext().lookup(jndiName);
     }
     /**
     * Invoke a method.
     *
     * The actual optimization happens in the delegate, the responsibility here it set 
the 
     * variables on the Invocation
     *
     */
     protected Object invoke(Invocation invocation)
     throws Exception
     {
        
        // just delegate
        return invoker.invoke(invocation);
     }
     
     
     /**
     *  Externalize this instance.
     *
     *  If this instance lives in a different VM than its container
     *  invoker, the remote interface of the container invoker is
     *  not externalized.
     */
     public void writeExternal(final ObjectOutput out)
     throws IOException
     {
        out.writeUTF(jndiName);
        out.writeObject(invoker);
     }
     
     /**
     *  Un-externalize this instance.
     *
     *  If this instance is deserialized in the same VM as its container
     *  invoker, the remote interface of the container invoker is
     *  restored by looking up the name in the invokers map.
     */
     public void readExternal(final ObjectInput in)
     throws IOException, ClassNotFoundException
     {
        jndiName = in.readUTF();
        objectName = "J2EE:service=EJB,jndiName="+jndiName;
        invoker = (Invoker) in.readObject();
     }
     
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
  }
  
  
  
  
  1.1                  jboss/src/main/org/jboss/proxy/ejb/HomeProxy.java
  
  Index: HomeProxy.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.rmi.MarshalledObject;
  
  import java.lang.reflect.Method;
  import java.util.HashMap;
  import java.lang.reflect.Method;
  
  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.ejb.CacheKey;
  import org.jboss.invocation.Invoker;
  import org.jboss.proxy.ejb.handle.HomeHandleImpl;
  import org.jboss.invocation.Invocation;
  
  import org.jboss.util.FinderResults;
  
  /*
  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 HomeProxy
  extends GenericProxy
  {
     // Constants -----------------------------------------------------
     
     /** Serial Version Identifier. */
  //   private static final long serialVersionUID = 432426690456622923L;
     
     // Static --------------------------------------------------------
     
     /** {@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. */    
     protected EJBMetaData ejbMetaData;
     
     // Constructors --------------------------------------------------
     
     /**
     * No-argument constructor for externalization.
     */
     public HomeProxy() {}
     
     /**
     * Construct a <tt>HomeProxy</tt>.
     *
     */
     public HomeProxy(String jndiName, Invoker invoker, EJBMetaData ejbMetaData)
     {
        super(jndiName, invoker);
        this.ejbMetaData = ejbMetaData;  
     }
     
     // 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(final Object proxy,
        final 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 = EMPTY_ARGS;
        
        // Implement local methods
        if (m.equals(TO_STRING)) {
           return jndiName.toString() + "Home";
        }
        else if (m.equals(EQUALS)) {
           // equality of the proxy home is based on names...
           Object temp = invoke(proxy, TO_STRING, args);
           return new Boolean(temp.equals(jndiName.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(jndiName);
        }
        else if (m.equals(GET_EJB_META_DATA)) {
           return ejbMetaData;
        }
        else if (m.equals(REMOVE_BY_HANDLE)) {
           // First get the EJBObject
           EJBObject object = ((Handle) args[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.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(args[0]);
           
           // create an invocation for the new format
           
           Invocation invocation = new Invocation(new HashMap());
           
           invocation.setContainer(objectName);
           invocation.setId(id);
           invocation.setType("remote");
           invocation.setMethod(REMOVE_OBJECT);
           invocation.setArguments(EMPTY_ARGS);
           return invoke(invocation);
        }
        
        
        // If not taken care of, go on and call the container
        else { 
           
           // Create an Invocation
           
           return invoke(createInvocation(m, args));
        }
     }
     
     
     public Invocation createInvocation(Method m, Object[] arguments)
     {
        
        Invocation invocation = new Invocation(new HashMap());
        
        invocation.setContainer(objectName);
        invocation.setType("home");
        invocation.setMethod(m);
        invocation.setArguments(arguments);
        
        return invocation;
     }
     
     /**
     * Externalization support.
     *
     * @param out
     *
     * @throws IOException
     */
     public void writeExternal(final ObjectOutput out)
     throws IOException
     {
        super.writeExternal(out);
        out.writeObject(ejbMetaData);
     }
     
     /**
     * Externalization support.
     *
     * @param in
     *
     * @throws IOException
     * @throws ClassNotFoundException
     */
     public void readExternal(final ObjectInput in)
     throws IOException, ClassNotFoundException
     {
        super.readExternal(in);
        ejbMetaData = (EJBMetaData)in.readObject();
     }
     
     // Package protected ---------------------------------------------
     
     // Protected -----------------------------------------------------
     
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/proxy/ejb/StatefulSessionProxy.java
  
  Index: StatefulSessionProxy.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.rmi.MarshalledObject;
  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.Invoker;
  
  import org.jboss.proxy.ejb.handle.StatefulHandleImpl;
  import org.jboss.util.FinderResults;
  
  /**
  * 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 StatefulSessionProxy
  extends GenericProxy
  {
     // Constants -----------------------------------------------------
     
     /** Serial Version Identifier. */
    // private static final long serialVersionUID = 1379411137308931705L;
     
     // Attributes ----------------------------------------------------
     
     /** JBoss generated identifier. */
     protected Object id;
     
     // Static --------------------------------------------------------
    
     // Constructors --------------------------------------------------
     
     /**
     * No-argument constructor for externalization.
     */
     public StatefulSessionProxy() {}
     
     /**
     * Construct a <tt>StatefulSessionProxy</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            JBoss generated identifier.
     * @param optimize      True if the proxy will attempt to optimize
     *                      VM-local calls.
     */
     public StatefulSessionProxy(String name,
        Object cacheID,
        Invoker invoker)
     {
        super(name,invoker);
        id = cacheID;
     }
     
     // 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 final Object invoke(final Object proxy,
        final Method m,
        Object[] args)
     throws Throwable
     {
        // Normalize args to always be an array
        if (args == null)
           args = EMPTY_ARGS;
        
        // Implement local methods
        if (m.equals(TO_STRING)) {
           return jndiName + ":" + id.toString();
        }
        else if (m.equals(EQUALS)) {
           return invoke(proxy, IS_IDENTICAL, args);
        }
        else if (m.equals(HASH_CODE)) {
           return new Integer(id.hashCode());
        }
        
        // Implement local EJB calls
        else if (m.equals(GET_HANDLE)) {
           return new StatefulHandleImpl(jndiName,invoker.getServerHostName(), id);
        }
        else if (m.equals(GET_EJB_HOME)) {
           
           return getEJBHome();
        }
        else if (m.equals(GET_PRIMARY_KEY)) {
         
           return id;
        }
        else if (m.equals(IS_IDENTICAL)) {
           // MF FIXME
           // See above, this is not correct but works for now (do jboss1.0 PKHolder 
hack in here)
           return isIdentical(args[0], id);
        }
        
        // If not taken care of, go on and call the container
        else {
           return invoke(createInvocation(id, m, args));
        }
     }
     
     public Invocation createInvocation(Object id, Method m, Object[] args) 
     {
        Invocation invocation = new Invocation(new HashMap());
        invocation.setContainer(objectName);
        invocation.setType("remote");
        invocation.setId(id);
        invocation.setMethod(m);
        invocation.setArguments(args);
        
        return invocation;
     
     }
     // Package protected ---------------------------------------------
     
     
     // Protected -----------------------------------------------------
     
     /**
     * Externalization support.
     *
     * @param out
     *
     * @throws IOException
     */
     public void writeExternal(final ObjectOutput out)
     throws IOException
     {
        super.writeExternal(out);
        out.writeObject(id);
     }
     /**
     * Externalization support.
     *
     * @param in
     *
     * @throws IOException
     * @throws ClassNotFoundException
     */
     public void readExternal(final ObjectInput in)
     throws IOException, ClassNotFoundException
     {
        super.readExternal(in);
        id = in.readObject();
     }
     
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/proxy/ejb/StatelessSessionProxy.java
  
  Index: StatelessSessionProxy.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.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 StatelessSessionProxy
  extends GenericProxy
  {
     // Constants -----------------------------------------------------
     
     /** Serial Version Identifier. */
  //   private static final long serialVersionUID = 2327647224051998978L;
     
     // Attributes ----------------------------------------------------
     
     // Static --------------------------------------------------------
     
     // Constructors --------------------------------------------------
     
     /**
     * No-argument constructor for externalization.
     */
     public StatelessSessionProxy() {}
     
     /**
     * Construct a <tt>StatelessSessionProxy</tt>.
     *
     */
     public StatelessSessionProxy(String jndiName,
        Invoker invoker)
     {
        super(jndiName,invoker);
     }
     
     // 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 final Object invoke(final Object proxy,
        final Method m,
        Object[] args)
     throws Throwable
     {
        // Normalize args to always be an array
        if (args == null)
           args = EMPTY_ARGS;
        
        // Implement local methods
        if (m.equals(TO_STRING)) {
           return jndiName + ":Stateless";
        }
        else if (m.equals(EQUALS)) {
           return invoke(proxy, IS_IDENTICAL, args);
        }
        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(jndiName);
        }
        else if (m.equals(GET_PRIMARY_KEY)) {
           
           return jndiName;
        }
        else if (m.equals(GET_EJB_HOME)) {
           return getEJBHome();
        }
        
        else if (m.equals(IS_IDENTICAL)) {
           // All stateless beans are identical within a home,
           // if the names are equal we are equal
           return isIdentical(args[0], jndiName);
        }
        
        // If not taken care of, go on and call the container
        else {
           return invoke(createInvocation(m, args));
        }
     }
     
     public Invocation createInvocation(Method m, Object[] args) 
     {
        Invocation invocation = new Invocation(new HashMap());
        
        invocation.setContainer(objectName);
        invocation.setType("remote");
        invocation.setMethod(m);
        invocation.setArguments(args);  
        
        return 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