You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/01/31 05:38:46 UTC

cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/valves InterceptorValve.java ValveBase.java AccessLogValve.java

craigmcc    00/01/30 20:38:46

  Modified:    proposals/catalina/src/share/org/apache/tomcat/core
                        StandardContextValve.java StandardEngineValve.java
                        StandardHostValve.java StandardWrapperValve.java
               proposals/catalina/src/share/org/apache/tomcat/security
                        SecurityValve.java
               proposals/catalina/src/share/org/apache/tomcat/valves
                        AccessLogValve.java
  Added:       proposals/catalina/src/share/org/apache/tomcat/valves
                        InterceptorValve.java ValveBase.java
  Removed:     proposals/catalina/src/share/org/apache/tomcat/core
                        InterceptorValve.java ValveBase.java
  Log:
  Repackage the ValveBase base class into org.apache.tomcat.valves, which
  is a good place to put simple (single-Java-Class) Valve implementations,
  and move InterceptorValve into that package as well.
  
  More complex Valves, like org.apache.tomcat.security.SecurityValve, can
  still live in their own packages, but need to explicitly import the
  ValveBase class to use it (as do the Valves used to implement standard
  request processing behavior for the various Container implementations.
  
  Revision  Changes    Path
  1.2       +4 -3      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContextValve.java
  
  Index: StandardContextValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContextValve.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardContextValve.java	2000/01/24 08:31:31	1.1
  +++ StandardContextValve.java	2000/01/31 04:38:44	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContextValve.java,v 1.1 2000/01/24 08:31:31 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/01/24 08:31:31 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContextValve.java,v 1.2 2000/01/31 04:38:44 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/01/31 04:38:44 $
    *
    * ====================================================================
    *
  @@ -73,6 +73,7 @@
   import org.apache.tomcat.Response;
   import org.apache.tomcat.Wrapper;
   import org.apache.tomcat.util.StringManager;
  +import org.apache.tomcat.valves.ValveBase;
   
   
   /**
  @@ -80,7 +81,7 @@
    * <code>StandardContext</code> container implementation.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/01/24 08:31:31 $
  + * @version $Revision: 1.2 $ $Date: 2000/01/31 04:38:44 $
    */
   
   final class StandardContextValve
  
  
  
  1.2       +4 -3      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardEngineValve.java
  
  Index: StandardEngineValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardEngineValve.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardEngineValve.java	2000/01/24 08:31:31	1.1
  +++ StandardEngineValve.java	2000/01/31 04:38:44	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardEngineValve.java,v 1.1 2000/01/24 08:31:31 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/01/24 08:31:31 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardEngineValve.java,v 1.2 2000/01/31 04:38:44 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/01/31 04:38:44 $
    *
    * ====================================================================
    *
  @@ -73,6 +73,7 @@
   import org.apache.tomcat.Request;
   import org.apache.tomcat.Response;
   import org.apache.tomcat.util.StringManager;
  +import org.apache.tomcat.valves.ValveBase;
   
   
   /**
  @@ -80,7 +81,7 @@
    * <code>StandardEngine</code> container implementation.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/01/24 08:31:31 $
  + * @version $Revision: 1.2 $ $Date: 2000/01/31 04:38:44 $
    */
   
   final class StandardEngineValve
  
  
  
  1.2       +4 -3      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardHostValve.java
  
  Index: StandardHostValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardHostValve.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardHostValve.java	2000/01/24 08:31:31	1.1
  +++ StandardHostValve.java	2000/01/31 04:38:44	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardHostValve.java,v 1.1 2000/01/24 08:31:31 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/01/24 08:31:31 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardHostValve.java,v 1.2 2000/01/31 04:38:44 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/01/31 04:38:44 $
    *
    * ====================================================================
    *
  @@ -73,6 +73,7 @@
   import org.apache.tomcat.Request;
   import org.apache.tomcat.Response;
   import org.apache.tomcat.util.StringManager;
  +import org.apache.tomcat.valves.ValveBase;
   
   
   /**
  @@ -80,7 +81,7 @@
    * <code>StandardHost</code> container implementation.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/01/24 08:31:31 $
  + * @version $Revision: 1.2 $ $Date: 2000/01/31 04:38:44 $
    */
   
   final class StandardHostValve
  
  
  
  1.2       +4 -3      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java
  
  Index: StandardWrapperValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardWrapperValve.java	2000/01/30 06:56:20	1.1
  +++ StandardWrapperValve.java	2000/01/31 04:38:44	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v 1.1 2000/01/30 06:56:20 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/01/30 06:56:20 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v 1.2 2000/01/31 04:38:44 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/01/31 04:38:44 $
    *
    * ====================================================================
    *
  @@ -73,6 +73,7 @@
   import org.apache.tomcat.Response;
   import org.apache.tomcat.Wrapper;
   import org.apache.tomcat.util.StringManager;
  +import org.apache.tomcat.valves.ValveBase;
   
   
   /**
  @@ -80,7 +81,7 @@
    * <code>StandardWrapper</code> container implementation.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/01/30 06:56:20 $
  + * @version $Revision: 1.2 $ $Date: 2000/01/31 04:38:44 $
    */
   
   final class StandardWrapperValve
  
  
  
  1.3       +5 -5      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/SecurityValve.java
  
  Index: SecurityValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/SecurityValve.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SecurityValve.java	2000/01/29 22:59:33	1.2
  +++ SecurityValve.java	2000/01/31 04:38:45	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/SecurityValve.java,v 1.2 2000/01/29 22:59:33 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/01/29 22:59:33 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/SecurityValve.java,v 1.3 2000/01/31 04:38:45 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/01/31 04:38:45 $
    *
    * ====================================================================
    *
  @@ -78,7 +78,6 @@
   import org.apache.tomcat.Request;
   import org.apache.tomcat.Response;
   import org.apache.tomcat.Valve;
  -import org.apache.tomcat.core.ValveBase;
   import org.apache.tomcat.deployment.AuthorizationConstraint;
   import org.apache.tomcat.deployment.LoginConfiguration;
   import org.apache.tomcat.deployment.SecurityConstraint;
  @@ -89,6 +88,7 @@
   import org.apache.tomcat.deployment.WebApplicationDescriptor;
   import org.apache.tomcat.deployment.WebResourceCollection;
   import org.apache.tomcat.util.StringManager;
  +import org.apache.tomcat.valves.ValveBase;
   
   
   /**
  @@ -113,7 +113,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/01/29 22:59:33 $
  + * @version $Revision: 1.3 $ $Date: 2000/01/31 04:38:45 $
    */
   
   
  
  
  
  1.2       +1 -2      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/valves/AccessLogValve.java
  
  Index: AccessLogValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/valves/AccessLogValve.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AccessLogValve.java	2000/01/30 02:32:52	1.1
  +++ AccessLogValve.java	2000/01/31 04:38:45	1.2
  @@ -71,7 +71,6 @@
   import org.apache.tomcat.LifecycleException;
   import org.apache.tomcat.Request;
   import org.apache.tomcat.Response;
  -import org.apache.tomcat.core.ValveBase;
   import org.apache.tomcat.util.StringManager;
   
   
  @@ -115,7 +114,7 @@
    * can be implemented.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/01/30 02:32:52 $
  + * @version $Revision: 1.2 $ $Date: 2000/01/31 04:38:45 $
    */
   
   public final class AccessLogValve
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/valves/InterceptorValve.java
  
  Index: InterceptorValve.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/valves/InterceptorValve.java,v 1.1 2000/01/31 04:38:46 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/01/31 04:38:46 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.tomcat.valves;
  
  
  import java.io.IOException;
  import java.util.Enumeration;
  import java.util.Vector;
  import javax.servlet.ServletException;
  import org.apache.tomcat.Container;
  import org.apache.tomcat.Interceptor;
  import org.apache.tomcat.Lifecycle;
  import org.apache.tomcat.LifecycleException;
  import org.apache.tomcat.Request;
  import org.apache.tomcat.Response;
  import org.apache.tomcat.Valve;
  import org.apache.tomcat.util.StringManager;
  
  
  /**
   * Implementation of a <b>Valve</b> that supports a arbitrary sized stack of
   * <b>Interceptors</b> that are given the opportunity to pre-process and
   * post-process the current request and response.  When <code>invoke()</code>
   * is called, the following actions take place:
   * <ul>
   * <li>The <code>preService()</code> method of each configured Interceptor
   *     is called, until one of them throws an exception or returns
   *     <code>false</code> (indicating that the response has been generated).
   *     The Interceptors are called in the order they were added to this Valve.
   * <li>If no exception was thrown, and no Interceptor returned
   *     <code>false</code>, the next Valve in our pipeline is invoked.
   * <li>For each Interceptor whose <code>preService()</code> was called,
   *     the corresponding <code>postService()</code> method is called.  The
   *     Interceptors are called in reverse of the order they were added to
   *     this Valve.
   * <ul>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/01/31 04:38:46 $
   */
  
  public final class InterceptorValve
      extends ValveBase
      implements Lifecycle {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The descriptive information related to this implementation.
       */
      private static final String info =
  	"org.apache.tomcat.core.InterceptorValve/1.0";
  
  
      /**
       * The set of Interceptors configured for this Valve.
       */
      private Interceptor interceptors[] = new Interceptor[0];
  
  
      /**
       * The StringManager for this package.
       */
      private StringManager sm =
  	StringManager.getManager(Constants.Package);
  
  
      /**
       * Has this component been started yet?
       */
      private boolean started = false;
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return descriptive information about this Valve implementation.
       */
      public String getInfo() {
  
  	return (info);
  
      }
  
  
      //---------------------------------------------------------- Public Methods
  
  
      /**
       * Add a new Interceptor to those associated with this Valve.  The
       * <code>preService()</code> method of this Interceptor will be the
       * last one called prior to processing the request, and its
       * <code>postService()</code> method will be the last one called
       * afterwards.
       *
       * @param interceptor New interceptor to be associated
       *
       * @exception IllegalArgumentException if this Interceptor refuses
       *  to become associated with our associated Container
       */
      public void addInterceptor(Interceptor interceptor) {
  
  	synchronized (interceptors) {
  	    interceptor.setContainer(container);	// May throw IAE
  	    Interceptor temp[] = new Interceptor[interceptors.length + 1];
  	    for (int i = 0; i < interceptors.length; i++)
  		temp[i] = interceptors[i];
  	    temp[interceptors.length] = interceptor;
  	    interceptors = temp;
  	}
  
      }
  
  
      /**
       * Return the set of Interceptors associated with this Valve.
       */
      public Interceptor[] findInterceptors() {
  
  	synchronized (interceptors) {
  	    Interceptor results[] = new Interceptor[interceptors.length];
  	    for (int i = 0; i < interceptors.length; i++)
  		results[i] = interceptors[i];
  	    return (results);
  	}
  
      }
  
  
      /**
       * Invoke the <code>preService()</code> of all associated Interceptors,
       * then invoke the next Valve in our pipeline, and finally call the
       * <code>postService()</code> method of all associated Interceptors.
       * This processing schedule will be interrupted if an Interceptor
       * returns <code>false</code> (indicating that it has completely
       * generated the response), or if it throws an exception.  In all cases,
       * the <code>postService()</code> method is guaranteed to be called for
       * every Interceptor whose <code>preService()</code> method was called
       * for this request.
       *
       * @param request The servlet request to be processed
       * @param response The servlet response to be created
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet error occurs
       */
      public void invoke(Request request, Response response)
  	throws IOException, ServletException {
  
  	// Acquire a private copy of the current Interceptor list
  	// IMPLEMENTATION NOTE:  Not required if configuration can only
  	// occur at startup time
  	Interceptor list[] = findInterceptors();
  
  	// Call the preService() method of all defined Interceptors
  	boolean done = false;
  	int last = -1;
  	Throwable t = null;
  	for (int i = 0; i < list.length; i++) {
  	    last = i;
  	    try {
  		if (!list[i].preService(request, response))
  		    done = true;
  	    } catch (Throwable e) {
  		if ((e instanceof IOException) ||
  		    (e instanceof ServletException))
  		    t = e;
  		done = true;
  	    }
  	    if (done)
  		break;
  	}
  
  	// Invoke the next Valve in our pipeline, if any
  	if (getNext() != null) {
  	    try {
  		getNext().invoke(request, response);
  	    } catch (Throwable e) {
  		if ((e instanceof IOException) ||
  		    (e instanceof ServletException))
  		    t = e;
  	    }
  	}
  
  	// Call the postService() methods of all Interceptors for which
  	// we called the preService method
  	if (last < 0)
  	    return;
  	for (int i = last; i >= 0; i--) {
  	    list[i].postService(request, response, t);
  	}
  
      }
  
  
      /**
       * Remove this Interceptor from those associated with this Valve.  If
       * no such association exists, no action is taken.
       *
       * @param interceptor Interceptor to be removed
       */
      public void removeInterceptor(Interceptor interceptor) {
  
  	synchronized (interceptors) {
  	    boolean found = false;
  	    Interceptor temp[] = new Interceptor[interceptors.length - 1];
  	    for (int i = 0; i < interceptors.length; i++) {
  		if (!found) {
  		    if (interceptors[i] == interceptor) {
  			found = true;
  			try {
  			    interceptor.setContainer(null);
  			} catch (IllegalArgumentException e) {
  			    ;
  			}
  			continue;
  		    }
  		}
  		if (!found)
  		    temp[i] = interceptors[i];
  		else
  		    temp[i-1] = interceptors[i];
  	    }
  	    if (found)
  		interceptors = temp;
  	}
  
      }
  
  
      // ------------------------------------------------------ Lifecycle Methods
  
  
      /**
       * Prepare for the beginning of active use of the public methods of this
       * component.  This method should be called after <code>configure()</code>,
       * and before any of the public methods of the component are utilized.
       *
       * @exception IllegalStateException if this component has already been
       *  started
       * @exception LifecycleException if this component detects a fatal error
       *  that prevents this component from being used
       */
      public void start() throws LifecycleException {
  
  	// Validate and update our current component state
  	if (started)
  	    throw new LifecycleException
  		(sm.getString("interceptorValve.alreadyStarted"));
  	started = true;
  
  	// Start our subordinate Interceptors
  	synchronized (interceptors) {
  	    for (int i = 0; i < interceptors.length; i++) {
  		if (interceptors[i] instanceof Lifecycle)
  		    ((Lifecycle) interceptors[i]).start();
  	    }
  	}
  
      }
  
  
      /**
       * Gracefully terminate the active use of the public methods of this
       * component.  This method should be the last one called on a given
       * instance of this component.
       *
       * @exception IllegalStateException if this component has not been started
       * @exception LifecycleException if this component detects a fatal error
       *  that needs to be reported
       */
      public void stop() throws LifecycleException {
  
  	// Validate and update our current state
  	if (!started)
  	    throw new LifecycleException
  		(sm.getString("interceptorValve.notStarted"));
  	started = false;
  
  	// Stop our subordinate Interceptors
  	synchronized (interceptors) {
  	    for (int i = interceptors.length - 1; i >= 0; i--) {
  		if (interceptors[i] instanceof Lifecycle)
  		    ((Lifecycle) interceptors[i]).stop();
  	    }
  	}
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/valves/ValveBase.java
  
  Index: ValveBase.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/valves/ValveBase.java,v 1.1 2000/01/31 04:38:46 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/01/31 04:38:46 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.tomcat.valves;
  
  
  import java.io.IOException;
  import javax.servlet.ServletException;
  import org.apache.tomcat.Container;
  import org.apache.tomcat.Request;
  import org.apache.tomcat.Response;
  import org.apache.tomcat.Valve;
  
  
  /**
   * Convenience base class for implementations of the <b>Valve</b> interface.
   * A subclass <strong>MUST</strong> implement an <code>invoke()</code>
   * method to provide the required functionality, and <strong>MAY</strong>
   * implement the <code>Lifecycle</code> interface to provide configuration
   * management and lifecycle support.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/01/31 04:38:46 $
   */
  
  public abstract class ValveBase
      implements Valve {
  
  
      //------------------------------------------------------ Instance Variables
  
  
      /**
       * The Container whose pipeline this Valve is a component of.
       */
      protected Container container = null;
  
  
      /**
       * Descriptive information about this Valve implementation.  This value
       * should be overridden by subclasses.
       */
      protected static String info =
  	"org.apache.tomcat.core.ValveBase/1.0";
  
  
      /**
       * The next Valve in the pipeline this Valve is a component of.
       */
      protected Valve next = null;
  
  
      /**
       * The previous Valve in the pipeline this Valve is a component of.
       */
      protected Valve previous = null;
  
  
      //-------------------------------------------------------------- Properties
  
  
      /**
       * Return the Container with which this Valve is associated, if any.
       */
      public Container getContainer() {
  
  	return (container);
  
      }
  
  
      /**
       * Set the Container with which this Valve is associated, if any.
       *
       * @param container The new associated container
       */
      public void setContainer(Container container) {
  
  	this.container = container;
  
      }
  
  
      /**
       * Return descriptive information about this Valve implementation.
       */
      public String getInfo() {
  
  	return (info);
  
      }
  
  
      /**
       * Return the next Valve in this pipeline, or <code>null</code> if this
       * is the last Valve in the pipeline.
       */
      public Valve getNext() {
  
  	return (next);
  
      }
  
  
      /**
       * Set the Valve that follows this one in the pipeline it is part of.
       *
       * @param valve The new next valve
       */
      public void setNext(Valve valve) {
  
  	this.next = valve;
  
      }
  
  
      /**
       * Return the previous Valve in this pipeline, or <code>null</code> if
       * this is the first Valve in the pipeline.
       */
      public Valve getPrevious() {
  
  	return (previous);
  
      }
  
  
      /**
       * Set the Valve that preceeds this one in the pipeline it is part of.
       *
       * @param valve The previous valve
       */
      public void setPrevious(Valve valve) {
  
  	this.previous = valve;
  
      }
  
  
      //---------------------------------------------------------- Public Methods
  
  
      /**
       * The implementation-specific logic represented by this Valve.  See the
       * Valve description for the normal design patterns for this method.
       * <p>
       * This method <strong>MUST</strong> be provided by a subclass.
       *
       * @param request The servlet request to be processed
       * @param response The servlet response to be created
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet error occurs
       */
      public abstract void invoke(Request request, Response response)
  	throws IOException, ServletException;
  
  
  }