KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
20 import java.util.Set JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26 import org.apache.geronimo.gbean.GBeanLifecycle;
27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
28 import org.mortbay.jetty.servlet.FilterMapping;
29 import org.mortbay.jetty.Handler;
30
31 /**
32  * @version $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $
33  */

34 public class JettyFilterMapping extends FilterMapping {
35
36     private final String JavaDoc[] urlPatterns;
37     private final boolean requestDispatch;
38     private final boolean forwardDispatch;
39     private final boolean includeDispatch;
40     private final boolean errorDispatch;
41     private final JettyFilterHolder jettyFilterHolder;
42     private final Collection JavaDoc jettyServletHolders;
43     private final JettyFilterMapping previous;
44     private final JettyServletRegistration jettyServletRegistration;
45
46     //todo use an interface for endpoints.
47
public JettyFilterMapping() {
48         this.urlPatterns = null;
49         this.requestDispatch = false;
50         this.forwardDispatch = false;
51         this.includeDispatch = false;
52         this.errorDispatch = false;
53         this.jettyFilterHolder = null;
54         this.jettyServletHolders = null;
55         this.previous = null;
56         this.jettyServletRegistration = null;
57     }
58
59     public JettyFilterMapping(String JavaDoc[] urlPatterns,
60                               boolean requestDispatch,
61                               boolean forwardDispatch,
62                               boolean includeDispatch,
63                               boolean errorDispatch,
64                               JettyFilterHolder jettyFilterHolder,
65                               Collection JavaDoc jettyServletHolders,
66                               JettyFilterMapping previous,
67                               JettyServletRegistration jettyServletRegistration) {
68        this.urlPatterns = urlPatterns;
69         this.requestDispatch = requestDispatch;
70         this.forwardDispatch = forwardDispatch;
71         this.includeDispatch = includeDispatch;
72         this.errorDispatch = errorDispatch;
73         this.jettyFilterHolder = jettyFilterHolder;
74         this.jettyServletHolders = jettyServletHolders;
75         this.previous = previous;
76         this.jettyServletRegistration = jettyServletRegistration;
77
78         if (jettyServletRegistration != null) {
79             assert jettyServletHolders != null ^ urlPatterns != null;
80
81             String JavaDoc filterName = jettyFilterHolder.getFilterName();
82             int dispatches = 0;
83             if (requestDispatch) {
84                 dispatches |= Handler.REQUEST;
85             }
86             if (forwardDispatch) {
87                 dispatches |= Handler.FORWARD;
88             }
89             if (includeDispatch) {
90                 dispatches |= Handler.INCLUDE;
91             }
92             if (errorDispatch) {
93                 dispatches |= Handler.ERROR;
94             }
95
96
97             setFilterName(filterName);
98             setDispatches(dispatches);
99             setPathSpecs(urlPatterns);
100             if (jettyServletHolders != null) {
101                 String JavaDoc[] servletNames = new String JavaDoc[jettyServletHolders.size()];
102                 int i = 0;
103                 for (Iterator JavaDoc iterator = jettyServletHolders.iterator(); iterator.hasNext();) {
104                     JettyServletHolder jettyServletHolder = (JettyServletHolder) iterator.next();
105                     servletNames[i++] = jettyServletHolder.getServletName();
106                 }
107                 setServletNames(servletNames);
108             }
109
110             (jettyServletRegistration.getServletHandler()).addFilterMapping(this);
111         }
112     }
113
114     public String JavaDoc[] getUrlPatterns() {
115         return urlPatterns;
116     }
117
118     public boolean isRequestDispatch() {
119         return requestDispatch;
120     }
121
122     public boolean isForwardDispatch() {
123         return forwardDispatch;
124     }
125
126     public boolean isIncludeDispatch() {
127         return includeDispatch;
128     }
129
130     public boolean isErrorDispatch() {
131         return errorDispatch;
132     }
133
134     public JettyFilterHolder getFilter() {
135         return jettyFilterHolder;
136     }
137
138     public Collection JavaDoc getServlets() {
139         return jettyServletHolders;
140     }
141
142     public JettyFilterMapping getPrevious() {
143         return previous;
144     }
145
146     public JettyServletRegistration getJettyServletRegistration() {
147         return jettyServletRegistration;
148     }
149
150     public static final GBeanInfo GBEAN_INFO;
151
152     static {
153         GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(JettyFilterMapping.class, NameFactory.URL_WEB_FILTER_MAPPING);
154         infoBuilder.addAttribute("urlPatterns", String JavaDoc[].class, true);
155         infoBuilder.addAttribute("requestDispatch", boolean.class, true);
156         infoBuilder.addAttribute("forwardDispatch", boolean.class, true);
157         infoBuilder.addAttribute("includeDispatch", boolean.class, true);
158         infoBuilder.addAttribute("errorDispatch", boolean.class, true);
159
160         infoBuilder.addReference("Filter", JettyFilterHolder.class, NameFactory.WEB_FILTER);
161         infoBuilder.addReference("Servlets", JettyServletHolder.class, NameFactory.SERVLET);
162         infoBuilder.addReference("Previous", JettyFilterMapping.class, NameFactory.URL_WEB_FILTER_MAPPING);
163         infoBuilder.addReference("JettyServletRegistration", JettyServletRegistration.class, NameFactory.WEB_MODULE);
164
165         infoBuilder.setConstructor(new String JavaDoc[]{"urlPatterns",
166                                                 "requestDispatch",
167                                                 "forwardDispatch",
168                                                 "includeDispatch",
169                                                 "errorDispatch",
170                                                 "Filter",
171                                                 "Servlets",
172                                                 "Previous",
173                                                 "JettyServletRegistration"});
174
175         GBEAN_INFO = infoBuilder.getBeanInfo();
176     }
177
178     public static GBeanInfo getGBeanInfo() {
179         return GBEAN_INFO;
180     }
181 }
182
Popular Tags