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.factory;
018
019import org.springframework.beans.FatalBeanException;
020
021/**
022 * Exception thrown when a BeanFactory encounters an invalid bean definition:
023 * e.g. in case of incomplete or contradictory bean metadata.
024 *
025 * @author Rod Johnson
026 * @author Juergen Hoeller
027 * @author Rob Harrop
028 */
029@SuppressWarnings("serial")
030public class BeanDefinitionStoreException extends FatalBeanException {
031
032        private String resourceDescription;
033
034        private String beanName;
035
036
037        /**
038         * Create a new BeanDefinitionStoreException.
039         * @param msg the detail message (used as exception message as-is)
040         */
041        public BeanDefinitionStoreException(String msg) {
042                super(msg);
043        }
044
045        /**
046         * Create a new BeanDefinitionStoreException.
047         * @param msg the detail message (used as exception message as-is)
048         * @param cause the root cause (may be {@code null})
049         */
050        public BeanDefinitionStoreException(String msg, Throwable cause) {
051                super(msg, cause);
052        }
053
054        /**
055         * Create a new BeanDefinitionStoreException.
056         * @param resourceDescription description of the resource that the bean definition came from
057         * @param msg the detail message (used as exception message as-is)
058         */
059        public BeanDefinitionStoreException(String resourceDescription, String msg) {
060                super(msg);
061                this.resourceDescription = resourceDescription;
062        }
063
064        /**
065         * Create a new BeanDefinitionStoreException.
066         * @param resourceDescription description of the resource that the bean definition came from
067         * @param msg the detail message (used as exception message as-is)
068         * @param cause the root cause (may be {@code null})
069         */
070        public BeanDefinitionStoreException(String resourceDescription, String msg, Throwable cause) {
071                super(msg, cause);
072                this.resourceDescription = resourceDescription;
073        }
074
075        /**
076         * Create a new BeanDefinitionStoreException.
077         * @param resourceDescription description of the resource that the bean definition came from
078         * @param beanName the name of the bean
079         * @param msg the detail message (appended to an introductory message that indicates
080         * the resource and the name of the bean)
081         */
082        public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg) {
083                this(resourceDescription, beanName, msg, null);
084        }
085
086        /**
087         * Create a new BeanDefinitionStoreException.
088         * @param resourceDescription description of the resource that the bean definition came from
089         * @param beanName the name of the bean
090         * @param msg the detail message (appended to an introductory message that indicates
091         * the resource and the name of the bean)
092         * @param cause the root cause (may be {@code null})
093         */
094        public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg, Throwable cause) {
095                super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg,
096                                cause);
097                this.resourceDescription = resourceDescription;
098                this.beanName = beanName;
099        }
100
101
102        /**
103         * Return the description of the resource that the bean definition came from, if available.
104         */
105        public String getResourceDescription() {
106                return this.resourceDescription;
107        }
108
109        /**
110         * Return the name of the bean, if available.
111         */
112        public String getBeanName() {
113                return this.beanName;
114        }
115
116}