mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Polishing
This commit is contained in:
+66
-59
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -152,6 +152,28 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
return this.mappingRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the given mapping.
|
||||
* <p>This method may be invoked at runtime after initialization has completed.
|
||||
* @param mapping the mapping for the handler method
|
||||
* @param handler the handler
|
||||
* @param method the method
|
||||
*/
|
||||
public void registerMapping(T mapping, Object handler, Method method) {
|
||||
this.mappingRegistry.register(mapping, handler, method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Un-register the given mapping.
|
||||
* <p>This method may be invoked at runtime after initialization has completed.
|
||||
* @param mapping the mapping to unregister
|
||||
*/
|
||||
public void unregisterMapping(T mapping) {
|
||||
this.mappingRegistry.unregister(mapping);
|
||||
}
|
||||
|
||||
|
||||
// Handler method detection
|
||||
|
||||
/**
|
||||
* Detects handler methods at initialization.
|
||||
@@ -195,13 +217,6 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
handlerMethodsInitialized(getHandlerMethods());
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the given type is a handler with handler methods.
|
||||
* @param beanType the type of the bean being checked
|
||||
* @return "true" if this a handler type, "false" otherwise.
|
||||
*/
|
||||
protected abstract boolean isHandler(Class<?> beanType);
|
||||
|
||||
/**
|
||||
* Look for handler methods in a handler.
|
||||
* @param handler the bean name of a handler or a handler instance
|
||||
@@ -227,16 +242,6 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the mapping for a handler method. A method for which no
|
||||
* mapping can be provided is not a handler method.
|
||||
* @param method the method to provide a mapping for
|
||||
* @param handlerType the handler type, possibly a sub-type of the method's
|
||||
* declaring class
|
||||
* @return the mapping, or {@code null} if the method is not mapped
|
||||
*/
|
||||
protected abstract T getMappingForMethod(Method method, Class<?> handlerType);
|
||||
|
||||
/**
|
||||
* Register a handler method and its unique mapping. Invoked at startup for
|
||||
* each detected handler method.
|
||||
@@ -269,11 +274,6 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
return handlerMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract and return the URL paths contained in a mapping.
|
||||
*/
|
||||
protected abstract Set<String> getMappingPathPatterns(T mapping);
|
||||
|
||||
/**
|
||||
* Extract and return the CORS configuration for the mapping.
|
||||
*/
|
||||
@@ -288,25 +288,8 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
protected void handlerMethodsInitialized(Map<T, HandlerMethod> handlerMethods) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the given mapping.
|
||||
* <p>This method may be invoked at runtime after initialization has completed.
|
||||
* @param mapping the mapping for the handler method
|
||||
* @param handler the handler
|
||||
* @param method the method
|
||||
*/
|
||||
public void registerMapping(T mapping, Object handler, Method method) {
|
||||
this.mappingRegistry.register(mapping, handler, method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Un-register the given mapping.
|
||||
* <p>This method may be invoked at runtime after initialization has completed.
|
||||
* @param mapping the mapping to unregister
|
||||
*/
|
||||
public void unregisterMapping(T mapping) {
|
||||
this.mappingRegistry.unregister(mapping);
|
||||
}
|
||||
// Handler method lookup
|
||||
|
||||
/**
|
||||
* Look up a handler method for the given request.
|
||||
@@ -392,23 +375,6 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a mapping matches the current request and return a (potentially
|
||||
* new) mapping with conditions relevant to the current request.
|
||||
* @param mapping the mapping to get a match for
|
||||
* @param request the current HTTP servlet request
|
||||
* @return the match, or {@code null} if the mapping doesn't match
|
||||
*/
|
||||
protected abstract T getMatchingMapping(T mapping, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* Return a comparator for sorting matching mappings.
|
||||
* The returned comparator should sort 'better' matches higher.
|
||||
* @param request the current request
|
||||
* @return the comparator (never {@code null})
|
||||
*/
|
||||
protected abstract Comparator<T> getMappingComparator(HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* Invoked when a matching mapping is found.
|
||||
* @param mapping the matching mapping
|
||||
@@ -449,6 +415,48 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
}
|
||||
|
||||
|
||||
// Abstract template methods
|
||||
|
||||
/**
|
||||
* Whether the given type is a handler with handler methods.
|
||||
* @param beanType the type of the bean being checked
|
||||
* @return "true" if this a handler type, "false" otherwise.
|
||||
*/
|
||||
protected abstract boolean isHandler(Class<?> beanType);
|
||||
|
||||
/**
|
||||
* Provide the mapping for a handler method. A method for which no
|
||||
* mapping can be provided is not a handler method.
|
||||
* @param method the method to provide a mapping for
|
||||
* @param handlerType the handler type, possibly a sub-type of the method's
|
||||
* declaring class
|
||||
* @return the mapping, or {@code null} if the method is not mapped
|
||||
*/
|
||||
protected abstract T getMappingForMethod(Method method, Class<?> handlerType);
|
||||
|
||||
/**
|
||||
* Extract and return the URL paths contained in a mapping.
|
||||
*/
|
||||
protected abstract Set<String> getMappingPathPatterns(T mapping);
|
||||
|
||||
/**
|
||||
* Check if a mapping matches the current request and return a (potentially
|
||||
* new) mapping with conditions relevant to the current request.
|
||||
* @param mapping the mapping to get a match for
|
||||
* @param request the current HTTP servlet request
|
||||
* @return the match, or {@code null} if the mapping doesn't match
|
||||
*/
|
||||
protected abstract T getMatchingMapping(T mapping, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* Return a comparator for sorting matching mappings.
|
||||
* The returned comparator should sort 'better' matches higher.
|
||||
* @param request the current request
|
||||
* @return the comparator (never {@code null})
|
||||
*/
|
||||
protected abstract Comparator<T> getMappingComparator(HttpServletRequest request);
|
||||
|
||||
|
||||
/**
|
||||
* A registry that maintains all mappings to handler methods, exposing methods
|
||||
* to perform lookups and providing concurrent access.
|
||||
@@ -516,7 +524,6 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
this.readWriteLock.readLock().unlock();
|
||||
}
|
||||
|
||||
|
||||
public void register(T mapping, Object handler, Method method) {
|
||||
this.readWriteLock.writeLock().lock();
|
||||
try {
|
||||
|
||||
+8
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -48,6 +48,7 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth
|
||||
super(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
if (!parameter.hasParameterAnnotation(MatrixVariable.class)) {
|
||||
@@ -67,13 +68,10 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, MultiValueMap<String, String>> pathParameters =
|
||||
(Map<String, MultiValueMap<String, String>>) request.getAttribute(
|
||||
HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
|
||||
|
||||
Map<String, MultiValueMap<String, String>> pathParameters = (Map<String, MultiValueMap<String, String>>)
|
||||
request.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
|
||||
if (CollectionUtils.isEmpty(pathParameters)) {
|
||||
return null;
|
||||
}
|
||||
@@ -95,7 +93,7 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth
|
||||
String paramType = parameter.getParameterType().getName();
|
||||
throw new ServletRequestBindingException(
|
||||
"Found more than one match for URI path parameter '" + name +
|
||||
"' for parameter type [" + paramType + "]. Use pathVar attribute to disambiguate.");
|
||||
"' for parameter type [" + paramType + "]. Use 'pathVar' attribute to disambiguate.");
|
||||
}
|
||||
paramValues.addAll(params.get(name));
|
||||
found = true;
|
||||
@@ -127,4 +125,5 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth
|
||||
super(annotation.name(), annotation.required(), annotation.defaultValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -33,7 +33,6 @@ import org.springframework.web.bind.annotation.ValueConstants;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver;
|
||||
import org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
import org.springframework.web.method.support.UriComponentsContributor;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
@@ -43,22 +42,18 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
/**
|
||||
* Resolves method arguments annotated with an @{@link PathVariable}.
|
||||
*
|
||||
* <p>An @{@link PathVariable} is a named value that gets resolved from a URI
|
||||
* template variable. It is always required and does not have a default value
|
||||
* to fall back on. See the base class
|
||||
* <p>An @{@link PathVariable} is a named value that gets resolved from a URI template variable.
|
||||
* It is always required and does not have a default value to fall back on. See the base class
|
||||
* {@link org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver}
|
||||
* for more information on how named values are processed.
|
||||
*
|
||||
* <p>If the method parameter type is {@link Map}, the name specified in the
|
||||
* annotation is used to resolve the URI variable String value. The value is
|
||||
* then converted to a {@link Map} via type conversion assuming a suitable
|
||||
* {@link Converter} or {@link PropertyEditor} has been registered.
|
||||
* Or if the annotation does not specify name the
|
||||
* {@link RequestParamMapMethodArgumentResolver} is used instead to provide
|
||||
* access to all URI variables in a map.
|
||||
* <p>If the method parameter type is {@link Map}, the name specified in the annotation is used
|
||||
* to resolve the URI variable String value. The value is then converted to a {@link Map} via
|
||||
* type conversion, assuming a suitable {@link Converter} or {@link PropertyEditor} has been
|
||||
* registered.
|
||||
*
|
||||
* <p>A {@link WebDataBinder} is invoked to apply type conversion to resolved
|
||||
* path variable values that don't yet match the method parameter type.
|
||||
* <p>A {@link WebDataBinder} is invoked to apply type conversion to resolved path variable
|
||||
* values that don't yet match the method parameter type.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Arjen Poutsma
|
||||
@@ -95,10 +90,9 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueMethod
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
|
||||
Map<String, String> uriTemplateVars =
|
||||
(Map<String, String>) request.getAttribute(
|
||||
HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
|
||||
return (uriTemplateVars != null) ? uriTemplateVars.get(name) : null;
|
||||
Map<String, String> uriTemplateVars = (Map<String, String>) request.getAttribute(
|
||||
HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
|
||||
return (uriTemplateVars != null ? uriTemplateVars.get(name) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-2
@@ -28,7 +28,6 @@ import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.core.io.AbstractResource;
|
||||
@@ -238,6 +237,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private class FileNameVersionedResource extends AbstractResource implements VersionedResource {
|
||||
|
||||
private final Resource original;
|
||||
@@ -313,7 +313,6 @@ public class VersionResourceResolver extends AbstractResourceResolver {
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-2
@@ -19,8 +19,8 @@ package org.springframework.web.servlet.resource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Interface for a resource descriptor that describes its version
|
||||
* with a version string that can be derived from its content and/or metadata.
|
||||
* Interface for a resource descriptor that describes its version with a
|
||||
* version string that can be derived from its content and/or metadata.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 4.2.5
|
||||
@@ -29,4 +29,5 @@ import org.springframework.core.io.Resource;
|
||||
public interface VersionedResource extends Resource {
|
||||
|
||||
String getVersion();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user