KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Thrown when a bean doesn't match the expected type.
23  *
24  * @author Rod Johnson
25  * @author Juergen Hoeller
26  */

27 public class BeanNotOfRequiredTypeException extends BeansException {
28
29     /** The name of the instance that was of the wrong type */
30     private String JavaDoc beanName;
31
32     /** The required type */
33     private Class JavaDoc requiredType;
34
35     /** The offending type */
36     private Class JavaDoc actualType;
37
38
39     /**
40      * Create a new BeanNotOfRequiredTypeException.
41      * @param beanName the name of the bean requested
42      * @param requiredType the required type
43      * @param actualType the actual type returned, which did not match
44      * the expected type
45      */

46     public BeanNotOfRequiredTypeException(String JavaDoc beanName, Class JavaDoc requiredType, Class JavaDoc actualType) {
47         super("Bean named '" + beanName + "' must be of type [" + requiredType.getName() +
48                 "], but was actually of type [" + actualType.getName() + "]");
49         this.beanName = beanName;
50         this.requiredType = requiredType;
51         this.actualType = actualType;
52     }
53
54
55     /**
56      * Return the name of the instance that was of the wrong type.
57      */

58     public String JavaDoc getBeanName() {
59         return this.beanName;
60     }
61
62     /**
63      * Return the expected type for the bean.
64      */

65     public Class JavaDoc getRequiredType() {
66         return this.requiredType;
67     }
68
69     /**
70      * Return the actual type of the instance found.
71      */

72     public Class JavaDoc getActualType() {
73         return this.actualType;
74     }
75
76 }
77
Popular Tags