public abstract class AbstractNamedValueMethodArgumentResolver extends java.lang.Object implements HandlerMethodArgumentResolver
Subclasses define how to do the following:
A default value string can contain ${...} placeholders and Spring Expression
Language #{...}
expressions. For this to work a ConfigurableBeanFactory
must be supplied to the class constructor.
A ConversionService
may be used to apply type conversion to the resolved
argument value if it doesn't match the method parameter type.
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractNamedValueMethodArgumentResolver.NamedValueInfo
Represents the information about a named value, including name, whether it's
required and a default value.
|
Modifier and Type | Field and Description |
---|---|
private ConfigurableBeanFactory |
configurableBeanFactory |
private ConversionService |
conversionService |
private BeanExpressionContext |
expressionContext |
private java.util.Map<MethodParameter,AbstractNamedValueMethodArgumentResolver.NamedValueInfo> |
namedValueInfoCache |
Modifier | Constructor and Description |
---|---|
protected |
AbstractNamedValueMethodArgumentResolver(ConversionService cs,
ConfigurableBeanFactory beanFactory)
Constructor with a
ConversionService and a BeanFactory . |
Modifier and Type | Method and Description |
---|---|
protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo |
createNamedValueInfo(MethodParameter parameter)
Create the
AbstractNamedValueMethodArgumentResolver.NamedValueInfo object for the given method parameter. |
private AbstractNamedValueMethodArgumentResolver.NamedValueInfo |
getNamedValueInfo(MethodParameter parameter)
Obtain the named value for the given method parameter.
|
protected abstract void |
handleMissingValue(java.lang.String name,
MethodParameter parameter,
Message<?> message)
Invoked when a named value is required, but
resolveArgumentInternal(MethodParameter, Message, String) returned null and
there is no default value. |
private java.lang.Object |
handleNullValue(java.lang.String name,
java.lang.Object value,
java.lang.Class<?> paramType)
A
null results in a false value for boolean s or an
exception for other primitives. |
protected void |
handleResolvedValue(java.lang.Object arg,
java.lang.String name,
MethodParameter parameter,
Message<?> message)
Invoked after a value is resolved.
|
java.lang.Object |
resolveArgument(MethodParameter parameter,
Message<?> message)
Resolves a method parameter into an argument value from a given message.
|
protected abstract java.lang.Object |
resolveArgumentInternal(MethodParameter parameter,
Message<?> message,
java.lang.String name)
Resolves the given parameter type and value name into an argument value.
|
private java.lang.Object |
resolveDefaultValue(java.lang.String defaultValue)
Resolves the given default value into an argument value.
|
private AbstractNamedValueMethodArgumentResolver.NamedValueInfo |
updateNamedValueInfo(MethodParameter parameter,
AbstractNamedValueMethodArgumentResolver.NamedValueInfo info)
Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
supportsParameter
private final ConversionService conversionService
private final ConfigurableBeanFactory configurableBeanFactory
private final BeanExpressionContext expressionContext
private final java.util.Map<MethodParameter,AbstractNamedValueMethodArgumentResolver.NamedValueInfo> namedValueInfoCache
protected AbstractNamedValueMethodArgumentResolver(ConversionService cs, ConfigurableBeanFactory beanFactory)
ConversionService
and a BeanFactory
.cs
- conversion service for converting values to match the
target method parameter typebeanFactory
- a bean factory to use for resolving ${...}
placeholder
and #{...}
SpEL expressions in default values, or null
if default
values are not expected to contain expressionspublic java.lang.Object resolveArgument(MethodParameter parameter, Message<?> message) throws java.lang.Exception
HandlerMethodArgumentResolver
resolveArgument
in interface HandlerMethodArgumentResolver
parameter
- the method parameter to resolve.
This parameter must have previously been passed to
HandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)
which must have returned true
.message
- the currently processed messagenull
java.lang.Exception
- in case of errors with the preparation of argument valuesprivate AbstractNamedValueMethodArgumentResolver.NamedValueInfo getNamedValueInfo(MethodParameter parameter)
protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo createNamedValueInfo(MethodParameter parameter)
AbstractNamedValueMethodArgumentResolver.NamedValueInfo
object for the given method parameter. Implementations typically
retrieve the method annotation by means of MethodParameter.getParameterAnnotation(Class)
.parameter
- the method parameterprivate AbstractNamedValueMethodArgumentResolver.NamedValueInfo updateNamedValueInfo(MethodParameter parameter, AbstractNamedValueMethodArgumentResolver.NamedValueInfo info)
protected abstract java.lang.Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, java.lang.String name) throws java.lang.Exception
parameter
- the method parameter to resolve to an argument valuemessage
- the current requestname
- the name of the value being resolvednull
java.lang.Exception
- in case of errorsprivate java.lang.Object resolveDefaultValue(java.lang.String defaultValue)
protected abstract void handleMissingValue(java.lang.String name, MethodParameter parameter, Message<?> message)
resolveArgumentInternal(MethodParameter, Message, String)
returned null
and
there is no default value. Subclasses typically throw an exception in this case.name
- the name for the valueparameter
- the method parametermessage
- the message being processedprivate java.lang.Object handleNullValue(java.lang.String name, java.lang.Object value, java.lang.Class<?> paramType)
null
results in a false
value for boolean
s or an
exception for other primitives.protected void handleResolvedValue(java.lang.Object arg, java.lang.String name, MethodParameter parameter, Message<?> message)
arg
- the resolved argument valuename
- the argument nameparameter
- the argument parameter typemessage
- the message