KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > handler > SimpleServletHandlerAdapter


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
17 package org.springframework.web.servlet.handler;
18
19 import javax.servlet.Servlet JavaDoc;
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22
23 import org.springframework.web.servlet.HandlerAdapter;
24 import org.springframework.web.servlet.ModelAndView;
25
26 /**
27  * Adapter to use the Servlet interface with the generic DispatcherServlet.
28  * Calls the Servlet's <code>service</code> method to handle a request.
29  *
30  * <p>Last-modified checking is not explicitly supported: This is typically
31  * handled by the Servlet implementation itself (usually deriving from
32  * the HttpServlet base class).
33  *
34  * <p>This adapter is not activated by default; it needs to be defined as a
35  * bean in the DispatcherServlet context. It will automatically apply to
36  * mapped handler beans that implement the Servlet interface then.
37  *
38  * <p>Note that Servlet instances defined as bean will not receive initialization
39  * and destruction callbacks, unless a special post-processor such as
40  * SimpleServletPostProcessor is defined in the DispatcherServlet context.
41  *
42  * <p><b>Alternatively, consider wrapping a Servlet with Spring's
43  * ServletWrappingController.</b> This is particularly appropriate for
44  * existing Servlet classes, allowing to specify Servlet initialization
45  * parameters etc.
46  *
47  * @author Juergen Hoeller
48  * @since 1.1.5
49  * @see javax.servlet.Servlet
50  * @see javax.servlet.http.HttpServlet
51  * @see SimpleServletPostProcessor
52  * @see org.springframework.web.servlet.mvc.ServletWrappingController
53  */

54 public class SimpleServletHandlerAdapter implements HandlerAdapter {
55
56     public boolean supports(Object JavaDoc handler) {
57         return (handler instanceof Servlet JavaDoc);
58     }
59
60     public ModelAndView handle(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Object JavaDoc handler)
61             throws Exception JavaDoc {
62         
63         ((Servlet JavaDoc) handler).service(request, response);
64         return null;
65     }
66
67     public long getLastModified(HttpServletRequest JavaDoc request, Object JavaDoc handler) {
68         return -1;
69     }
70
71 }
72
Popular Tags