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 org.springframework.lang.Nullable;
020
021/**
022 * Exception thrown when referring to an invalid bean property.
023 * Carries the offending bean class and property name.
024 *
025 * @author Juergen Hoeller
026 * @since 1.0.2
027 */
028@SuppressWarnings("serial")
029public class InvalidPropertyException extends FatalBeanException {
030
031        private final Class<?> beanClass;
032
033        private final String propertyName;
034
035
036        /**
037         * Create a new InvalidPropertyException.
038         * @param beanClass the offending bean class
039         * @param propertyName the offending property
040         * @param msg the detail message
041         */
042        public InvalidPropertyException(Class<?> beanClass, String propertyName, String msg) {
043                this(beanClass, propertyName, msg, null);
044        }
045
046        /**
047         * Create a new InvalidPropertyException.
048         * @param beanClass the offending bean class
049         * @param propertyName the offending property
050         * @param msg the detail message
051         * @param cause the root cause
052         */
053        public InvalidPropertyException(Class<?> beanClass, String propertyName, String msg, @Nullable Throwable cause) {
054                super("Invalid property '" + propertyName + "' of bean class [" + beanClass.getName() + "]: " + msg, cause);
055                this.beanClass = beanClass;
056                this.propertyName = propertyName;
057        }
058
059        /**
060         * Return the offending bean class.
061         */
062        public Class<?> getBeanClass() {
063                return this.beanClass;
064        }
065
066        /**
067         * Return the name of the offending property.
068         */
069        public String getPropertyName() {
070                return this.propertyName;
071        }
072
073}