Browse Source

Replace ModelAndViewContainer parameter with Object

pull/7/head
Rossen Stoyanchev 14 years ago
parent
commit
ca9a3b4584
  1. 6
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodAdapter.java
  2. 33
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java
  3. 11
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/DefaultMethodReturnValueHandler.java
  4. 8
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/HttpEntityMethodProcessor.java
  5. 13
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/ModelAndViewMethodReturnValueHandler.java
  6. 8
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/RequestResponseBodyMethodProcessor.java
  7. 16
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/ViewMethodReturnValueHandler.java
  8. 10
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterIntegrationTests.java
  9. 10
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterTests.java
  10. 6
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/support/DefaultMethodReturnValueHandlerTests.java
  11. 4
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/support/ViewMethodReturnValueHandlerTests.java
  12. 8
      org.springframework.web/src/main/java/org/springframework/web/method/annotation/support/ModelAttributeMethodProcessor.java
  13. 8
      org.springframework.web/src/main/java/org/springframework/web/method/annotation/support/ModelMethodProcessor.java
  14. 8
      org.springframework.web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandler.java
  15. 8
      org.springframework.web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerContainer.java
  16. 4
      org.springframework.web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java
  17. 10
      org.springframework.web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java
  18. 6
      org.springframework.web/src/test/java/org/springframework/web/method/annotation/support/ModelAttributeMethodProcessorTests.java
  19. 3
      org.springframework.web/src/test/java/org/springframework/web/method/annotation/support/ModelMethodProcessorTests.java
  20. 4
      org.springframework.web/src/test/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerContainerTests.java
  21. 8
      org.springframework.web/src/test/java/org/springframework/web/method/support/StubReturnValueHandler.java

6
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java → org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodAdapter.java

@ -92,7 +92,7 @@ import org.springframework.web.util.WebUtils; @@ -92,7 +92,7 @@ import org.springframework.web.util.WebUtils;
* @author Rossen Stoyanchev
* @since 3.1
*/
public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter implements BeanFactoryAware,
public class RequestMappingHandlerMethodAdapter extends AbstractHandlerMethodAdapter implements BeanFactoryAware,
InitializingBean {
private WebArgumentResolver[] customArgumentResolvers;
@ -127,9 +127,9 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i @@ -127,9 +127,9 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
private final HandlerMethodArgumentResolverContainer binderMethodArgResolvers = new HandlerMethodArgumentResolverContainer();
/**
* Create a {@link RequestMappingHandlerAdapter} instance.
* Create a {@link RequestMappingHandlerMethodAdapter} instance.
*/
public RequestMappingHandlerAdapter() {
public RequestMappingHandlerMethodAdapter() {
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
stringHttpMessageConverter.setWriteAcceptCharset(false); // See SPR-7316

33
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java

@ -19,7 +19,6 @@ package org.springframework.web.servlet.mvc.method.annotation; @@ -19,7 +19,6 @@ package org.springframework.web.servlet.mvc.method.annotation;
import java.io.IOException;
import java.lang.reflect.Method;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpStatus;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
@ -27,11 +26,9 @@ import org.springframework.web.bind.annotation.ResponseStatus; @@ -27,11 +26,9 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodProcessor;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.InvocableHandlerMethod;
import org.springframework.web.method.support.HandlerMethodReturnValueHandlerContainer;
import org.springframework.web.method.support.InvocableHandlerMethod;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.ModelAndView;
@ -95,7 +92,11 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { @@ -95,7 +92,11 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
setResponseStatus((ServletWebRequest) request);
ModelAndViewContainer<View> mavContainer = new ModelAndViewContainer<View>(model);
if (returnValue == null && (isRequestNotModified(request) || usesResponseArgument())) {
return null;
}
ModelAndViewContainer mavContainer = new ModelAndViewContainer(model);
returnValueHandlers.handleReturnValue(returnValue, getReturnType(), mavContainer, request);
return getModelAndView(request, mavContainer, returnValue);
@ -122,36 +123,32 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { @@ -122,36 +123,32 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
* Create a {@link ModelAndView} from a {@link ModelAndViewContainer}.
*/
private ModelAndView getModelAndView(NativeWebRequest request,
ModelAndViewContainer<View> mavContainer,
ModelAndViewContainer mavContainer,
Object returnValue) {
if (returnValue == null && isResponseHandled(request)) {
return null;
}
else if (returnValueHandlerUsesResponseArgument()) {
if (returnValueHandlerUsesResponseArgument()) {
return null;
}
else {
ModelAndView mav = new ModelAndView().addAllObjects(mavContainer.getModel());
mav.setViewName(mavContainer.getViewName());
if (mavContainer.getView() != null) {
mav.setView(mavContainer.getView());
mav.setView((View) mavContainer.getView());
}
return mav;
}
}
private boolean isResponseHandled(NativeWebRequest request) {
/**
* Check whether the request qualifies as not modified...
* TODO: document fully including sample user code
*/
private boolean isRequestNotModified(NativeWebRequest request) {
ServletWebRequest servletRequest = (ServletWebRequest) request;
return (servletRequest.isNotModified() || (responseStatus != null) || usesResponseArgument());
}
/**
* Whether any of the underlying {@link HandlerMethodArgumentResolver}s or
* {@link HandlerMethodReturnValueHandler}s use the response argument.
* @see HandlerMethodProcessor#usesResponseArgument(MethodParameter)
*/
protected boolean usesResponseArgument() {
return (super.usesResponseArgument() || returnValueHandlerUsesResponseArgument());
return (super.usesResponseArgument() || returnValueHandlerUsesResponseArgument() || (responseStatus != null));
}
private boolean returnValueHandlerUsesResponseArgument() {

11
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/DefaultMethodReturnValueHandler.java

@ -55,11 +55,10 @@ public class DefaultMethodReturnValueHandler implements HandlerMethodReturnValue @@ -55,11 +55,10 @@ public class DefaultMethodReturnValueHandler implements HandlerMethodReturnValue
return false;
}
@SuppressWarnings("unchecked")
public <V> void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer<V> mavContainer,
NativeWebRequest webRequest) throws Exception {
public void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
for (ModelAndViewResolver resolver : this.customModelAndViewResolvers) {
Class<?> handlerType = returnType.getDeclaringClass();
@ -67,7 +66,7 @@ public class DefaultMethodReturnValueHandler implements HandlerMethodReturnValue @@ -67,7 +66,7 @@ public class DefaultMethodReturnValueHandler implements HandlerMethodReturnValue
ExtendedModelMap extModel = (ExtendedModelMap) mavContainer.getModel();
ModelAndView mav = resolver.resolveModelAndView(method, handlerType, returnValue, extModel, webRequest);
if (mav != ModelAndViewResolver.UNRESOLVED) {
mavContainer.setView((V) mav.getView());
mavContainer.setView(mav.getView());
mavContainer.setViewName(mav.getViewName());
mavContainer.addModelAttributes(mav.getModel());
return;

8
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/HttpEntityMethodProcessor.java

@ -112,10 +112,10 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro @@ -112,10 +112,10 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
}
public <V> void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer<V> mavContainer,
NativeWebRequest webRequest) throws Exception {
public void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
if (returnValue == null) {
return;
}

13
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/ModelAndViewMethodReturnValueHandler.java

@ -38,15 +38,14 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn @@ -38,15 +38,14 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn
return false;
}
@SuppressWarnings("unchecked")
public <V> void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer<V> mavContainer,
NativeWebRequest webRequest) throws Exception {
public void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
ModelAndView mav = (ModelAndView) returnValue;
mavContainer.setView((V) mav.getView());
mavContainer.setView(mav.getView());
mavContainer.setViewName(mav.getViewName());
mavContainer.addModelAttributes(mav.getModel());
}
}

8
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/RequestResponseBodyMethodProcessor.java

@ -79,10 +79,10 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter @@ -79,10 +79,10 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
return new ServletServerHttpRequest(servletRequest);
}
public <V> void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer<V> mavContainer,
NativeWebRequest webRequest)
public void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest)
throws IOException, HttpMediaTypeNotAcceptableException {
if (returnValue != null) {
writeWithMessageConverters(webRequest, returnValue);

16
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/ViewMethodReturnValueHandler.java

@ -39,17 +39,19 @@ public class ViewMethodReturnValueHandler implements HandlerMethodReturnValueHan @@ -39,17 +39,19 @@ public class ViewMethodReturnValueHandler implements HandlerMethodReturnValueHan
return false;
}
@SuppressWarnings("unchecked")
public <V> void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer<V> mavContainer,
NativeWebRequest webRequest) throws Exception {
public void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
if (returnValue instanceof String) {
mavContainer.setViewName((String) returnValue);
}
else if (returnValue instanceof View){
mavContainer.setView(returnValue);
}
else {
V view = (V) returnValue;
mavContainer.setView(view);
// should not happen
throw new UnsupportedOperationException();
}
}

10
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterIntegrationTests.java

@ -77,12 +77,12 @@ import org.springframework.web.method.HandlerMethod; @@ -77,12 +77,12 @@ import org.springframework.web.method.HandlerMethod;
import org.springframework.web.method.support.InvocableHandlerMethod;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMethodAdapter;
/**
* A test fixture for higher-level {@link RequestMappingHandlerAdapter} tests.
* A test fixture for higher-level {@link RequestMappingHandlerMethodAdapter} tests.
*
* <p>The aim here is not to test {@link RequestMappingHandlerAdapter} itself nor to exercise
* <p>The aim here is not to test {@link RequestMappingHandlerMethodAdapter} itself nor to exercise
* every {@link Controller @Controller} method feature but to have a place to try any feature
* related to {@link Controller @Controller} invocations. Preferably actual tests should be
* added to the components that provide that respective functionality.
@ -98,7 +98,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl @@ -98,7 +98,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
*/
public class RequestMappingHandlerAdapterIntegrationTests {
private RequestMappingHandlerAdapter handlerAdapter;
private RequestMappingHandlerMethodAdapter handlerAdapter;
private MockHttpServletRequest request;
@ -109,7 +109,7 @@ public class RequestMappingHandlerAdapterIntegrationTests { @@ -109,7 +109,7 @@ public class RequestMappingHandlerAdapterIntegrationTests {
ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
bindingInitializer.setValidator(new StubValidator());
this.handlerAdapter = new RequestMappingHandlerAdapter();
this.handlerAdapter = new RequestMappingHandlerMethodAdapter();
this.handlerAdapter.setWebBindingInitializer(bindingInitializer);
this.handlerAdapter.setCustomArgumentResolvers(new WebArgumentResolver[] { new ColorArgumentResolver() });

10
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterTests.java

@ -30,12 +30,12 @@ import org.springframework.web.bind.annotation.SessionAttributes; @@ -30,12 +30,12 @@ import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.method.support.InvocableHandlerMethod;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMethodAdapter;
/**
* Test fixture for {@link RequestMappingHandlerAdapter} unit tests.
* Test fixture for {@link RequestMappingHandlerMethodAdapter} unit tests.
*
* The tests in this class focus on {@link RequestMappingHandlerAdapter} functionality exclusively.
* The tests in this class focus on {@link RequestMappingHandlerMethodAdapter} functionality exclusively.
* Also see {@link RequestMappingHandlerAdapterIntegrationTests} for higher-level tests invoking
* {@link Controller @Controller} methods.
*
@ -43,7 +43,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl @@ -43,7 +43,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
*/
public class RequestMappingHandlerAdapterTests {
private RequestMappingHandlerAdapter handlerAdapter;
private RequestMappingHandlerMethodAdapter handlerAdapter;
private MockHttpServletRequest request;
@ -51,7 +51,7 @@ public class RequestMappingHandlerAdapterTests { @@ -51,7 +51,7 @@ public class RequestMappingHandlerAdapterTests {
@Before
public void setup() throws Exception {
this.handlerAdapter = new RequestMappingHandlerAdapter();
this.handlerAdapter = new RequestMappingHandlerMethodAdapter();
this.handlerAdapter.setApplicationContext(new GenericWebApplicationContext());
this.handlerAdapter.afterPropertiesSet();

6
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/support/DefaultMethodReturnValueHandlerTests.java

@ -28,8 +28,6 @@ import org.springframework.mock.web.MockHttpServletRequest; @@ -28,8 +28,6 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.ui.ExtendedModelMap;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.mvc.method.annotation.support.DefaultMethodReturnValueHandler;
/**
* Test fixture for {@link DefaultMethodReturnValueHandler} unit tests.
@ -42,12 +40,12 @@ public class DefaultMethodReturnValueHandlerTests { @@ -42,12 +40,12 @@ public class DefaultMethodReturnValueHandlerTests {
private ServletWebRequest webRequest;
private ModelAndViewContainer<View> mavContainer;
private ModelAndViewContainer mavContainer;
@Before
public void setUp() {
this.handler = new DefaultMethodReturnValueHandler(null);
this.mavContainer = new ModelAndViewContainer<View>(new ExtendedModelMap());
this.mavContainer = new ModelAndViewContainer(new ExtendedModelMap());
this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
}

4
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/support/ViewMethodReturnValueHandlerTests.java

@ -45,12 +45,12 @@ public class ViewMethodReturnValueHandlerTests { @@ -45,12 +45,12 @@ public class ViewMethodReturnValueHandlerTests {
private ServletWebRequest webRequest;
private ModelAndViewContainer<View> mavContainer;
private ModelAndViewContainer mavContainer;
@Before
public void setUp() {
this.handler = new ViewMethodReturnValueHandler();
this.mavContainer = new ModelAndViewContainer<View>(new ExtendedModelMap());
this.mavContainer = new ModelAndViewContainer(new ExtendedModelMap());
this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
}

8
org.springframework.web/src/main/java/org/springframework/web/method/annotation/support/ModelAttributeMethodProcessor.java

@ -160,10 +160,10 @@ public class ModelAttributeMethodProcessor @@ -160,10 +160,10 @@ public class ModelAttributeMethodProcessor
return returnType.getMethodAnnotation(ModelAttribute.class) != null;
}
public <V> void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer<V> mavContainer,
NativeWebRequest webRequest) throws Exception {
public void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
String name = ModelFactory.getNameForReturnValue(returnValue, returnType);
mavContainer.addModelAttribute(name, returnValue);
}

8
org.springframework.web/src/main/java/org/springframework/web/method/annotation/support/ModelMethodProcessor.java

@ -70,10 +70,10 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand @@ -70,10 +70,10 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public <V> void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer<V> mavContainer,
NativeWebRequest webRequest) throws Exception {
public void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
if (returnValue instanceof Model) {
mavContainer.addModelAttributes((Model) returnValue);
}

8
org.springframework.web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandler.java

@ -46,9 +46,9 @@ public interface HandlerMethodReturnValueHandler extends HandlerMethodProcessor @@ -46,9 +46,9 @@ public interface HandlerMethodReturnValueHandler extends HandlerMethodProcessor
* @param webRequest the current request
* @throws Exception in case of errors
*/
<V> void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer<V> mavContainer,
NativeWebRequest webRequest) throws Exception;
void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception;
}

8
org.springframework.web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerContainer.java

@ -57,10 +57,10 @@ public class HandlerMethodReturnValueHandlerContainer implements HandlerMethodRe @@ -57,10 +57,10 @@ public class HandlerMethodReturnValueHandlerContainer implements HandlerMethodRe
* Handles the given method return value by iterating over registered {@link HandlerMethodReturnValueHandler}s
* to find one that supports it.
*/
public <V> void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer<V> mavContainer,
NativeWebRequest webRequest) throws Exception {
public void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
if (handler != null) {
handler.handleReturnValue(returnValue, returnType, mavContainer, webRequest);

4
org.springframework.web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.web.method.support;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
@ -201,7 +202,8 @@ public class InvocableHandlerMethod extends HandlerMethod { @@ -201,7 +202,8 @@ public class InvocableHandlerMethod extends HandlerMethod {
if (args != null && args.length > 0) {
builder.append(" and argument types ");
for (int i = 0; i < args.length; i++) {
builder.append(" : arg[").append(i).append("] ").append(args[i].getClass());
String argClass = (args[i] != null) ? args[i].getClass().toString() : "null";
builder.append(" : arg[").append(i).append("] ").append(argClass);
}
}
else {

10
org.springframework.web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java

@ -31,14 +31,12 @@ import org.springframework.ui.ModelMap; @@ -31,14 +31,12 @@ import org.springframework.ui.ModelMap;
*
* @author Rossen Stoyanchev
* @since 3.1
*
* @param <V> Servlet or Portlet specific View type.
*/
public class ModelAndViewContainer<V> {
public class ModelAndViewContainer {
private String viewName;
private V view;
private Object view;
private final ModelMap actualModel = new ExtendedModelMap();
@ -60,11 +58,11 @@ public class ModelAndViewContainer<V> { @@ -60,11 +58,11 @@ public class ModelAndViewContainer<V> {
this.viewName = viewName;
}
public V getView() {
public Object getView() {
return this.view;
}
public void setView(V view) {
public void setView(Object view) {
this.view = view;
}

6
org.springframework.web/src/test/java/org/springframework/web/method/annotation/support/ModelAttributeMethodProcessorTests.java

@ -195,20 +195,18 @@ public class ModelAttributeMethodProcessorTests { @@ -195,20 +195,18 @@ public class ModelAttributeMethodProcessorTests {
processor.resolveArgument(notAnnotatedParam, model, webRequest, binderFactory);
}
@SuppressWarnings("rawtypes")
@Test
public void handleAnnotatedReturnValue() throws Exception {
ModelAndViewContainer<?> mavContainer = new ModelAndViewContainer(model);
ModelAndViewContainer mavContainer = new ModelAndViewContainer(model);
processor.handleReturnValue("expected", annotatedReturnParam, mavContainer, webRequest);
assertEquals("expected", mavContainer.getModel().get("modelAttrName"));
}
@SuppressWarnings("rawtypes")
@Test
public void handleNotAnnotatedReturnValue() throws Exception {
TestBean testBean = new TestBean("expected");
ModelAndViewContainer<?> mavContainer = new ModelAndViewContainer(model);
ModelAndViewContainer mavContainer = new ModelAndViewContainer(model);
processor.handleReturnValue(testBean, notAnnotatedReturnParam, mavContainer, webRequest);
assertSame(testBean, mavContainer.getModel().get("testBean"));

3
org.springframework.web/src/test/java/org/springframework/web/method/annotation/support/ModelMethodProcessorTests.java

@ -97,7 +97,6 @@ public class ModelMethodProcessorTests { @@ -97,7 +97,6 @@ public class ModelMethodProcessorTests {
assertSame(model, result);
}
@SuppressWarnings("rawtypes")
@Test
public void handleReturnValue() throws Exception {
ExtendedModelMap implicitModel = new ExtendedModelMap();
@ -106,7 +105,7 @@ public class ModelMethodProcessorTests { @@ -106,7 +105,7 @@ public class ModelMethodProcessorTests {
ExtendedModelMap returnValue = new ExtendedModelMap();
returnValue.put("attr2", "value2");
ModelAndViewContainer<?> mavContainer = new ModelAndViewContainer(implicitModel);
ModelAndViewContainer mavContainer = new ModelAndViewContainer(implicitModel);
resolver.handleReturnValue(returnValue , modelReturnType, mavContainer, webRequest);
ModelMap actualModel = mavContainer.getModel();
assertEquals("value1", actualModel.get("attr1"));

4
org.springframework.web/src/test/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerContainerTests.java

@ -34,7 +34,7 @@ public class HandlerMethodReturnValueHandlerContainerTests { @@ -34,7 +34,7 @@ public class HandlerMethodReturnValueHandlerContainerTests {
private HandlerMethodReturnValueHandlerContainer container;
ModelAndViewContainer<?> mavContainer;
ModelAndViewContainer mavContainer;
private MethodParameter paramInteger;
@ -47,7 +47,7 @@ public class HandlerMethodReturnValueHandlerContainerTests { @@ -47,7 +47,7 @@ public class HandlerMethodReturnValueHandlerContainerTests {
this.paramInteger = new MethodParameter(getClass().getDeclaredMethod("handleInteger"), -1);
this.paramString = new MethodParameter(getClass().getDeclaredMethod("handleString"), -1);
mavContainer = new ModelAndViewContainer<Object>(null);
mavContainer = new ModelAndViewContainer(null);
}
@Test

8
org.springframework.web/src/test/java/org/springframework/web/method/support/StubReturnValueHandler.java

@ -47,10 +47,10 @@ public class StubReturnValueHandler implements HandlerMethodReturnValueHandler { @@ -47,10 +47,10 @@ public class StubReturnValueHandler implements HandlerMethodReturnValueHandler {
return returnType.getParameterType().equals(this.supportedReturnType);
}
public <V> void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer<V> mavContainer,
NativeWebRequest webRequest) throws Exception {
public void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
this.unhandledReturnValue = returnValue;
if (returnValue != null) {
mavContainer.addModelAttribute(Conventions.getVariableName(returnValue), returnValue);

Loading…
Cancel
Save