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.beans; 018 019import java.beans.PropertyChangeEvent; 020 021import org.springframework.lang.Nullable; 022 023/** 024 * Superclass for exceptions related to a property access, 025 * such as type mismatch or invocation target exception. 026 * 027 * @author Rod Johnson 028 * @author Juergen Hoeller 029 */ 030@SuppressWarnings("serial") 031public abstract class PropertyAccessException extends BeansException { 032 033 @Nullable 034 private final PropertyChangeEvent propertyChangeEvent; 035 036 037 /** 038 * Create a new PropertyAccessException. 039 * @param propertyChangeEvent the PropertyChangeEvent that resulted in the problem 040 * @param msg the detail message 041 * @param cause the root cause 042 */ 043 public PropertyAccessException(PropertyChangeEvent propertyChangeEvent, String msg, @Nullable Throwable cause) { 044 super(msg, cause); 045 this.propertyChangeEvent = propertyChangeEvent; 046 } 047 048 /** 049 * Create a new PropertyAccessException without PropertyChangeEvent. 050 * @param msg the detail message 051 * @param cause the root cause 052 */ 053 public PropertyAccessException(String msg, @Nullable Throwable cause) { 054 super(msg, cause); 055 this.propertyChangeEvent = null; 056 } 057 058 059 /** 060 * Return the PropertyChangeEvent that resulted in the problem. 061 * <p>May be {@code null}; only available if an actual bean property 062 * was affected. 063 */ 064 @Nullable 065 public PropertyChangeEvent getPropertyChangeEvent() { 066 return this.propertyChangeEvent; 067 } 068 069 /** 070 * Return the name of the affected property, if available. 071 */ 072 @Nullable 073 public String getPropertyName() { 074 return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getPropertyName() : null); 075 } 076 077 /** 078 * Return the affected value that was about to be set, if any. 079 */ 080 @Nullable 081 public Object getValue() { 082 return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getNewValue() : null); 083 } 084 085 /** 086 * Return a corresponding error code for this type of exception. 087 */ 088 public abstract String getErrorCode(); 089 090}