org.springframework.messaging.handler.annotation.support

## Class AbstractNamedValueMethodArgumentResolver

- java.lang.Object
- - org.springframework.messaging.handler.annotation.support.AbstractNamedValueMethodArgumentResolver

- All Implemented Interfaces:
    HandlerMethodArgumentResolver
  Direct Known Subclasses:
    DestinationVariableMethodArgumentResolver, HeaderMethodArgumentResolver

      public abstract class AbstractNamedValueMethodArgumentResolver
      extends Object
      implements HandlerMethodArgumentResolver

  Abstract base class for resolving method arguments from a named value. Message headers, and path variables are examples of named values. Each may have a name, a required flag, and a default value.

  Subclasses define how to do the following:

  - Obtain named value information for a method parameter
  - Resolve names into argument values
  - Handle missing argument values when argument values are required
  - Optionally handle a resolved value

  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.

  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Nested Class Summary

    Nested Classes
    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.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractNamedValueMethodArgumentResolver(ConversionService cs, ConfigurableBeanFactory beanFactory)` Constructor with a `ConversionService` and a `BeanFactory`.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo` | `createNamedValueInfo(MethodParameter parameter)` Create the `AbstractNamedValueMethodArgumentResolver.NamedValueInfo` object for the given method parameter.
    `protected abstract void` | `handleMissingValue(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.
    `protected void` | `handleResolvedValue(Object arg, String name, MethodParameter parameter, Message<?> message)` Invoked after a value is resolved.
    `Object` | `resolveArgument(MethodParameter parameter, Message<?> message)` Resolves a method parameter into an argument value from a given message.
    `protected abstract Object` | `resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name)` Resolves the given parameter type and value name into an argument value.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver

      `supportsParameter`

- - ### Constructor Detail

    - #### AbstractNamedValueMethodArgumentResolver

          protected AbstractNamedValueMethodArgumentResolver(ConversionService cs,
                                                             ConfigurableBeanFactory beanFactory)

      Constructor with a `ConversionService` and a `BeanFactory`.
      Parameters:
        `cs` - conversion service for converting values to match the target method parameter type
        `beanFactory` - a bean factory to use for resolving `${...}` placeholder and `#{...}` SpEL expressions in default values, or `null` if default values are not expected to contain expressions

  - ### Method Detail

    - #### resolveArgument

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

      Description copied from interface: `HandlerMethodArgumentResolver`
      Resolves a method parameter into an argument value from a given message.
      Specified by:
        `resolveArgument` in interface `HandlerMethodArgumentResolver`
      Parameters:
        `parameter` - the method parameter to resolve. This parameter must have previously been passed to `HandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)` and it must have returned `true`
        `message` - the currently processed message
      Returns:
        the resolved argument value, or `null`.
      Throws:
        `Exception` - in case of errors with the preparation of argument values

    - #### createNamedValueInfo

          protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo createNamedValueInfo(MethodParameter parameter)

      Create the `AbstractNamedValueMethodArgumentResolver.NamedValueInfo` object for the given method parameter. Implementations typically retrieve the method annotation by means of `MethodParameter.getParameterAnnotation(Class)`.
      Parameters:
        `parameter` - the method parameter
      Returns:
        the named value information

    - #### resolveArgumentInternal

          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` - the method parameter to resolve to an argument value
        `message` - the current request
        `name` - the name of the value being resolved
      Returns:
        the resolved argument. May be `null`
      Throws:
        `Exception` - in case of errors

    - #### handleMissingValue

          protected abstract void handleMissingValue(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. Subclasses typically throw an exception in this case.
      Parameters:
        `name` - the name for the value
        `parameter` - the method parameter
        `message` - the message being processed

    - #### handleResolvedValue

          protected void handleResolvedValue(Object arg,
                                             String name,
                                             MethodParameter parameter,
                                             Message<?> message)

      Invoked after a value is resolved.
      Parameters:
        `arg` - the resolved argument value
        `name` - the argument name
        `parameter` - the argument parameter type
        `message` - the message