1 16 17 package org.springframework.web.servlet.mvc.throwaway; 18 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletResponse ; 21 22 import org.springframework.web.bind.ServletRequestDataBinder; 23 import org.springframework.web.servlet.HandlerAdapter; 24 import org.springframework.web.servlet.ModelAndView; 25 26 37 public class ThrowawayControllerHandlerAdapter implements HandlerAdapter { 38 39 public static final String DEFAULT_COMMAND_NAME = "throwawayController"; 40 41 private String commandName = DEFAULT_COMMAND_NAME; 42 43 44 48 public final void setCommandName(String commandName) { 49 this.commandName = commandName; 50 } 51 52 55 public final String getCommandName() { 56 return this.commandName; 57 } 58 59 60 public boolean supports(Object handler) { 61 return (handler instanceof ThrowawayController); 62 } 63 64 65 71 public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) 72 throws Exception { 73 74 ThrowawayController throwaway = (ThrowawayController) handler; 75 76 ServletRequestDataBinder binder = createBinder(request, throwaway); 77 binder.bind(request); 78 binder.closeNoCatch(); 79 80 return throwaway.execute(); 81 } 82 83 97 protected ServletRequestDataBinder createBinder(HttpServletRequest request, ThrowawayController command) 98 throws Exception { 99 100 ServletRequestDataBinder binder = new ServletRequestDataBinder(command, getCommandName()); 101 initBinder(request, binder); 102 return binder; 103 } 104 105 120 protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) 121 throws Exception { 122 } 123 124 125 128 public long getLastModified(HttpServletRequest request, Object handler) { 129 return -1; 130 } 131 132 } 133 | Popular Tags |