KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > NoSuchBeanDefinitionException


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.beans.factory;
18
19 import org.springframework.beans.BeansException;
20
21 /**
22  * Exception thrown when a BeanFactory is asked for a bean
23  * instance name for which it cannot find a definition.
24  *
25  * @author Rod Johnson
26  * @author Juergen Hoeller
27  */

28 public class NoSuchBeanDefinitionException extends BeansException {
29
30     /** Name of the missing bean */
31     private String JavaDoc beanName;
32
33     /** Required bean type */
34     private Class JavaDoc beanType;
35
36
37     /**
38      * Create a new NoSuchBeanDefinitionException.
39      * @param name the name of the missing bean
40      */

41     public NoSuchBeanDefinitionException(String JavaDoc name) {
42         super("No bean named '" + name + "' is defined");
43         this.beanName = name;
44     }
45
46     /**
47      * Create a new NoSuchBeanDefinitionException.
48      * @param name the name of the missing bean
49      * @param message further, detailed message describing the problem
50      */

51     public NoSuchBeanDefinitionException(String JavaDoc name, String JavaDoc message) {
52         super("No bean named '" + name + "' is defined: " + message);
53         this.beanName = name;
54     }
55
56     /**
57      * Create a new NoSuchBeanDefinitionException.
58      * @param type required type of bean
59      * @param message further, detailed message describing the problem
60      */

61     public NoSuchBeanDefinitionException(Class JavaDoc type, String JavaDoc message) {
62         super("No unique bean of type [" + type.getName() + "] is defined: " + message);
63         this.beanType = type;
64     }
65
66
67     /**
68      * Return the name of the missing bean,
69      * if it was a lookup by name that failed.
70      */

71     public String JavaDoc getBeanName() {
72         return this.beanName;
73     }
74
75     /**
76      * Return the required type of bean,
77      * if it was a lookup by type that failed.
78      */

79     public Class JavaDoc getBeanType() {
80         return this.beanType;
81     }
82
83 }
84
Popular Tags