KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > jetty > servlet > FilterHolder


1 // ========================================================================
2
// $Id: FilterHolder.java,v 1.31 2005/04/07 09:15:33 gregwilkins Exp $
3
// Copyright 1996-2004 Mort Bay Consulting Pty. Ltd.
4
// ------------------------------------------------------------------------
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// ========================================================================
15

16 package org.mortbay.jetty.servlet;
17
18 import java.util.Enumeration JavaDoc;
19
20 import javax.servlet.Filter JavaDoc;
21 import javax.servlet.FilterConfig JavaDoc;
22 import javax.servlet.ServletContext JavaDoc;
23
24 import org.mortbay.http.HttpHandler;
25
26 /* --------------------------------------------------------------------- */
27 /**
28  * @version $Id: FilterHolder.java,v 1.31 2005/04/07 09:15:33 gregwilkins Exp $
29  * @author Greg Wilkins
30  */

31 public class FilterHolder
32     extends Holder
33 {
34     /* ------------------------------------------------------------ */
35
36     private transient Filter JavaDoc _filter;
37     private transient Config JavaDoc _config;
38         
39     /* ---------------------------------------------------------------- */
40     /** Constructor for Serialization.
41      */

42     public FilterHolder()
43     {}
44     
45     /* ---------------------------------------------------------------- */
46     public FilterHolder(HttpHandler httpHandler,
47                         String JavaDoc name,
48                         String JavaDoc className)
49     {
50         super(httpHandler,name,className);
51     }
52
53
54     
55
56     /* ------------------------------------------------------------ */
57     public void start()
58         throws Exception JavaDoc
59     {
60         super.start();
61         
62         if (!javax.servlet.Filter JavaDoc.class
63             .isAssignableFrom(_class))
64         {
65             super.stop();
66             throw new IllegalStateException JavaDoc(_class+" is not a javax.servlet.Filter");
67         }
68
69         _filter=(Filter JavaDoc)newInstance();
70         _config=new Config JavaDoc();
71         _filter.init(_config);
72     }
73
74     /* ------------------------------------------------------------ */
75     public void stop()
76     {
77         if (_filter!=null)
78             _filter.destroy();
79         _filter=null;
80         _config=null;
81         super.stop();
82     }
83     
84     /* ------------------------------------------------------------ */
85     public Filter JavaDoc getFilter()
86     {
87         return _filter;
88     }
89
90     /* ------------------------------------------------------------ */
91     public String JavaDoc toString()
92     {
93         return getName();
94     }
95     
96     /* ------------------------------------------------------------ */
97     /* ------------------------------------------------------------ */
98     /* ------------------------------------------------------------ */
99     class Config implements FilterConfig JavaDoc
100     {
101         /* ------------------------------------------------------------ */
102         public String JavaDoc getFilterName()
103         {
104             return FilterHolder.this.getName();
105         }
106
107         /* ------------------------------------------------------------ */
108         public ServletContext JavaDoc getServletContext()
109         {
110             return ((WebApplicationHandler)_httpHandler).getServletContext();
111         }
112         
113         /* -------------------------------------------------------- */
114         public String JavaDoc getInitParameter(String JavaDoc param)
115         {
116             return FilterHolder.this.getInitParameter(param);
117         }
118     
119         /* -------------------------------------------------------- */
120         public Enumeration JavaDoc getInitParameterNames()
121         {
122             return FilterHolder.this.getInitParameterNames();
123         }
124     }
125     
126 }
127
128
129
130
131
132
Popular Tags