Polishing
This commit is contained in:
parent
ef1748f694
commit
8a96d1a6ee
|
@ -19,7 +19,8 @@ package org.springframework.cache;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A manager for a set of {@link Cache}s.
|
* Spring's central cache manager SPI.
|
||||||
|
* Allows for retrieving named {@link Cache} regions.
|
||||||
*
|
*
|
||||||
* @author Costin Leau
|
* @author Costin Leau
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
|
@ -28,14 +29,14 @@ public interface CacheManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the cache associated with the given name.
|
* Return the cache associated with the given name.
|
||||||
* @param name cache identifier (must not be {@code null})
|
* @param name the cache identifier (must not be {@code null})
|
||||||
* @return the associated cache, or {@code null} if none is found
|
* @return the associated cache, or {@code null} if none found
|
||||||
*/
|
*/
|
||||||
Cache getCache(String name);
|
Cache getCache(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a collection of the caches known by this cache manager.
|
* Return a collection of the cache names known by this manager.
|
||||||
* @return names of caches known by the cache manager
|
* @return the names of all caches known by the cache manager
|
||||||
*/
|
*/
|
||||||
Collection<String> getCacheNames();
|
Collection<String> getCacheNames();
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@ -33,25 +33,28 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.method.HandlerMethodSelector;
|
import org.springframework.web.method.HandlerMethodSelector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Discovers annotated exception handling methods in a given class type, including all
|
* Discovers {@linkplain ExceptionHandler @ExceptionHandler} methods in a given class,
|
||||||
* super types, and helps to resolve an Exception to a method that can handle it. The
|
* including all of its superclasses, and helps to resolve a given {@link Exception}
|
||||||
* exception types supported by a given method can also be discovered from the method
|
* to the exception types supported by a given {@link Method}.
|
||||||
* signature.
|
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public class ExceptionHandlerMethodResolver {
|
public class ExceptionHandlerMethodResolver {
|
||||||
|
|
||||||
/** A filter for selecting annotated exception handling methods. */
|
/**
|
||||||
public final static MethodFilter EXCEPTION_HANDLER_METHODS = new MethodFilter() {
|
* A filter for selecting {@code @ExceptionHandler} methods.
|
||||||
|
*/
|
||||||
|
public static final MethodFilter EXCEPTION_HANDLER_METHODS = new MethodFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method method) {
|
public boolean matches(Method method) {
|
||||||
return (AnnotationUtils.findAnnotation(method, ExceptionHandler.class) != null);
|
return (AnnotationUtils.findAnnotation(method, ExceptionHandler.class) != null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arbitrary {@link Method} reference, indicating no method found in the cache.
|
||||||
|
*/
|
||||||
private static final Method NO_METHOD_FOUND = ClassUtils.getMethodIfAvailable(System.class, "currentTimeMillis");
|
private static final Method NO_METHOD_FOUND = ClassUtils.getMethodIfAvailable(System.class, "currentTimeMillis");
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,26 +119,26 @@ public class ExceptionHandlerMethodResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a method to handle the given exception.
|
* Find a {@link Method} to handle the given exception.
|
||||||
* Use {@link ExceptionDepthComparator} if more than one match is found.
|
* Use {@link ExceptionDepthComparator} if more than one match is found.
|
||||||
* @param exception the exception
|
* @param exception the exception
|
||||||
* @return a method to handle the exception or {@code null}
|
* @return a Method to handle the exception, or {@code null} if none found
|
||||||
*/
|
*/
|
||||||
public Method resolveMethod(Exception exception) {
|
public Method resolveMethod(Exception exception) {
|
||||||
return resolveMethodByExceptionType(exception.getClass());
|
return resolveMethodByExceptionType(exception.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a method to handle the given exception type. This can be useful if
|
* Find a {@link Method} to handle the given exception type. This can be
|
||||||
* an Exception instance is not available (example for tools).
|
* useful if an {@link Exception} instance is not available (e.g. for tools).
|
||||||
* @param exceptionType the exception type
|
* @param exceptionType the exception type
|
||||||
* @return a method to handle the exception or {@code null}
|
* @return a Method to handle the exception, or {@code null} if none found
|
||||||
*/
|
*/
|
||||||
public Method resolveMethodByExceptionType(Class<? extends Exception> exceptionType) {
|
public Method resolveMethodByExceptionType(Class<? extends Exception> exceptionType) {
|
||||||
Method method = this.exceptionLookupCache.get(exceptionType);
|
Method method = this.exceptionLookupCache.get(exceptionType);
|
||||||
if (method == null) {
|
if (method == null) {
|
||||||
method = getMappedMethod(exceptionType);
|
method = getMappedMethod(exceptionType);
|
||||||
this.exceptionLookupCache.put(exceptionType, method != null ? method : NO_METHOD_FOUND);
|
this.exceptionLookupCache.put(exceptionType, (method != null ? method : NO_METHOD_FOUND));
|
||||||
}
|
}
|
||||||
return method != NO_METHOD_FOUND ? method : null;
|
return method != NO_METHOD_FOUND ? method : null;
|
||||||
}
|
}
|
||||||
|
@ -152,7 +155,7 @@ public class ExceptionHandlerMethodResolver {
|
||||||
}
|
}
|
||||||
if (!matches.isEmpty()) {
|
if (!matches.isEmpty()) {
|
||||||
Collections.sort(matches, new ExceptionDepthComparator(exceptionType));
|
Collections.sort(matches, new ExceptionDepthComparator(exceptionType));
|
||||||
return mappedMethods.get(matches.get(0));
|
return this.mappedMethods.get(matches.get(0));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -226,9 +226,9 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (HttpMediaTypeNotAcceptableException e) {
|
catch (HttpMediaTypeNotAcceptableException ex) {
|
||||||
// should never happen
|
// should never happen
|
||||||
throw new IllegalStateException("Cannot compare without having any requested media types");
|
throw new IllegalStateException("Cannot compare without having any requested media types", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,6 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
|
||||||
/**
|
/**
|
||||||
* Check if any of the HTTP request methods match the given request and
|
* Check if any of the HTTP request methods match the given request and
|
||||||
* return an instance that contains the matching HTTP request method only.
|
* return an instance that contains the matching HTTP request method only.
|
||||||
*
|
|
||||||
* @param request the current request
|
* @param request the current request
|
||||||
* @return the same instance if the condition is empty, a new condition with
|
* @return the same instance if the condition is empty, a new condition with
|
||||||
* the matched request method, or {@code null} if no request methods match
|
* the matched request method, or {@code null} if no request methods match
|
||||||
|
@ -114,7 +113,7 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
|
||||||
try {
|
try {
|
||||||
return RequestMethod.valueOf(request.getMethod());
|
return RequestMethod.valueOf(request.getMethod());
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException ex) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,7 +383,7 @@ public class FormTag extends AbstractHtmlElementTag {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getHttpMethod() {
|
private String getHttpMethod() {
|
||||||
return isMethodBrowserSupported(getMethod()) ? getMethod() : DEFAULT_METHOD;
|
return (isMethodBrowserSupported(getMethod()) ? getMethod() : DEFAULT_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertHttpMethod(String method) {
|
private void assertHttpMethod(String method) {
|
||||||
|
|
Loading…
Reference in New Issue