提交 f36e8252 编写于 作者: J Juergen Hoeller

polishing

上级 f72769a6
......@@ -22,7 +22,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -72,7 +71,8 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
private final Map<String, Object> handlerMap = new LinkedHashMap<String, Object>();
private MappedInterceptors mappedInterceptors;
/**
* Set if URL lookup should always use the full path within the current servlet
* context. Else, the path within the current servlet mapping is used if applicable
......@@ -164,10 +164,11 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
@Override
protected void initInterceptors() {
super.initInterceptors();
Map<String, MappedInterceptor> mappedInterceptors = BeanFactoryUtils.beansOfTypeIncludingAncestors(getApplicationContext(), MappedInterceptor.class, true, false);
Map<String, MappedInterceptor> mappedInterceptors = BeanFactoryUtils.beansOfTypeIncludingAncestors(
getApplicationContext(), MappedInterceptor.class, true, false);
if (!mappedInterceptors.isEmpty()) {
this.mappedInterceptors = new MappedInterceptors(mappedInterceptors.values().toArray(new MappedInterceptor[mappedInterceptors.size()]));
this.mappedInterceptors = new MappedInterceptors(mappedInterceptors.values().toArray(
new MappedInterceptor[mappedInterceptors.size()]));
}
}
......@@ -201,8 +202,9 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
handler = buildPathExposingHandler(rawHandler, lookupPath, lookupPath, null);
}
}
if (handler != null & this.mappedInterceptors != null) {
Set<HandlerInterceptor> mappedInterceptors = this.mappedInterceptors.getInterceptors(lookupPath, this.pathMatcher);
if (handler != null && this.mappedInterceptors != null) {
Set<HandlerInterceptor> mappedInterceptors =
this.mappedInterceptors.getInterceptors(lookupPath, this.pathMatcher);
if (!mappedInterceptors.isEmpty()) {
HandlerExecutionChain chain;
if (handler instanceof HandlerExecutionChain) {
......@@ -435,6 +437,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
}
}
/**
* Special interceptor for exposing the
* {@link AbstractUrlHandlerMapping#URI_TEMPLATE_VARIABLES_ATTRIBUTE} attribute.
......
......@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.servlet.handler;
import org.springframework.web.context.request.WebRequestInterceptor;
......@@ -20,6 +21,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
/**
* Holds information about a HandlerInterceptor mapped to a path into the application.
*
* @author Keith Donald
* @since 3.0
*/
......@@ -29,9 +31,10 @@ public final class MappedInterceptor {
private final HandlerInterceptor interceptor;
/**
* Creates a new mapped interceptor.
* @param pathPattern the path pattern
* Create a new mapped interceptor.
* @param pathPatterns the path patterns
* @param interceptor the interceptor
*/
public MappedInterceptor(String[] pathPatterns, HandlerInterceptor interceptor) {
......@@ -40,8 +43,8 @@ public final class MappedInterceptor {
}
/**
* Creates a new mapped interceptor.
* @param pathPattern the path pattern
* Create a new mapped interceptor.
* @param pathPatterns the path patterns
* @param interceptor the interceptor
*/
public MappedInterceptor(String[] pathPatterns, WebRequestInterceptor interceptor) {
......@@ -49,18 +52,19 @@ public final class MappedInterceptor {
this.interceptor = new WebRequestHandlerInterceptorAdapter(interceptor);
}
/**
* The path into the application the interceptor is mapped to.
*/
public String[] getPathPatterns() {
return pathPatterns;
return this.pathPatterns;
}
/**
* The actual Interceptor reference.
*/
public HandlerInterceptor getInterceptor() {
return interceptor;
return this.interceptor;
}
}
\ No newline at end of file
}
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,7 +17,6 @@
package org.springframework.web.servlet.tags.form;
import java.beans.PropertyEditor;
import javax.servlet.jsp.JspException;
/**
......@@ -52,7 +51,7 @@ public abstract class AbstractCheckedElementTag extends AbstractHtmlInputElement
tagWriter.writeAttribute("checked", "checked");
}
}
/**
* Determines whether the supplied value matched the selected value
* through delegating to {@link SelectedValueComparator#isSelected}.
......@@ -68,7 +67,7 @@ public abstract class AbstractCheckedElementTag extends AbstractHtmlInputElement
*/
protected void renderFromBoolean(Boolean boundValue, TagWriter tagWriter) throws JspException {
tagWriter.writeAttribute("value", "true");
if (boundValue.booleanValue()) {
if (boundValue) {
tagWriter.writeAttribute("checked", "checked");
}
}
......
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -19,7 +19,6 @@ package org.springframework.web.servlet.tags.form;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.jsp.JspException;
import org.springframework.beans.BeanWrapper;
......@@ -103,13 +102,17 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem
this.itemValue = itemValue;
}
/**
* Get the name of the property mapped to the '<code>value</code>' attribute
* of the '<code>input type="checkbox/radio"</code>' tag.
*/
protected String getItemValue() {
return this.itemValue;
}
/**
* Set the value to be displayed as part
* of the '<code>input type="checkbox/radio"</code>' tag.
* Set the value to be displayed as part of the
* '<code>input type="checkbox/radio"</code>' tag.
* <p>May be a runtime expression.
*/
public void setItemLabel(String itemLabel) {
......@@ -118,8 +121,8 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem
}
/**
* Get the value to be displayed as part
* of the '<code>input type="checkbox/radio"</code>' tag.
* Get the value to be displayed as part of the
* '<code>input type="checkbox/radio"</code>' tag.
*/
protected String getItemLabel() {
return this.itemLabel;
......@@ -183,7 +186,7 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem
@Override
protected int writeTagContent(TagWriter tagWriter) throws JspException {
Object items = getItems();
Object itemsObject = (items instanceof String ? evaluate("items", (String) items) : items);
Object itemsObject = (items instanceof String ? evaluate("items", items) : items);
String itemValue = getItemValue();
String itemLabel = getItemLabel();
......
......@@ -33,7 +33,6 @@ public interface HttpMessageConverter<T> {
/**
* Indicates whether the given class can be read by this converter.
*
* @param clazz the class to test for readability
* @param mediaType the media type to read, can be {@code null} if not specified
* @return <code>true</code> if readable; <code>false</code> otherwise
......@@ -42,7 +41,6 @@ public interface HttpMessageConverter<T> {
/**
* Indicates whether the given class can be written by this converter.
*
* @param clazz the class to test for writability
* @param mediaType the media type to write, can be {@code null} if not specified
* @return <code>true</code> if writable; <code>false</code> otherwise
......@@ -51,14 +49,12 @@ public interface HttpMessageConverter<T> {
/**
* Return the list of {@link MediaType} objects supported by this converter.
*
* @return the list of supported media types
*/
List<MediaType> getSupportedMediaTypes();
/**
* Read an object of the given type form the given input message, and returns it.
*
* @param clazz the type of object to return. This type must have previously been passed to the {@link #canRead
* canRead} method of this interface, which must have returned {@code true}.
* @param inputMessage the HTTP input message to read from
......
......@@ -81,8 +81,8 @@ import org.springframework.web.context.request.WebRequest;
*
* @author Juergen Hoeller
* @author Arjen Poutsma
* @see #invokeHandlerMethod
* @since 2.5.2
* @see #invokeHandlerMethod
*/
public class HandlerMethodInvoker {
......@@ -103,6 +103,7 @@ public class HandlerMethodInvoker {
private final SimpleSessionStatus sessionStatus = new SimpleSessionStatus();
public HandlerMethodInvoker(HandlerMethodResolver methodResolver) {
this(methodResolver, null);
}
......@@ -111,12 +112,9 @@ public class HandlerMethodInvoker {
this(methodResolver, bindingInitializer, new DefaultSessionAttributeStore(), null, null, null);
}
public HandlerMethodInvoker(HandlerMethodResolver methodResolver,
WebBindingInitializer bindingInitializer,
SessionAttributeStore sessionAttributeStore,
ParameterNameDiscoverer parameterNameDiscoverer,
WebArgumentResolver[] customArgumentResolvers,
HttpMessageConverter[] messageConverters) {
public HandlerMethodInvoker(HandlerMethodResolver methodResolver, WebBindingInitializer bindingInitializer,
SessionAttributeStore sessionAttributeStore, ParameterNameDiscoverer parameterNameDiscoverer,
WebArgumentResolver[] customArgumentResolvers, HttpMessageConverter[] messageConverters) {
this.methodResolver = methodResolver;
this.bindingInitializer = bindingInitializer;
......@@ -126,10 +124,9 @@ public class HandlerMethodInvoker {
this.messageConverters = messageConverters;
}
public final Object invokeHandlerMethod(Method handlerMethod,
Object handler,
NativeWebRequest webRequest,
ExtendedModelMap implicitModel) throws Exception {
public final Object invokeHandlerMethod(Method handlerMethod, Object handler,
NativeWebRequest webRequest, ExtendedModelMap implicitModel) throws Exception {
Method handlerMethodToInvoke = BridgeMethodResolver.findBridgedMethod(handlerMethod);
try {
......@@ -174,10 +171,8 @@ public class HandlerMethodInvoker {
}
@SuppressWarnings("unchecked")
private Object[] resolveHandlerArguments(Method handlerMethod,
Object handler,
NativeWebRequest webRequest,
ExtendedModelMap implicitModel) throws Exception {
private Object[] resolveHandlerArguments(Method handlerMethod, Object handler,
NativeWebRequest webRequest, ExtendedModelMap implicitModel) throws Exception {
Class[] paramTypes = handlerMethod.getParameterTypes();
Object[] args = new Object[paramTypes.length];
......@@ -340,10 +335,8 @@ public class HandlerMethodInvoker {
}
}
private Object[] resolveInitBinderArguments(Object handler,
Method initBinderMethod,
WebDataBinder binder,
NativeWebRequest webRequest) throws Exception {
private Object[] resolveInitBinderArguments(Object handler, Method initBinderMethod,
WebDataBinder binder, NativeWebRequest webRequest) throws Exception {
Class[] initBinderParams = initBinderMethod.getParameterTypes();
Object[] initBinderArgs = new Object[initBinderParams.length];
......@@ -410,12 +403,9 @@ public class HandlerMethodInvoker {
}
@SuppressWarnings("unchecked")
private Object resolveRequestParam(String paramName,
boolean required,
String defaultValue,
MethodParameter methodParam,
NativeWebRequest webRequest,
Object handlerForInitBinderCall) throws Exception {
private Object resolveRequestParam(String paramName, boolean required, String defaultValue,
MethodParameter methodParam, NativeWebRequest webRequest, Object handlerForInitBinderCall)
throws Exception {
Class<?> paramType = methodParam.getParameterType();
if (Map.class.isAssignableFrom(paramType)) {
......@@ -471,12 +461,9 @@ public class HandlerMethodInvoker {
}
@SuppressWarnings("unchecked")
private Object resolveRequestHeader(String headerName,
boolean required,
String defaultValue,
MethodParameter methodParam,
NativeWebRequest webRequest,
Object handlerForInitBinderCall) throws Exception {
private Object resolveRequestHeader(String headerName, boolean required, String defaultValue,
MethodParameter methodParam, NativeWebRequest webRequest, Object handlerForInitBinderCall)
throws Exception {
Class<?> paramType = methodParam.getParameterType();
if (Map.class.isAssignableFrom(paramType)) {
......@@ -532,7 +519,9 @@ public class HandlerMethodInvoker {
}
}
/** Resolves the given {@link RequestBody @RequestBody} annotation. */
/**
* Resolves the given {@link RequestBody @RequestBody} annotation.
*/
@SuppressWarnings("unchecked")
protected Object resolveRequestBody(MethodParameter methodParam, NativeWebRequest webRequest, Object handler)
throws Exception {
......@@ -563,8 +552,8 @@ public class HandlerMethodInvoker {
}
/**
* Return a {@link HttpInputMessage} for the given {@link NativeWebRequest}. Throws an UnsupportedOperationException by
* default.
* Return a {@link HttpInputMessage} for the given {@link NativeWebRequest}.
* <p>Throws an UnsupportedOperationException by default.
*/
protected HttpInputMessage createHttpInputMessage(NativeWebRequest webRequest) throws Exception {
throw new UnsupportedOperationException("@RequestBody not supported");
......@@ -596,7 +585,10 @@ public class HandlerMethodInvoker {
return binder.convertIfNecessary(cookieValue, paramType, methodParam);
}
/** Resolves the given {@link CookieValue @CookieValue} annotation. Throws an UnsupportedOperationException by default. */
/**
* Resolves the given {@link CookieValue @CookieValue} annotation.
* <p>Throws an UnsupportedOperationException by default.
*/
protected Object resolveCookieValue(String cookieName, Class paramType, NativeWebRequest webRequest)
throws Exception {
......@@ -619,8 +611,8 @@ public class HandlerMethodInvoker {
}
/**
* Resolves the given {@link PathVariable @PathVariable} annotation. Throws an UnsupportedOperationException by
* default.
* Resolves the given {@link PathVariable @PathVariable} annotation.
* <p>Throws an UnsupportedOperationException by default.
*/
protected String resolvePathVariable(String pathVarName, Class paramType, NativeWebRequest webRequest)
throws Exception {
......@@ -652,11 +644,8 @@ public class HandlerMethodInvoker {
return value;
}
private WebRequestDataBinder resolveModelAttribute(String attrName,
MethodParameter methodParam,
ExtendedModelMap implicitModel,
NativeWebRequest webRequest,
Object handler) throws Exception {
private WebRequestDataBinder resolveModelAttribute(String attrName, MethodParameter methodParam,
ExtendedModelMap implicitModel, NativeWebRequest webRequest, Object handler) throws Exception {
// Bind request parameter onto object...
String name = attrName;
......@@ -683,10 +672,8 @@ public class HandlerMethodInvoker {
}
@SuppressWarnings("unchecked")
public final void updateModelAttributes(Object handler,
Map<String, Object> mavModel,
ExtendedModelMap implicitModel,
NativeWebRequest webRequest) throws Exception {
public final void updateModelAttributes(Object handler, Map<String, Object> mavModel,
ExtendedModelMap implicitModel, NativeWebRequest webRequest) throws Exception {
if (this.methodResolver.hasSessionAttributes() && this.sessionStatus.isComplete()) {
for (String attrName : this.methodResolver.getActualSessionAttributeNames()) {
......@@ -753,9 +740,7 @@ public class HandlerMethodInvoker {
throw new IllegalStateException(message);
}
protected void doBind(WebRequestDataBinder binder,
NativeWebRequest webRequest,
boolean validate,
protected void doBind(WebRequestDataBinder binder, NativeWebRequest webRequest, boolean validate,
boolean failOnErrors) throws Exception {
binder.bind(webRequest);
......@@ -803,10 +788,8 @@ public class HandlerMethodInvoker {
return WebArgumentResolver.UNRESOLVED;
}
protected final void addReturnValueAsModelAttribute(Method handlerMethod,
Class handlerType,
Object returnValue,
ExtendedModelMap implicitModel) {
protected final void addReturnValueAsModelAttribute(Method handlerMethod, Class handlerType,
Object returnValue, ExtendedModelMap implicitModel) {
ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
String attrName = (attr != null ? attr.value() : "");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册