KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > util > handler > TcHandler


1
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the "License"). You may not use this file except
7  * in compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * glassfish/bootstrap/legal/CDDLv1.0.txt or
11  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * HEADER in each file and include the License file at
17  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
18  * add the following below this CDDL HEADER, with the
19  * fields enclosed by brackets "[]" replaced with your
20  * own identifying information: Portions Copyright [yyyy]
21  * [name of copyright owner]
22  *
23  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24  *
25  * Portions Copyright Apache Software Foundation.
26  */

27 package org.apache.tomcat.util.handler;
28
29 import java.io.*;
30 import java.util.*;
31 import java.security.*;
32
33
34 /**
35  * The lowest level component of Jk ( and hopefully Coyote ).
36  *
37  * Try to keep it minimal and flexible - add only if you _have_ to add.
38  *
39  * It is similar in concept and can implement/wrap tomcat3.3 Interceptor, tomcat4.0 Valve,
40  * axis Handler, tomcat3.3 Handler, apache2 Hooks etc.
41  *
42  * Both iterative (Interceptor, Hook ) and recursive ( Valve ) behavior are supported.
43  * Named TcHandler because Handler name is too overloaded.
44  *
45  * The interface allows both stateless and statefull implementations ( like Servlet ).
46  *
47  * @author Costin Manolache
48  */

49 public abstract class TcHandler {
50     public static final int OK=0;
51     public static final int LAST=1;
52     public static final int ERROR=2;
53
54     protected Hashtable attributes=new Hashtable();
55     protected TcHandler next;
56     protected String JavaDoc name;
57     protected int id;
58
59     // -------------------- Configuration --------------------
60

61     /** Set the name of the handler. Will allways be called by
62      * worker env after creating the worker.
63      */

64     public void setName(String JavaDoc s ) {
65         name=s;
66     }
67
68     public String JavaDoc getName() {
69         return name;
70     }
71
72     /** Set the id of the worker. It can be used for faster dispatch.
73      * Must be unique, managed by whoever creates the handlers.
74      */

75     public void setId( int id ) {
76         this.id=id;
77     }
78
79     public int getId() {
80         return id;
81     }
82     
83     /** Catalina-style "recursive" invocation. A handler is required to call
84      * the next handler if set.
85      */

86     public void setNext( TcHandler h ) {
87         next=h;
88     }
89
90
91     /** Base implementation will just save all attributes.
92      * It is higly desirable to override this and allow runtime reconfiguration.
93      * XXX Should I make it abstract and force everyone to override ?
94      */

95     public void setAttribute( String JavaDoc name, Object JavaDoc value ) {
96         attributes.put( name, value );
97     }
98
99     /** Get an attribute. Override to allow runtime query ( attribute can be
100      * anything, including statistics, etc )
101      */

102     public Object JavaDoc getAttribute( String JavaDoc name ) {
103         return attributes.get(name) ;
104     }
105
106     //-------------------- Lifecycle --------------------
107

108     /** Should register the request types it can handle,
109      * same style as apache2.
110      */

111     public void init() throws IOException {
112     }
113
114     /** Clean up and stop the handler. Override if needed.
115      */

116     public void destroy() throws IOException {
117     }
118
119     public void start() throws IOException {
120     }
121
122     public void stop() throws IOException {
123     }
124
125     // -------------------- Action --------------------
126

127     /** The 'hook' method. If a 'next' was set, invoke should call it ( recursive behavior,
128      * similar with valve ).
129      *
130      * The application using the handler can also iterate, using the same semantics with
131      * Interceptor or APR hooks.
132      *
133      * @returns OK, LAST, ERROR Status of the execution, semantic similar with apache
134      */

135     public abstract int invoke(TcHandlerCtx tcCtx) throws IOException;
136
137
138
139 }
140
Popular Tags