public class ExceptionHandlerMethodResolver
extends java.lang.Object
Exception
to the exception types supported by a given Method
.Modifier and Type | Field and Description |
---|---|
static ReflectionUtils.MethodFilter |
EXCEPTION_HANDLER_METHODS
A filter for selecting
@ExceptionHandler methods. |
private java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.reflect.Method> |
exceptionLookupCache |
private java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.reflect.Method> |
mappedMethods |
private static java.lang.reflect.Method |
NO_METHOD_FOUND
Arbitrary
Method reference, indicating no method found in the cache. |
Constructor and Description |
---|
ExceptionHandlerMethodResolver(java.lang.Class<?> handlerType)
A constructor that finds
ExceptionHandler methods in the given type. |
Modifier and Type | Method and Description |
---|---|
private void |
addExceptionMapping(java.lang.Class<? extends java.lang.Throwable> exceptionType,
java.lang.reflect.Method method) |
protected void |
detectAnnotationExceptionMappings(java.lang.reflect.Method method,
java.util.List<java.lang.Class<? extends java.lang.Throwable>> result) |
private java.util.List<java.lang.Class<? extends java.lang.Throwable>> |
detectExceptionMappings(java.lang.reflect.Method method)
Extract exception mappings from the
@ExceptionHandler annotation first,
and then as a fallback from the method signature itself. |
private java.lang.reflect.Method |
getMappedMethod(java.lang.Class<? extends java.lang.Exception> exceptionType)
Return the
Method mapped to the given exception type, or null if none. |
boolean |
hasExceptionMappings()
Whether the contained type has any exception mappings.
|
java.lang.reflect.Method |
resolveMethod(java.lang.Exception exception)
Find a
Method to handle the given exception. |
java.lang.reflect.Method |
resolveMethodByExceptionType(java.lang.Class<? extends java.lang.Exception> exceptionType)
Find a
Method to handle the given exception type. |
public static final ReflectionUtils.MethodFilter EXCEPTION_HANDLER_METHODS
@ExceptionHandler
methods.private static final java.lang.reflect.Method NO_METHOD_FOUND
Method
reference, indicating no method found in the cache.private final java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.reflect.Method> mappedMethods
private final java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.reflect.Method> exceptionLookupCache
public ExceptionHandlerMethodResolver(java.lang.Class<?> handlerType)
ExceptionHandler
methods in the given type.handlerType
- the type to introspectprivate java.util.List<java.lang.Class<? extends java.lang.Throwable>> detectExceptionMappings(java.lang.reflect.Method method)
@ExceptionHandler
annotation first,
and then as a fallback from the method signature itself.protected void detectAnnotationExceptionMappings(java.lang.reflect.Method method, java.util.List<java.lang.Class<? extends java.lang.Throwable>> result)
private void addExceptionMapping(java.lang.Class<? extends java.lang.Throwable> exceptionType, java.lang.reflect.Method method)
public boolean hasExceptionMappings()
public java.lang.reflect.Method resolveMethod(java.lang.Exception exception)
Method
to handle the given exception.
Use ExceptionDepthComparator
if more than one match is found.exception
- the exceptionnull
if none foundpublic java.lang.reflect.Method resolveMethodByExceptionType(java.lang.Class<? extends java.lang.Exception> exceptionType)
Method
to handle the given exception type. This can be
useful if an Exception
instance is not available (e.g. for tools).exceptionType
- the exception typenull
if none foundprivate java.lang.reflect.Method getMappedMethod(java.lang.Class<? extends java.lang.Exception> exceptionType)
Method
mapped to the given exception type, or null
if none.