001/*
002 * Copyright 2002-2014 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.method.support;
018
019import org.springframework.core.MethodParameter;
020import org.springframework.lang.Nullable;
021import org.springframework.web.bind.WebDataBinder;
022import org.springframework.web.bind.support.WebDataBinderFactory;
023import org.springframework.web.context.request.NativeWebRequest;
024
025/**
026 * Strategy interface for resolving method parameters into argument values in
027 * the context of a given request.
028 *
029 * @author Arjen Poutsma
030 * @since 3.1
031 * @see HandlerMethodReturnValueHandler
032 */
033public interface HandlerMethodArgumentResolver {
034
035        /**
036         * Whether the given {@linkplain MethodParameter method parameter} is
037         * supported by this resolver.
038         * @param parameter the method parameter to check
039         * @return {@code true} if this resolver supports the supplied parameter;
040         * {@code false} otherwise
041         */
042        boolean supportsParameter(MethodParameter parameter);
043
044        /**
045         * Resolves a method parameter into an argument value from a given request.
046         * A {@link ModelAndViewContainer} provides access to the model for the
047         * request. A {@link WebDataBinderFactory} provides a way to create
048         * a {@link WebDataBinder} instance when needed for data binding and
049         * type conversion purposes.
050         * @param parameter the method parameter to resolve. This parameter must
051         * have previously been passed to {@link #supportsParameter} which must
052         * have returned {@code true}.
053         * @param mavContainer the ModelAndViewContainer for the current request
054         * @param webRequest the current request
055         * @param binderFactory a factory for creating {@link WebDataBinder} instances
056         * @return the resolved argument value, or {@code null} if not resolvable
057         * @throws Exception in case of errors with the preparation of argument values
058         */
059        @Nullable
060        Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer,
061                        NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception;
062
063}