01: /*
02: * Copyright 2001-2007 Hippo (www.hippo.nl)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package nl.hippo.util.spring;
17:
18: import java.io.IOException;
19: import javax.servlet.ServletException;
20: import javax.servlet.http.HttpServlet;
21: import javax.servlet.http.HttpServletRequest;
22: import javax.servlet.http.HttpServletResponse;
23: import javax.servlet.ServletContext;
24: import javax.servlet.ServletConfig;
25:
26: public class MultipleXmlContextLoaderServlet extends HttpServlet {
27:
28: private static final long serialVersionUID = -5059231295356265430L;
29:
30: private MultipleXmlContextLoader contextLoader;
31:
32: /**
33: * Initialize the root web application context.
34: */
35: public void init(ServletConfig servletConfig)
36: throws ServletException {
37: super .init(servletConfig);
38: this .contextLoader = createContextLoader(servletConfig
39: .getServletContext());
40: this .contextLoader
41: .initWebApplicationContext(getServletContext());
42: }
43:
44: /**
45: * Create the ContextLoader to use. Can be overridden in subclasses.
46: * @return the new ContextLoader
47: */
48: protected MultipleXmlContextLoader createContextLoader(
49: ServletContext servletContext) {
50: return new MultipleXmlContextLoader(servletContext);
51: }
52:
53: /**
54: * Return the ContextLoader used by this servlet.
55: */
56: public MultipleXmlContextLoader getContextLoader() {
57: return contextLoader;
58: }
59:
60: /**
61: * Close the root web application context.
62: */
63: public void destroy() {
64: this .contextLoader
65: .closeWebApplicationContext(getServletContext());
66: }
67:
68: /**
69: * This should never even be called since no mapping to this servlet should
70: * ever be created in web.xml. That's why a correctly invoked Servlet 2.3
71: * listener is much more appropriate for initialization work ;-)
72: */
73: public void service(HttpServletRequest request,
74: HttpServletResponse response) throws IOException {
75: getServletContext().log(
76: "Attempt to call service method on ContextLoaderServlet as ["
77: + request.getRequestURI() + "] was ignored");
78: response.sendError(HttpServletResponse.SC_BAD_REQUEST);
79: }
80:
81: public String getServletInfo() {
82: return "ContextLoaderServlet for Servlet API 2.2/2.3 "
83: + "(deprecated in favor of ContextLoaderListener for Servlet API 2.4)";
84: }
85:
86: }
|