001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.servlet.mvc;
018
019import javax.servlet.http.HttpServletRequest;
020import javax.servlet.http.HttpServletResponse;
021
022import org.springframework.web.servlet.HandlerAdapter;
023import org.springframework.web.servlet.ModelAndView;
024
025/**
026 * Adapter to use the plain {@link Controller} workflow interface with
027 * the generic {@link org.springframework.web.servlet.DispatcherServlet}.
028 * Supports handlers that implement the {@link LastModified} interface.
029 *
030 * <p>This is an SPI class, not used directly by application code.
031 *
032 * @author Rod Johnson
033 * @author Juergen Hoeller
034 * @see org.springframework.web.servlet.DispatcherServlet
035 * @see Controller
036 * @see LastModified
037 * @see HttpRequestHandlerAdapter
038 */
039public class SimpleControllerHandlerAdapter implements HandlerAdapter {
040
041        @Override
042        public boolean supports(Object handler) {
043                return (handler instanceof Controller);
044        }
045
046        @Override
047        public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
048                        throws Exception {
049
050                return ((Controller) handler).handleRequest(request, response);
051        }
052
053        @Override
054        public long getLastModified(HttpServletRequest request, Object handler) {
055                if (handler instanceof LastModified) {
056                        return ((LastModified) handler).getLastModified(request);
057                }
058                return -1L;
059        }
060
061}