Save This Page
Home » jboss-5.0.0.CR1-src » org » jboss » proxy » ejb » [javadoc | source]
    1   /*
    2   * JBoss, Home of Professional Open Source
    3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
    4   * by the @authors tag. See the copyright.txt in the distribution for a
    5   * full listing of individual contributors.
    6   *
    7   * This is free software; you can redistribute it and/or modify it
    8   * under the terms of the GNU Lesser General Public License as
    9   * published by the Free Software Foundation; either version 2.1 of
   10   * the License, or (at your option) any later version.
   11   *
   12   * This software is distributed in the hope that it will be useful,
   13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   15   * Lesser General Public License for more details.
   16   *
   17   * You should have received a copy of the GNU Lesser General Public
   18   * License along with this software; if not, write to the Free
   19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   21   */
   22   package org.jboss.proxy.ejb;
   23   
   24   import java.lang.reflect.Method;
   25   import java.rmi.RemoteException;
   26   
   27   import org.jboss.invocation.Invocation;
   28   import org.jboss.invocation.InvocationContext;
   29   import org.jboss.invocation.InvocationKey;
   30   import org.jboss.invocation.InvocationType;
   31   import org.jboss.proxy.ejb.handle.StatelessHandleImpl;
   32   
   33   
   34   /**
   35    * An EJB stateless session bean proxy class.
   36    *
   37    * @author <a href="mailto:marc.fleury@jboss.org">Marc Fleury</a>
   38    * @version $Revision: 37459 $
   39    */
   40   public class StatelessSessionInterceptor
   41      extends GenericEJBInterceptor
   42   {
   43      /** Serial Version Identifier. @since 1.4 */
   44      private static final long serialVersionUID = -8807189798153718350L;
   45   
   46      /**
   47       * No-argument constructor for externalization.
   48       */
   49      public StatelessSessionInterceptor()
   50      {}
   51      
   52      
   53      // Public --------------------------------------------------------
   54      
   55      /**
   56       * InvocationHandler implementation.
   57       *
   58       * @throws Throwable    Any exception or error thrown while processing.
   59       */
   60      public Object invoke(Invocation invocation)
   61         throws Throwable
   62      {
   63         InvocationContext ctx = invocation.getInvocationContext();  
   64         Method m = invocation.getMethod();
   65         
   66         // Implement local methods
   67         if (m.equals(TO_STRING))
   68         {
   69            return toString(ctx);
   70         }
   71         else if (m.equals(EQUALS))
   72         {
   73            Object[] args = invocation.getArguments();
   74            String argsString = args[0] != null ? args[0].toString() : "";
   75            String thisString = toString(ctx);
   76            return new Boolean(thisString.equals(argsString));
   77         }
   78         else if (m.equals(HASH_CODE))
   79         {
   80            // We base the stateless hash on the hash of the proxy...
   81            // MF XXX: it could be that we want to return the hash of the name?
   82            return new Integer(this.hashCode());
   83         }
   84         // Implement local EJB calls
   85         else if (m.equals(GET_HANDLE))
   86         {
   87            return new StatelessHandleImpl(
   88                  (String)ctx.getValue(InvocationKey.JNDI_NAME));
   89         }
   90         else if (m.equals(GET_PRIMARY_KEY))
   91         {
   92            throw new RemoteException("Call to getPrimaryKey not allowed on session bean");
   93         }
   94         else if (m.equals(GET_EJB_HOME))
   95         {
   96            return getEJBHome(invocation);
   97         }
   98         else if (m.equals(IS_IDENTICAL))
   99         {
  100            // All stateless beans are identical within a home,
  101            // if the names are equal we are equal
  102            Object[] args = invocation.getArguments();
  103            String argsString = args[0].toString();
  104            String thisString = toString(ctx);
  105            return new Boolean(thisString.equals(argsString));
  106         }
  107         // If not taken care of, go on and call the container
  108         else
  109         {
  110            invocation.setType(InvocationType.REMOTE);
  111            
  112            return getNext().invoke(invocation);
  113         }
  114      }
  115      
  116      // Package protected ---------------------------------------------
  117      
  118      // Protected -----------------------------------------------------
  119      
  120      // Private -------------------------------------------------------
  121      private String toString(InvocationContext ctx)
  122      {
  123         return ctx.getValue(InvocationKey.JNDI_NAME) + ":Stateless";
  124      }   
  125   }

Save This Page
Home » jboss-5.0.0.CR1-src » org » jboss » proxy » ejb » [javadoc | source]