001: /*
002: * Copyright 2002-2007 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: * http://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:
017: package org.springframework.beans.factory;
018:
019: import org.springframework.beans.FatalBeanException;
020:
021: /**
022: * Exception thrown when a BeanFactory encounters an error when
023: * attempting to create a bean from a bean definition.
024: *
025: * @author Juergen Hoeller
026: */
027: public class BeanCreationException extends FatalBeanException {
028:
029: private String beanName;
030:
031: private String resourceDescription;
032:
033: /**
034: * Create a new BeanCreationException.
035: * @param msg the detail message
036: */
037: public BeanCreationException(String msg) {
038: super (msg);
039: }
040:
041: /**
042: * Create a new BeanCreationException.
043: * @param msg the detail message
044: * @param cause the root cause
045: */
046: public BeanCreationException(String msg, Throwable cause) {
047: super (msg, cause);
048: }
049:
050: /**
051: * Create a new BeanCreationException.
052: * @param beanName the name of the bean requested
053: * @param msg the detail message
054: */
055: public BeanCreationException(String beanName, String msg) {
056: this (beanName, msg, (Throwable) null);
057: }
058:
059: /**
060: * Create a new BeanCreationException.
061: * @param beanName the name of the bean requested
062: * @param msg the detail message
063: * @param cause the root cause
064: */
065: public BeanCreationException(String beanName, String msg,
066: Throwable cause) {
067: super ("Error creating bean with name '" + beanName + "': "
068: + msg, cause);
069: this .beanName = beanName;
070: }
071:
072: /**
073: * Create a new BeanCreationException.
074: * @param resourceDescription description of the resource
075: * that the bean definition came from
076: * @param beanName the name of the bean requested
077: * @param msg the detail message
078: */
079: public BeanCreationException(String resourceDescription,
080: String beanName, String msg) {
081: this (resourceDescription, beanName, msg, null);
082: }
083:
084: /**
085: * Create a new BeanCreationException.
086: * @param resourceDescription description of the resource
087: * that the bean definition came from
088: * @param beanName the name of the bean requested
089: * @param msg the detail message
090: * @param cause the root cause
091: */
092: public BeanCreationException(String resourceDescription,
093: String beanName, String msg, Throwable cause) {
094: super ("Error creating bean with name '"
095: + beanName
096: + "'"
097: + (resourceDescription != null ? " defined in "
098: + resourceDescription : "") + ": " + msg, cause);
099: this .resourceDescription = resourceDescription;
100: this .beanName = beanName;
101: }
102:
103: /**
104: * Return the name of the bean requested, if any.
105: */
106: public String getBeanName() {
107: return this .beanName;
108: }
109:
110: /**
111: * Return the description of the resource that the bean
112: * definition came from, if any.
113: */
114: public String getResourceDescription() {
115: return this.resourceDescription;
116: }
117:
118: }
|