KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty6 > JettyFilterHolder


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.jetty6;
18
19 import java.util.Map JavaDoc;
20
21 import org.apache.geronimo.gbean.GBeanInfo;
22 import org.apache.geronimo.gbean.GBeanInfoBuilder;
23 import org.apache.geronimo.gbean.GBeanLifecycle;
24 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
25 import org.mortbay.jetty.servlet.FilterHolder;
26
27 /**
28  * @version $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $
29  */

30 public class JettyFilterHolder implements GBeanLifecycle {
31
32     private final FilterHolder filterHolder;
33
34     //todo consider an interface instead of this constructor for endpoint use.
35
public JettyFilterHolder() {
36         filterHolder = null;
37     }
38
39     public JettyFilterHolder(String JavaDoc filterName, String JavaDoc filterClass, Map JavaDoc initParams, JettyServletRegistration jettyServletRegistration) throws Exception JavaDoc {
40         filterHolder = new FilterHolder();
41         if (jettyServletRegistration != null) {
42             filterHolder.setName(filterName);
43             filterHolder.setClassName(filterClass);
44             filterHolder.setInitParameters(initParams);
45             (jettyServletRegistration.getServletHandler()).addFilter(filterHolder);
46
47 // ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
48
// try {
49
// ClassLoader newCL = jettyServletRegistration.getWebClassLoader();
50
// Thread.currentThread().setContextClassLoader(newCL);
51
// start();
52
// } finally {
53
// Thread.currentThread().setContextClassLoader(oldCL);
54
// }
55
}
56     }
57
58     public String JavaDoc getFilterName() {
59         return filterHolder.getName();
60     }
61
62     public void doStart() throws Exception JavaDoc {
63             filterHolder.start();
64     }
65
66     public void doStop() throws Exception JavaDoc {
67                 filterHolder.stop();
68     }
69
70     public void doFail() {
71         try {
72             filterHolder.stop();
73         } catch (Exception JavaDoc e) {
74             //ignore?
75
}
76     }
77     
78     public static final GBeanInfo GBEAN_INFO;
79
80     static {
81         GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(JettyFilterHolder.class, NameFactory.WEB_FILTER);
82         infoBuilder.addAttribute("filterName", String JavaDoc.class, true);
83         infoBuilder.addAttribute("filterClass", String JavaDoc.class, true);
84         infoBuilder.addAttribute("initParams", Map JavaDoc.class, true);
85
86         infoBuilder.addReference("JettyServletRegistration", JettyServletRegistration.class, NameFactory.WEB_MODULE);
87
88         infoBuilder.setConstructor(new String JavaDoc[] {"filterName", "filterClass", "initParams", "JettyServletRegistration"});
89
90         GBEAN_INFO = infoBuilder.getBeanInfo();
91
92     }
93
94     public static GBeanInfo getGBeanInfo() {
95         return GBEAN_INFO;
96     }
97
98 }
99
Popular Tags