001/* 002 * Copyright 2002-2018 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; 018 019import org.springframework.core.MethodParameter; 020 021/** 022 * {@link ServletRequestBindingException} subclass that indicates that a matrix 023 * variable expected in the method parameters of an {@code @RequestMapping} 024 * method is not present among the matrix variables extracted from the URL. 025 * 026 * @author Juergen Hoeller 027 * @since 5.1 028 * @see MissingPathVariableException 029 */ 030@SuppressWarnings("serial") 031public class MissingMatrixVariableException extends ServletRequestBindingException { 032 033 private final String variableName; 034 035 private final MethodParameter parameter; 036 037 038 /** 039 * Constructor for MissingMatrixVariableException. 040 * @param variableName the name of the missing matrix variable 041 * @param parameter the method parameter 042 */ 043 public MissingMatrixVariableException(String variableName, MethodParameter parameter) { 044 super(""); 045 this.variableName = variableName; 046 this.parameter = parameter; 047 } 048 049 050 @Override 051 public String getMessage() { 052 return "Missing matrix variable '" + this.variableName + 053 "' for method parameter of type " + this.parameter.getNestedParameterType().getSimpleName(); 054 } 055 056 /** 057 * Return the expected name of the matrix variable. 058 */ 059 public final String getVariableName() { 060 return this.variableName; 061 } 062 063 /** 064 * Return the method parameter bound to the matrix variable. 065 */ 066 public final MethodParameter getParameter() { 067 return this.parameter; 068 } 069 070}