Save This Page
Home » jboss-5.0.0.CR1-src » org » jboss » ejb » plugins » [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.ejb.plugins;
   23   
   24   import org.jboss.invocation.Invocation;
   25   import org.jboss.invocation.InvocationType;
   26   
   27   import javax.ejb.TimerHandle;
   28   
   29   /**
   30    * This Interceptor validates the incomming arguments and the return value of the call.
   31    *
   32    * Here is the place where you want to make sure that local object don't pass through
   33    * the remote interface. 
   34    *
   35    * @author Thomas.Diesler@jboss.org
   36    * @version $Revision: 37459 $
   37    */
   38   public class CallValidationInterceptor
   39           extends AbstractInterceptor
   40   {
   41      // Constants -----------------------------------------------------
   42       
   43      // Attributes ----------------------------------------------------
   44   
   45      // Static --------------------------------------------------------
   46   
   47      // Constructors --------------------------------------------------
   48      
   49      // Public --------------------------------------------------------
   50   
   51      // Interceptor implementation --------------------------------------
   52      
   53      public Object invokeHome(final Invocation mi) throws Exception
   54      {
   55         validateArguments(mi);
   56         Object obj = getNext().invokeHome(mi);
   57         return validateReturnValue(mi, obj);
   58      }
   59   
   60      public Object invoke(final Invocation mi) throws Exception
   61      {
   62         validateArguments(mi);
   63         Object obj = getNext().invoke(mi);
   64         return validateReturnValue(mi, obj);
   65      }
   66   
   67      /** Do some validation of the incoming parameters */
   68      protected void validateArguments(Invocation mi)
   69      {
   70         if (mi.getType() == InvocationType.REMOTE)
   71         {
   72            Object[] params = mi.getArguments();
   73            for (int i = 0; i < params.length; i++)
   74            {
   75               Object obj = params[i];
   76               if (obj instanceof TimerHandle)
   77                  throw new IllegalArgumentException("Cannot pass TimerHandle through remote interface");
   78            }
   79         }
   80      }
   81   
   82      /** Do some validation of the return value */
   83      protected Object validateReturnValue(Invocation mi, Object retValue)
   84      {
   85         if (mi.getType() == InvocationType.REMOTE)
   86         {
   87            if (retValue instanceof TimerHandle)
   88               throw new IllegalArgumentException("Cannot return TimerHandle from remote interface");
   89         }
   90         return retValue;
   91      }
   92   
   93   }

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