Top Description Inners Fields Constructors Methods
org.springframework.messaging.handler.annotation.support

public abstract Class AbstractNamedValueMethodArgumentResolver

extends Object
implements HandlerMethodArgumentResolver
Class Inheritance
All Implemented Interfaces
org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver
Known Direct Subclasses
org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver, org.springframework.messaging.handler.annotation.support.HeaderMethodArgumentResolver
Imports
java.util.Map, java.util.concurrent.ConcurrentHashMap, org.springframework.beans.factory.BeanFactory, org.springframework.beans.factory.config.BeanExpressionContext, .BeanExpressionResolver, .ConfigurableBeanFactory, org.springframework.core.MethodParameter, org.springframework.core.convert.ConversionService, .TypeDescriptor, org.springframework.core.convert.support.DefaultConversionService, org.springframework.lang.Nullable, org.springframework.messaging.Message, org.springframework.messaging.handler.annotation.ValueConstants, org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver, org.springframework.util.ClassUtils

Abstract base class to resolve method arguments from a named value, e.g. message headers or destination variables. Named values could have one or more of a name, a required flag, and a default value.

Subclasses only need to define specific steps such as how to obtain named value details from a method parameter, how to resolve to argument values, or how to handle missing values.

A default value string can contain ${...} placeholders and Spring Expression Language #{...} expressions which will be resolved if a ConfigurableBeanFactory is supplied to the class constructor.

A ConversionService is used to convert a resolved String argument value to the expected target method parameter type.

Authors
Rossen Stoyanchev, Juergen Hoeller
Since
4.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
AbstractNamedValueMethodArgumentResolver.NamedValueInfo

Represents a named value declaration.

Field Summary

Modifier and TypeField and Description
private final ConfigurableBeanFactory
private final ConversionService
private final BeanExpressionContext
private final Map<MethodParameter, AbstractNamedValueMethodArgumentResolver.NamedValueInfo>

Constructor Summary

AccessConstructor and Description
protected
AbstractNamedValueMethodArgumentResolver(ConversionService
conversion service for converting String values to the target method parameter type
conversionService
,
ConfigurableBeanFactory
a bean factory for resolving ${...} placeholders and #{...} SpEL expressions in default values
beanFactory
)

Constructor with a ConversionService and a BeanFactory.

Method Summary

Modifier and TypeMethod and Description
protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo

Returns:

the named value information
createNamedValueInfo
(MethodParameter
the method parameter
parameter
)

Create the 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(String
the name for the value
name
,
MethodParameter
the target method parameter
parameter
,
Message<?>
the message being processed
message
)

Invoked when a value is required, but resolveArgumentInternal returned null and there is no default value.

private Object
handleNullValue(String name, Object value, Class<?> paramType)

One last chance to handle a possible null value.

protected void
handleResolvedValue(Object
the resolved argument value
arg
,
String
the argument name
name
,
MethodParameter
the argument parameter type
parameter
,
Message<?>
the message
message
)

Invoked after a value is resolved.

public Object
resolveArgument(MethodParameter
the method parameter to resolve. This parameter must have previously been passed to supportsParameter(org.springframework.core.MethodParameter) which must have returned true.
parameter
,
Message<?>
the currently processed message
message
)

Implements org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver.resolveArgument.

Resolves a method parameter into an argument value from a given message.

protected abstract Object

Returns:

the resolved argument. May be null
resolveArgumentInternal
(MethodParameter
the method parameter to resolve to an argument value
parameter
,
Message<?>
the current request
message
,
String
the name of the value being resolved
name
)

Resolves the given parameter type and value name into an argument value.

private Object
resolveEmbeddedValuesAndExpressions(String value)

Resolve the given annotation-specified value, potentially containing placeholders and expressions.

private AbstractNamedValueMethodArgumentResolver.NamedValueInfo
updateNamedValueInfo(MethodParameter parameter, AbstractNamedValueMethodArgumentResolver.NamedValueInfo info)

Fall back on the parameter name from the class file if necessary and replace ValueConstants#DEFAULT_NONE with null.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configurableBeanFactoryback to summary
private final ConfigurableBeanFactory configurableBeanFactory
Annotations
@Nullable
conversionServiceback to summary
private final ConversionService conversionService
expressionContextback to summary
private final BeanExpressionContext expressionContext
Annotations
@Nullable
namedValueInfoCacheback to summary
private final Map<MethodParameter, AbstractNamedValueMethodArgumentResolver.NamedValueInfo> namedValueInfoCache

Constructor Detail

AbstractNamedValueMethodArgumentResolverback to summary
protected AbstractNamedValueMethodArgumentResolver(ConversionService conversionService, ConfigurableBeanFactory beanFactory)

Constructor with a ConversionService and a BeanFactory.

Parameters
conversionService:ConversionService

conversion service for converting String values to the target method parameter type

beanFactory:ConfigurableBeanFactory

a bean factory for resolving ${...} placeholders and #{...} SpEL expressions in default values

Method Detail

createNamedValueInfoback to summary
protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo createNamedValueInfo(MethodParameter parameter)

Create the NamedValueInfo object for the given method parameter. Implementations typically retrieve the method annotation by means of MethodParameter#getParameterAnnotation(Class).

Parameters
parameter:MethodParameter

the method parameter

Returns:AbstractNamedValueMethodArgumentResolver.NamedValueInfo

the named value information

getNamedValueInfoback to summary
private AbstractNamedValueMethodArgumentResolver.NamedValueInfo getNamedValueInfo(MethodParameter parameter)

Obtain the named value for the given method parameter.

handleMissingValueback to summary
protected abstract void handleMissingValue(String name, MethodParameter parameter, Message<?> message)

Invoked when a value is required, but resolveArgumentInternal returned null and there is no default value. Subclasses can throw an appropriate exception for this case.

Parameters
name:String

the name for the value

parameter:MethodParameter

the target method parameter

message:Message<?>

the message being processed

handleNullValueback to summary
private Object handleNullValue(String name, Object value, Class<?> paramType)

One last chance to handle a possible null value. Specifically for booleans method parameters, use Boolean#FALSE. Also raise an ISE for primitive types.

Annotations
@Nullable
handleResolvedValueback to summary
protected void handleResolvedValue(Object arg, String name, MethodParameter parameter, Message<?> message)

Invoked after a value is resolved.

Parameters
arg:Object

the resolved argument value

name:String

the argument name

parameter:MethodParameter

the argument parameter type

message:Message<?>

the message

resolveArgumentback to summary
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception

Implements org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver.resolveArgument.

Doc from org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver.resolveArgument.

Resolves a method parameter into an argument value from a given message.

Parameters
parameter:MethodParameter

the method parameter to resolve. This parameter must have previously been passed to supportsParameter(org.springframework.core.MethodParameter) which must have returned true.

message:Message<?>

the currently processed message

Returns:Object

the resolved argument value, or null

Annotations
@Override
Exceptions
Exception:
in case of errors with the preparation of argument values
resolveArgumentInternalback to summary
protected abstract Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name) throws Exception

Resolves the given parameter type and value name into an argument value.

Parameters
parameter:MethodParameter

the method parameter to resolve to an argument value

message:Message<?>

the current request

name:String

the name of the value being resolved

Returns:Object

the resolved argument. May be null

Annotations
@Nullable
Exceptions
Exception:
in case of errors
resolveEmbeddedValuesAndExpressionsback to summary
private Object resolveEmbeddedValuesAndExpressions(String value)

Resolve the given annotation-specified value, potentially containing placeholders and expressions.

Annotations
@Nullable
updateNamedValueInfoback to summary
private AbstractNamedValueMethodArgumentResolver.NamedValueInfo updateNamedValueInfo(MethodParameter parameter, AbstractNamedValueMethodArgumentResolver.NamedValueInfo info)

Fall back on the parameter name from the class file if necessary and replace ValueConstants#DEFAULT_NONE with null.

org.springframework.messaging.handler.annotation.support back to summary

protected Class AbstractNamedValueMethodArgumentResolver.NamedValueInfo

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.messaging.handler.annotation.support.AbstractNamedValueMethodArgumentResolver.NamedValueInfo
Known Direct Subclasses
org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver.DestinationVariableNamedValueInfo, org.springframework.messaging.handler.annotation.support.HeaderMethodArgumentResolver.HeaderNamedValueInfo

Represents a named value declaration.

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final boolean

Constructor Summary

AccessConstructor and Description
protected
NamedValueInfo(String name, boolean required, String defaultValue)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultValueback to summary
private final String defaultValue
Annotations
@Nullable
nameback to summary
private final String name
requiredback to summary
private final boolean required

Constructor Detail

NamedValueInfoback to summary
protected NamedValueInfo(String name, boolean required, String defaultValue)