User: starksm 
  Date: 02/03/07 17:26:55

  Modified:    src/main/org/jboss/proxy/ejb EntityInterceptor.java
                        GenericEJBInterceptor.java
                        StatefulSessionInterceptor.java
                        StatelessSessionInterceptor.java
  Log:
  Fix the stateful interceptor use of Integer and reduce the
  obfuscation level of the code.
  
  Revision  Changes    Path
  1.2       +67 -57    jboss/src/main/org/jboss/proxy/ejb/EntityInterceptor.java
  
  Index: EntityInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/proxy/ejb/EntityInterceptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EntityInterceptor.java    7 Mar 2002 18:25:52 -0000       1.1
  +++ EntityInterceptor.java    8 Mar 2002 01:26:55 -0000       1.2
  @@ -1,106 +1,114 @@
   /*
  -* JBoss, the OpenSource J2EE webOS
  -*
  -* Distributable under LGPL license.
  -* See terms of license at gnu.org.
  -*/
  + * 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 javax.naming.InitialContext;
   
   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>
  -*/
  + * An EJB entity bean proxy class.
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  + * @version $Revision: 1.2 $
  + *
  + * <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;
  +   //   private static final long serialVersionUID = -1523442773137704949L;
      
      // Attributes ----------------------------------------------------
  -
  +   
      // Static --------------------------------------------------------
      
      // Constructors --------------------------------------------------
      
      /**
  -   * No-argument constructor for externalization.
  -   */
  -   public EntityInterceptor() {}
  +    * 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
  +    * 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());
  +      if (m.equals(TO_STRING))
  +      {
  +         return toString(ctx);
  +      }
  +      else if (m.equals(EQUALS))
  +      {
  +         Object[] args = invocation.getArguments();
  +         String argsString = args[0].toString();
  +         String thisString = toString(ctx);
  +         return new Boolean(thisString.equals(argsString));
  +      }
  +      else if (m.equals(HASH_CODE))
  +      {
  +         return new Integer(ctx.getCacheId().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_HANDLE))
  +      {
  +         String jndiName = (String) ctx.getValue(JNDI_NAME);
  +         Object id = ((CacheKey)ctx.getCacheId()).getId();
  +         return new EntityHandleImpl(jndiName, id);
         }
  -      else if (m.equals(GET_PRIMARY_KEY)) {
  +      else if (m.equals(GET_PRIMARY_KEY))
  +      {
            return ((CacheKey)ctx.getCacheId()).getId();
         }
  -      else if (m.equals(GET_EJB_HOME)) {
  +      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()));
  +      else if (m.equals(IS_IDENTICAL))
  +      {
  +         Object[] args = invocation.getArguments();
  +         String argsString = args[0].toString();
  +         String thisString = toString(ctx);
  +         return new Boolean(thisString.equals(argsString));
         }
  -      
         // If not taken care of, go on and call the container
  -      else {
  -         
  +      else
  +      {
            // We are a Remote invocation
            invocation.setType(Invocation.REMOTE);
            // We pertain to this ID (represented by cache ID)
  @@ -111,9 +119,11 @@
      }
      
      // Package protected ---------------------------------------------
  -
  +   
      // Protected -----------------------------------------------------//////
  +   private String toString(InvocationContext ctx)
  +   {
  +      return ctx.getValue(JNDI_NAME) + ":" + ctx.getCacheId().toString();
  +   }
      
   }
  -
  -
  
  
  
  1.2       +14 -9     jboss/src/main/org/jboss/proxy/ejb/GenericEJBInterceptor.java
  
  Index: GenericEJBInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/proxy/ejb/GenericEJBInterceptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GenericEJBInterceptor.java        7 Mar 2002 18:25:52 -0000       1.1
  +++ GenericEJBInterceptor.java        8 Mar 2002 01:26:55 -0000       1.2
  @@ -47,7 +47,7 @@
    *      
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    *
    * <p><b>2001/11/19: marcf</b>
    * <ol>
  @@ -55,8 +55,8 @@
    * </ol>
    */
   public abstract class GenericEJBInterceptor
  -extends Interceptor
  -implements Externalizable
  +   extends Interceptor
  +   implements Externalizable
   {
      
      public static final Integer JNDI_NAME = new Integer(new 
String("JNDI_NAME").hashCode());
  @@ -68,9 +68,10 @@
      protected static final Method GET_PRIMARY_KEY, GET_HANDLE, GET_EJB_HOME, 
IS_IDENTICAL;
      
      /** Initialize the static variables. */
  -   static {
  -      try {
  -         
  +   static
  +   {
  +      try
  +      { 
            // Get the methods from Object
            Class[] empty = {};
            Class type = Object.class;
  @@ -87,7 +88,8 @@
            GET_EJB_HOME = type.getMethod("getEJBHome", empty);
            IS_IDENTICAL = type.getMethod("isIdentical", new Class[] { type });
         }
  -      catch (Exception e) {
  +      catch (Exception e)
  +      {
            e.printStackTrace();
            throw new ExceptionInInitializerError(e);
         }
  @@ -123,8 +125,11 @@
      }
   */   
      
  -   protected EJBHome getEJBHome(Invocation invocation) throws NamingException {
  -      return (EJBHome) new InitialContext().lookup((String) 
invocation.getInvocationContext().getValue(JNDI_NAME));
  +   protected EJBHome getEJBHome(Invocation invocation) throws NamingException
  +   {
  +      InitialContext iniCtx = new InitialContext();
  +      String jndiName = (String) 
invocation.getInvocationContext().getValue(JNDI_NAME);
  +      return (EJBHome) iniCtx.lookup(jndiName);
      }
   }
     
  
  
  
  1.2       +67 -59    
jboss/src/main/org/jboss/proxy/ejb/StatefulSessionInterceptor.java
  
  Index: StatefulSessionInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/proxy/ejb/StatefulSessionInterceptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StatefulSessionInterceptor.java   7 Mar 2002 18:25:52 -0000       1.1
  +++ StatefulSessionInterceptor.java   8 Mar 2002 01:26:55 -0000       1.2
  @@ -1,110 +1,113 @@
   /*
  -* JBoss, the OpenSource J2EE webOS
  -*
  -* Distributable under LGPL license.
  -* See terms of license at gnu.org.
  -*/
  + * 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.InitialContext;
   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>
  -*/
  + *
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  + * @version $Revision: 1.2 $
  + *
  + * <p><b>2001/11/23: marcf</b>
  + * <ol>
  + *   <li>Initial checkin
  + * </ol>
  + */
   public class StatefulSessionInterceptor
  -extends GenericEJBInterceptor
  +   extends GenericEJBInterceptor
   {
      // Constants -----------------------------------------------------
      
      /** Serial Version Identifier. */
  -  // private static final long serialVersionUID = 1379411137308931705L;
  +   // 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() {}
  -   
  +    * 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
  +    * 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();
  +      if (m.equals(TO_STRING))
  +      {
  +         return toString(ctx);
  +      }
  +      else if (m.equals(EQUALS))
  +      {
  +         Object[] args = invocation.getArguments();
  +         String argsString = args[0].toString();
  +         String thisString = toString(ctx);
  +         return new Boolean(thisString.equals(argsString));
         }
  -      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)) {
  +      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_HANDLE))
  +      {
  +         int objectName = ((Integer) ctx.getObjectName()).intValue();
  +         String jndiName = (String) ctx.getValue(JNDI_NAME);
  +         Invoker invoker = ctx.getInvoker();
  +         Object id = ctx.getCacheId();
  +         return new StatefulHandleImpl(objectName, jndiName, invoker, id);
         }
  -      else if (m.equals(GET_EJB_HOME)) {
  -
  +      else if (m.equals(GET_EJB_HOME))
  +      {
            return getEJBHome(invocation);
         }
  -      else if (m.equals(GET_PRIMARY_KEY)) {
  -
  +      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()));
  +      else if (m.equals(IS_IDENTICAL))
  +      {
  +         Object[] args = invocation.getArguments();
  +         String argsString = args[0].toString();
  +         String thisString = toString(ctx);
  +         return new Boolean(thisString.equals(argsString));
         }
  -
         // If not taken care of, go on and call the container
  -      else {
  -         
  +      else
  +      {
            // It is a remote invocation
            invocation.setType(Invocation.REMOTE);
            
  @@ -113,5 +116,10 @@
            
            return getNext().invoke(invocation);
         }
  +   }
  +
  +   private String toString(InvocationContext ctx)
  +   {
  +      return ctx.getValue(JNDI_NAME) + ":" + ctx.getCacheId().toString();
      }
   }
  
  
  
  1.2       +61 -53    
jboss/src/main/org/jboss/proxy/ejb/StatelessSessionInterceptor.java
  
  Index: StatelessSessionInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/proxy/ejb/StatelessSessionInterceptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StatelessSessionInterceptor.java  7 Mar 2002 18:25:52 -0000       1.1
  +++ StatelessSessionInterceptor.java  8 Mar 2002 01:26:55 -0000       1.2
  @@ -1,13 +1,12 @@
   /*
  -* JBoss, the OpenSource J2EE webOS
  -*
  -* Distributable under LGPL license.
  -* See terms of license at gnu.org.
  -*/
  + * 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;
  @@ -16,18 +15,18 @@
   
   
   /**
  -* 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>  
  -*/
  + * An EJB stateless session bean proxy class.
  + *
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  + * @version $Revision: 1.2 $
  + *
  + * <p><b>2001/11/23: marcf</b>
  + * <ol>
  + *   <li>Initial checkin
  + * </ol>
  + */
   public class StatelessSessionInterceptor
  -extends GenericEJBInterceptor
  +   extends GenericEJBInterceptor
   {
      // Constants -----------------------------------------------------
      
  @@ -41,65 +40,72 @@
      // Constructors --------------------------------------------------
      
      /**
  -   * No-argument constructor for externalization.
  -   */
  -   public StatelessSessionInterceptor() {}
  +    * 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.
  -   */
  +    * 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
  +      throws Throwable
      {
  -   
  -      InvocationContext ctx = invocation.getInvocationContext();
  -      
  +      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"));
  +      if (m.equals(TO_STRING))
  +      {
  +         return toString(ctx);
  +      }
  +      else if (m.equals(EQUALS))
  +      {
  +         Object[] args = invocation.getArguments();
  +         String argsString = args[0].toString();
  +         String thisString = toString(ctx);
  +         return new Boolean(thisString.equals(argsString));
         }
  -      else if (m.equals(HASH_CODE)) {
  +      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)) {
  +      else if (m.equals(GET_HANDLE))
  +      {
            return new StatelessHandleImpl((String)ctx.getValue(JNDI_NAME));
         }
  -      else if (m.equals(GET_PRIMARY_KEY)) {
  -         
  +      else if (m.equals(GET_PRIMARY_KEY))
  +      {  
            return ctx.getValue(JNDI_NAME);
         }
  -      else if (m.equals(GET_EJB_HOME)) {
  +      else if (m.equals(GET_EJB_HOME))
  +      {
            return getEJBHome(invocation);
         }
  -      
  -      else if (m.equals(IS_IDENTICAL)) {
  +      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"));
  +         Object[] args = invocation.getArguments();
  +         String argsString = args[0].toString();
  +         String thisString = toString(ctx);
  +         return new Boolean(thisString.equals(argsString));
         }
  -      
         // If not taken care of, go on and call the container
  -      else {
  -      
  +      else
  +      {
            invocation.setType(Invocation.REMOTE);
            
            return getNext().invoke(invocation);
  @@ -111,6 +117,8 @@
      // Protected -----------------------------------------------------
      
      // Private -------------------------------------------------------
  -   
  -   // Inner classes -------------------------------------------------
  -}
  \ No newline at end of file
  +   private String toString(InvocationContext ctx)
  +   {
  +      return ctx.getValue(JNDI_NAME) + ":Stateless";
  +   }   
  +}
  
  
  

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

Reply via email to