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   
   25   import org.jboss.ejb.Container;
   26   import org.jboss.ejb.Interceptor;
   27   import org.jboss.invocation.Invocation;
   28   import org.jboss.logging.Logger;
   29   
   30   import java.lang.reflect.Method;
   31   
   32   /**
   33    * An abstract base class for container interceptors.
   34    *
   35    * @author <a href="mailto:rickard.oberg@telkel.com">Rickard Oberg</a>
   36    * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
   37    * @author Scott.Stark@jboss.org
   38    * @version $Revision: 66439 $
   39    */
   40   public abstract class AbstractInterceptor
   41         implements Interceptor
   42   {
   43      // Constants -----------------------------------------------------
   44   
   45      // Attributes ----------------------------------------------------
   46   
   47      /** The next interceptor in the chain. */
   48      protected Interceptor nextInterceptor;
   49      /** Logging instance */
   50      protected Logger log = Logger.getLogger(this.getClass());
   51      /** The container the interceptor is associated with */
   52      protected Container container;
   53   
   54      // Static --------------------------------------------------------
   55   
   56      // Constructors --------------------------------------------------
   57   
   58      // Public --------------------------------------------------------
   59   
   60      // Interceptor implementation ------------------------------------
   61   
   62      public void setContainer(Container container)
   63      {
   64         this.container = container;
   65      }
   66   
   67      public Container getContainer()
   68      {
   69         return container;
   70      }
   71   
   72      public void setNext(final Interceptor interceptor)
   73      {
   74         // assert interceptor != null
   75         nextInterceptor = interceptor;
   76      }
   77   
   78      public Interceptor getNext()
   79      {
   80         return nextInterceptor;
   81      }
   82   
   83      public void create() throws Exception
   84      {
   85         // empty
   86      }
   87   
   88      public void start() throws Exception
   89      {
   90         // empty
   91      }
   92   
   93      public void stop()
   94      {
   95         // empty
   96      }
   97   
   98      public void destroy()
   99      {
  100         // empty
  101      }
  102   
  103      public Object invokeHome(final Invocation mi) throws Exception
  104      {
  105         // assert mi != null;
  106         return getNext().invokeHome(mi);
  107      }
  108   
  109      public Object invoke(final Invocation mi) throws Exception
  110      {
  111         // assert mi != null;
  112         return getNext().invoke(mi);
  113      }
  114   
  115      /**
  116       See if the given exception e is compatible with an exception declared
  117       as thrown by the invocation method.
  118   
  119       @param invocation - the current invocation
  120       @param e - the exception thrown by the invocation
  121       @return true if e is a declared exception, false otherwise
  122       */
  123      public boolean isAppException(Invocation invocation, Throwable e)
  124      {
  125         Method m = invocation.getMethod();
  126         Class[] exceptions = m.getExceptionTypes();
  127         boolean isAppException = false;
  128         for(int n = 0; isAppException == false && n < exceptions.length; n ++)
  129         {
  130            Class exType = exceptions[n];
  131            isAppException = exType.isInstance(e);
  132         }
  133         return isAppException;
  134      }
  135   
  136      // Protected -----------------------------------------------------
  137   }

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