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.beans; 018 019/** 020 * Exception thrown on an attempt to set the value of a property that 021 * is not writable (typically because there is no setter method). 022 * 023 * @author Rod Johnson 024 * @author Alef Arendsen 025 * @author Arjen Poutsma 026 */ 027@SuppressWarnings("serial") 028public class NotWritablePropertyException extends InvalidPropertyException { 029 030 private String[] possibleMatches = null; 031 032 033 /** 034 * Create a new NotWritablePropertyException. 035 * @param beanClass the offending bean class 036 * @param propertyName the offending property name 037 */ 038 public NotWritablePropertyException(Class<?> beanClass, String propertyName) { 039 super(beanClass, propertyName, 040 "Bean property '" + propertyName + "' is not writable or has an invalid setter method: " + 041 "Does the return type of the getter match the parameter type of the setter?"); 042 } 043 044 /** 045 * Create a new NotWritablePropertyException. 046 * @param beanClass the offending bean class 047 * @param propertyName the offending property name 048 * @param msg the detail message 049 */ 050 public NotWritablePropertyException(Class<?> beanClass, String propertyName, String msg) { 051 super(beanClass, propertyName, msg); 052 } 053 054 /** 055 * Create a new NotWritablePropertyException. 056 * @param beanClass the offending bean class 057 * @param propertyName the offending property name 058 * @param msg the detail message 059 * @param cause the root cause 060 */ 061 public NotWritablePropertyException(Class<?> beanClass, String propertyName, String msg, Throwable cause) { 062 super(beanClass, propertyName, msg, cause); 063 } 064 065 /** 066 * Create a new NotWritablePropertyException. 067 * @param beanClass the offending bean class 068 * @param propertyName the offending property name 069 * @param msg the detail message 070 * @param possibleMatches suggestions for actual bean property names 071 * that closely match the invalid property name 072 */ 073 public NotWritablePropertyException(Class<?> beanClass, String propertyName, String msg, String[] possibleMatches) { 074 super(beanClass, propertyName, msg); 075 this.possibleMatches = possibleMatches; 076 } 077 078 079 /** 080 * Return suggestions for actual bean property names that closely match 081 * the invalid property name, if any. 082 */ 083 public String[] getPossibleMatches() { 084 return this.possibleMatches; 085 } 086 087}