001/* 002 * Copyright 2002-2012 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.bind.support; 018 019import org.springframework.core.MethodParameter; 020import org.springframework.web.context.request.NativeWebRequest; 021 022/** 023 * SPI for resolving custom arguments for a specific handler method parameter. 024 * Typically implemented to detect special parameter types, resolving 025 * well-known argument values for them. 026 * 027 * <p>A typical implementation could look like as follows: 028 * 029 * <pre class="code"> 030 * public class MySpecialArgumentResolver implements WebArgumentResolver { 031 * 032 * public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) { 033 * if (methodParameter.getParameterType().equals(MySpecialArg.class)) { 034 * return new MySpecialArg("myValue"); 035 * } 036 * return UNRESOLVED; 037 * } 038 * }</pre> 039 * 040 * @author Juergen Hoeller 041 * @since 2.5.2 042 * @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#setCustomArgumentResolvers 043 * @see org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter#setCustomArgumentResolvers 044 */ 045public interface WebArgumentResolver { 046 047 /** 048 * Marker to be returned when the resolver does not know how to 049 * handle the given method parameter. 050 */ 051 Object UNRESOLVED = new Object(); 052 053 054 /** 055 * Resolve an argument for the given handler method parameter within the given web request. 056 * @param methodParameter the handler method parameter to resolve 057 * @param webRequest the current web request, allowing access to the native request as well 058 * @return the argument value, or {@code UNRESOLVED} if not resolvable 059 * @throws Exception in case of resolution failure 060 */ 061 Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception; 062 063}