01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 beanName;
31:
32: /** The required type */
33: private Class requiredType;
34:
35: /** The offending type */
36: private Class actualType;
37:
38: /**
39: * Create a new BeanNotOfRequiredTypeException.
40: * @param beanName the name of the bean requested
41: * @param requiredType the required type
42: * @param actualType the actual type returned, which did not match
43: * the expected type
44: */
45: public BeanNotOfRequiredTypeException(String beanName,
46: Class requiredType, Class actualType) {
47: super ("Bean named '" + beanName + "' must be of type ["
48: + requiredType.getName()
49: + "], but was actually of type ["
50: + actualType.getName() + "]");
51: this .beanName = beanName;
52: this .requiredType = requiredType;
53: this .actualType = actualType;
54: }
55:
56: /**
57: * Return the name of the instance that was of the wrong type.
58: */
59: public String getBeanName() {
60: return this .beanName;
61: }
62:
63: /**
64: * Return the expected type for the bean.
65: */
66: public Class getRequiredType() {
67: return this .requiredType;
68: }
69:
70: /**
71: * Return the actual type of the instance found.
72: */
73: public Class getActualType() {
74: return this.actualType;
75: }
76:
77: }
|