01: /*
02: * Copyright 2002-2007 the original author or authors.
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:
17: package org.springframework.web.servlet.mvc;
18:
19: import javax.servlet.http.HttpServletRequest;
20: import javax.servlet.http.HttpServletResponse;
21:
22: import org.springframework.web.HttpRequestHandler;
23: import org.springframework.web.servlet.HandlerAdapter;
24: import org.springframework.web.servlet.ModelAndView;
25:
26: /**
27: * Adapter to use the plain {@link org.springframework.web.HttpRequestHandler}
28: * interface with the generic {@link org.springframework.web.servlet.DispatcherServlet}.
29: * Supports handlers that implement the {@link LastModified} interface.
30: *
31: * <p>This is an SPI class, not used directly by application code.
32: *
33: * @author Juergen Hoeller
34: * @since 2.0
35: * @see org.springframework.web.servlet.DispatcherServlet
36: * @see org.springframework.web.HttpRequestHandler
37: * @see LastModified
38: * @see SimpleControllerHandlerAdapter
39: */
40: public class HttpRequestHandlerAdapter implements HandlerAdapter {
41:
42: public boolean supports(Object handler) {
43: return (handler instanceof HttpRequestHandler);
44: }
45:
46: public ModelAndView handle(HttpServletRequest request,
47: HttpServletResponse response, Object handler)
48: throws Exception {
49:
50: ((HttpRequestHandler) handler).handleRequest(request, response);
51: return null;
52: }
53:
54: public long getLastModified(HttpServletRequest request,
55: Object handler) {
56: if (handler instanceof LastModified) {
57: return ((LastModified) handler).getLastModified(request);
58: }
59: return -1L;
60: }
61:
62: }
|