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