public class ExceptionMapperFactory extends java.lang.Object implements ExceptionMappers
Exception mappers
implementation that aggregates
exception mappers and server as the main entry point for exception mapper
instance lookup.Modifier and Type | Class and Description |
---|---|
static class |
ExceptionMapperFactory.ExceptionMappersConfigurator
Configurator which initializes and register
ExceptionMappers instance into InjectionManager and
BootstrapBag . |
private static class |
ExceptionMapperFactory.ExceptionMapperType |
Modifier and Type | Field and Description |
---|---|
private Value<java.util.Set<ExceptionMapperFactory.ExceptionMapperType>> |
exceptionMapperTypes |
private static java.util.logging.Logger |
LOGGER |
Constructor and Description |
---|
ExceptionMapperFactory(InjectionManager injectionManager)
Create new exception mapper factory initialized with
injection manager
instance that will be used to look up all providers implementing ExceptionMapper interface. |
Modifier and Type | Method and Description |
---|---|
private LazyValue<java.util.Set<ExceptionMapperFactory.ExceptionMapperType>> |
createLazyExceptionMappers(InjectionManager injectionManager)
Returns
LazyValue of exception mappers that delays their creation to the first use. |
private int |
distance(java.lang.Class<?> c,
java.lang.Class<?> emtc) |
<T extends java.lang.Throwable> |
find(java.lang.Class<T> type)
Get an exception mapping provider for a particular class of exception.
|
private <T extends java.lang.Throwable> |
find(java.lang.Class<T> type,
T exceptionInstance) |
<T extends java.lang.Throwable> |
findMapping(T exceptionInstance)
Get an exception mapping provider for a particular exception instance.
|
private java.lang.Class<? extends java.lang.Throwable> |
getExceptionType(java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> c) |
private java.lang.Class |
getResolvedType(java.lang.reflect.Type t,
java.lang.Class c,
java.lang.Class dc) |
private java.lang.Class |
getType(java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> clazz)
Get exception type for given exception mapper class.
|
private java.lang.Class |
getTypeFromInterface(java.lang.Class<?> clazz,
java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> original)
Iterate through interface hierarchy of
clazz and get exception type for given class. |
private <T extends java.lang.Throwable> |
isPreferredCandidate(T exceptionInstance,
javax.ws.rs.ext.ExceptionMapper<T> candidate,
boolean sameDistance)
Determines whether the currently considered candidate should be preferred over the previous one.
|
private static final java.util.logging.Logger LOGGER
private final Value<java.util.Set<ExceptionMapperFactory.ExceptionMapperType>> exceptionMapperTypes
public ExceptionMapperFactory(InjectionManager injectionManager)
injection manager
instance that will be used to look up all providers implementing ExceptionMapper
interface.injectionManager
- injection manager.public <T extends java.lang.Throwable> javax.ws.rs.ext.ExceptionMapper<T> findMapping(T exceptionInstance)
ExceptionMappers
This method is similar to method ExceptionMappers.find(Class)
. In addition it takes
into an account the result of the ExtendedExceptionMapper.isMappable(Throwable)
of any mapper that implements Jersey ExtendedExceptionMapper
API.
If an extended exception mapper returns false
from isMappable(Throwable)
,
the mapper is disregarded from the search.
Exception mapping providers are checked one by one until a first provider returns
true
from the isMappable(Throwable)
method or until a first provider
is found which best supports the exception type and does not implement ExtendedExceptionMapper
API (i.e. it is a standard JAX-RS ExceptionMapper
). The order in which the providers are
checked is determined by the distance of the declared exception mapper type and the actual exception
type.
Note that if an exception mapping provider does not implement ExtendedExceptionMapper
it is always considered applicable for a given exception instance.
findMapping
in interface ExceptionMappers
T
- type of the exception handled by the exception mapping provider.exceptionInstance
- exception to be handled by the exception mapping provider.ExceptionMapper
for the supplied exception instance type or null
if none
is found.public <T extends java.lang.Throwable> javax.ws.rs.ext.ExceptionMapper<T> find(java.lang.Class<T> type)
ExceptionMappers
type
.find
in interface ExceptionMappers
T
- type of the exception handled by the exception mapping provider.type
- the class of exception.ExceptionMapper
for the supplied type or null
if none is found.private <T extends java.lang.Throwable> javax.ws.rs.ext.ExceptionMapper<T> find(java.lang.Class<T> type, T exceptionInstance)
private <T extends java.lang.Throwable> boolean isPreferredCandidate(T exceptionInstance, javax.ws.rs.ext.ExceptionMapper<T> candidate, boolean sameDistance)
T
- exception type.exceptionInstance
- exception to be mapped.candidate
- mapper able to map given exception type.sameDistance
- flag indicating whether this and the previously considered candidate are in the same distance.true
if the given candidate is preferred over the previous one with the same or lower distance,
false
otherwise.private LazyValue<java.util.Set<ExceptionMapperFactory.ExceptionMapperType>> createLazyExceptionMappers(InjectionManager injectionManager)
LazyValue
of exception mappers that delays their creation to the first use. The exception mappers won't be
created during bootstrap but at the time of the first call.injectionManager
- injection manager that may not be fully populated at the time of a function call therefore the
result is wrapped to lazy value.private int distance(java.lang.Class<?> c, java.lang.Class<?> emtc)
private java.lang.Class<? extends java.lang.Throwable> getExceptionType(java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> c)
private java.lang.Class getType(java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> clazz)
clazz
- class to get exception type for.private java.lang.Class getTypeFromInterface(java.lang.Class<?> clazz, java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> original)
clazz
and get exception type for given class.clazz
- class to inspect.null
if the class doesn't implement ExceptionMapper
.private java.lang.Class getResolvedType(java.lang.reflect.Type t, java.lang.Class c, java.lang.Class dc)