Home » apache-tomcat-6.0.26-src » org.apache » tomcat » util » handler » [javadoc | source]

    1   
    2   
    3   /*
    4    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    5    * 
    6    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    7    * 
    8    * Portions Copyright Apache Software Foundation.
    9    * 
   10    * The contents of this file are subject to the terms of either the GNU
   11    * General Public License Version 2 only ("GPL") or the Common Development
   12    * and Distribution License("CDDL") (collectively, the "License").  You
   13    * may not use this file except in compliance with the License. You can obtain
   14    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   15    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   16    * language governing permissions and limitations under the License.
   17    * 
   18    * When distributing the software, include this License Header Notice in each
   19    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   20    * Sun designates this particular file as subject to the "Classpath" exception
   21    * as provided by Sun in the GPL Version 2 section of the License file that
   22    * accompanied this code.  If applicable, add the following below the License
   23    * Header, with the fields enclosed by brackets [] replaced by your own
   24    * identifying information: "Portions Copyrighted [year]
   25    * [name of copyright owner]"
   26    * 
   27    * Contributor(s):
   28    * 
   29    * If you wish your version of this file to be governed by only the CDDL or
   30    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   31    * elects to include this software in this distribution under the [CDDL or GPL
   32    * Version 2] license."  If you don't indicate a single choice of license, a
   33    * recipient has the option to distribute your version of this file under
   34    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   35    * its licensees as provided above.  However, if you add GPL Version 2 code
   36    * and therefore, elected the GPL Version 2 license, then the option applies
   37    * only if the new code is made subject to such option by the copyright
   38    * holder.
   39    */
   40   package org.apache.tomcat.util.handler;
   41   
   42   import java.io;
   43   import java.util;
   44   import java.security;
   45   
   46   
   47   /**
   48    * The lowest level component of Jk ( and hopefully Coyote ). 
   49    *
   50    * Try to keep it minimal and flexible - add only if you _have_ to add.
   51    *
   52    * It is similar in concept and can implement/wrap tomcat3.3 Interceptor, tomcat4.0 Valve,
   53    * axis Handler, tomcat3.3 Handler, apache2 Hooks etc.
   54    *
   55    * Both iterative (Interceptor, Hook ) and recursive ( Valve ) behavior are supported.
   56    * Named TcHandler because Handler name is too overloaded.
   57    *
   58    * The interface allows both stateless and statefull implementations ( like Servlet ).
   59    *
   60    * @author Costin Manolache
   61    */
   62   public abstract class TcHandler {
   63       public static final int OK=0;
   64       public static final int LAST=1;
   65       public static final int ERROR=2;
   66   
   67       protected Hashtable attributes=new Hashtable();
   68       protected TcHandler next;
   69       protected String name;
   70       protected int id;
   71   
   72       // -------------------- Configuration --------------------
   73       
   74       /** Set the name of the handler. Will allways be called by
   75        *  worker env after creating the worker.
   76        */
   77       public void setName(String s ) {
   78           name=s;
   79       }
   80   
   81       public String getName() {
   82           return name;
   83       }
   84   
   85       /** Set the id of the worker. It can be used for faster dispatch.
   86        *  Must be unique, managed by whoever creates the handlers.
   87        */
   88       public void setId( int id ) {
   89           this.id=id;
   90       }
   91   
   92       public int getId() {
   93           return id;
   94       }
   95       
   96       /** Catalina-style "recursive" invocation. A handler is required to call
   97        *  the next handler if set.
   98        */
   99       public void setNext( TcHandler h ) {
  100           next=h;
  101       }
  102   
  103   
  104       /** Base implementation will just save all attributes. 
  105        *  It is higly desirable to override this and allow runtime reconfiguration.
  106        *  XXX Should I make it abstract and force everyone to override ?
  107        */
  108       public void setAttribute( String name, Object value ) {
  109           attributes.put( name, value );
  110       }
  111   
  112       /** Get an attribute. Override to allow runtime query ( attribute can be
  113        *  anything, including statistics, etc )
  114        */
  115       public Object getAttribute( String name ) {
  116           return attributes.get(name) ;
  117       }
  118   
  119       //-------------------- Lifecycle --------------------
  120       
  121       /** Should register the request types it can handle,
  122        *   same style as apache2.
  123        */
  124       public void init() throws IOException {
  125       }
  126   
  127       /** Clean up and stop the handler. Override if needed.
  128        */
  129       public void destroy() throws IOException {
  130       }
  131   
  132       public void start() throws IOException {
  133       }
  134   
  135       public void stop() throws IOException {
  136       }
  137   
  138       // -------------------- Action --------------------
  139       
  140       /** The 'hook' method. If a 'next' was set, invoke should call it ( recursive behavior,
  141        *  similar with valve ).
  142        *
  143        * The application using the handler can also iterate, using the same semantics with
  144        * Interceptor or APR hooks.
  145        *
  146        * @returns OK, LAST, ERROR Status of the execution, semantic similar with apache
  147        */
  148       public abstract int invoke(TcHandlerCtx tcCtx)  throws IOException;
  149   
  150   
  151   
  152   }

Home » apache-tomcat-6.0.26-src » org.apache » tomcat » util » handler » [javadoc | source]