KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
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  *
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.jetty;
18
19 import java.io.Serializable JavaDoc;
20
21 import org.apache.geronimo.gbean.GBeanInfo;
22 import org.apache.geronimo.gbean.GBeanInfoBuilder;
23 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
24 import org.mortbay.jetty.servlet.Dispatcher;
25 import org.mortbay.jetty.servlet.WebApplicationHandler;
26
27 /**
28  * @version $Rev: $ $Date: $
29  */

30 public class JettyFilterMapping implements Serializable JavaDoc {
31
32     private final String JavaDoc urlPattern;
33     private final boolean requestDispatch;
34     private final boolean forwardDispatch;
35     private final boolean includeDispatch;
36     private final boolean errorDispatch;
37     private final JettyFilterHolder jettyFilterHolder;
38     private final JettyServletHolder jettyServletHolder;
39     private final JettyFilterMapping previous;
40     private final JettyServletRegistration jettyServletRegistration;
41
42     //todo use an interface for endpoints.
43
public JettyFilterMapping() {
44         this.urlPattern = null;
45         this.requestDispatch = false;
46         this.forwardDispatch = false;
47         this.includeDispatch = false;
48         this.errorDispatch = false;
49         this.jettyFilterHolder = null;
50         this.jettyServletHolder = null;
51         this.previous = null;
52         this.jettyServletRegistration = null;
53     }
54
55     public JettyFilterMapping(String JavaDoc urlPattern,
56                               boolean requestDispatch,
57                               boolean forwardDispatch,
58                               boolean includeDispatch,
59                               boolean errorDispatch,
60                               JettyFilterHolder jettyFilterHolder,
61                               JettyServletHolder jettyServletHolder,
62                               JettyFilterMapping previous,
63                               JettyServletRegistration jettyServletRegistration) {
64        this.urlPattern = urlPattern;
65         this.requestDispatch = requestDispatch;
66         this.forwardDispatch = forwardDispatch;
67         this.includeDispatch = includeDispatch;
68         this.errorDispatch = errorDispatch;
69         this.jettyFilterHolder = jettyFilterHolder;
70         this.jettyServletHolder = jettyServletHolder;
71         this.previous = previous;
72         this.jettyServletRegistration = jettyServletRegistration;
73
74         if (jettyServletRegistration != null) {
75             assert jettyServletHolder != null ^ urlPattern != null;
76
77             String JavaDoc filterName = jettyFilterHolder.getFilterName();
78             int dispatches = 0;
79             if (requestDispatch) {
80                 dispatches |= Dispatcher.__REQUEST;
81             }
82             if (forwardDispatch) {
83                 dispatches |= Dispatcher.__FORWARD;
84             }
85             if (includeDispatch) {
86                 dispatches |= Dispatcher.__INCLUDE;
87             }
88             if (errorDispatch) {
89                 dispatches |= Dispatcher.__ERROR;
90             }
91
92
93             if (jettyServletHolder == null) {
94                 ((WebApplicationHandler)jettyServletRegistration.getServletHandler()).addFilterPathMapping(urlPattern, filterName, dispatches);
95             } else {
96                 String JavaDoc servletName = jettyServletHolder.getServletName();
97                 ((WebApplicationHandler)jettyServletRegistration.getServletHandler()).addFilterServletMapping(servletName, filterName, dispatches);
98             }
99         }
100     }
101
102     public String JavaDoc getUrlPattern() {
103         return urlPattern;
104     }
105
106     public boolean isRequestDispatch() {
107         return requestDispatch;
108     }
109
110     public boolean isForwardDispatch() {
111         return forwardDispatch;
112     }
113
114     public boolean isIncludeDispatch() {
115         return includeDispatch;
116     }
117
118     public boolean isErrorDispatch() {
119         return errorDispatch;
120     }
121
122     public JettyFilterHolder getFilter() {
123         return jettyFilterHolder;
124     }
125
126     public JettyServletHolder getServlet() {
127         return jettyServletHolder;
128     }
129
130     public JettyFilterMapping getPrevious() {
131         return previous;
132     }
133
134     public JettyServletRegistration getJettyServletRegistration() {
135         return jettyServletRegistration;
136     }
137
138     public static final GBeanInfo GBEAN_INFO;
139
140     static {
141         GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(JettyFilterMapping.class, NameFactory.WEB_FILTER_MAPPING);
142         infoBuilder.addAttribute("urlPattern", String JavaDoc.class, true);
143         infoBuilder.addAttribute("requestDispatch", boolean.class, true);
144         infoBuilder.addAttribute("forwardDispatch", boolean.class, true);
145         infoBuilder.addAttribute("includeDispatch", boolean.class, true);
146         infoBuilder.addAttribute("errorDispatch", boolean.class, true);
147
148         infoBuilder.addReference("Filter", JettyFilterHolder.class, NameFactory.WEB_FILTER);
149         infoBuilder.addReference("Servlet", JettyServletHolder.class, NameFactory.SERVLET);
150         infoBuilder.addReference("Previous", JettyFilterMapping.class, NameFactory.WEB_FILTER_MAPPING);
151         infoBuilder.addReference("JettyServletRegistration", JettyServletRegistration.class, NameFactory.WEB_MODULE);
152
153         infoBuilder.setConstructor(new String JavaDoc[]{"urlPattern",
154                                                 "requestDispatch",
155                                                 "forwardDispatch",
156                                                 "includeDispatch",
157                                                 "errorDispatch",
158                                                 "Filter",
159                                                 "Servlet",
160                                                 "Previous",
161                                                 "JettyServletRegistration"});
162
163         GBEAN_INFO = infoBuilder.getBeanInfo();
164     }
165
166     public static GBeanInfo getGBeanInfo() {
167         return GBEAN_INFO;
168     }
169 }
170
Popular Tags