01: /*
02: * Copyright 2002-2006 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.config;
18:
19: import org.springframework.util.Assert;
20:
21: /**
22: * Immutable placeholder class used for a property value object when it's a
23: * reference to another bean name in the factory, to be resolved at runtime.
24: *
25: * @author Juergen Hoeller
26: * @since 2.0
27: * @see RuntimeBeanReference
28: * @see BeanDefinition#getPropertyValues()
29: * @see org.springframework.beans.factory.BeanFactory#getBean
30: */
31: public class RuntimeBeanNameReference implements BeanReference {
32:
33: private final String beanName;
34:
35: private Object source;
36:
37: /**
38: * Create a new RuntimeBeanNameReference to the given bean name.
39: * @param beanName name of the target bean
40: */
41: public RuntimeBeanNameReference(String beanName) {
42: Assert.hasText(beanName, "'beanName' must not be empty");
43: this .beanName = beanName;
44: }
45:
46: public String getBeanName() {
47: return beanName;
48: }
49:
50: /**
51: * Set the configuration source <code>Object</code> for this metadata element.
52: * <p>The exact type of the object will depend on the configuration mechanism used.
53: */
54: public void setSource(Object source) {
55: this .source = source;
56: }
57:
58: public Object getSource() {
59: return source;
60: }
61:
62: public boolean equals(Object other) {
63: if (this == other) {
64: return true;
65: }
66: if (!(other instanceof RuntimeBeanNameReference)) {
67: return false;
68: }
69: RuntimeBeanNameReference that = (RuntimeBeanNameReference) other;
70: return this .beanName.equals(that.beanName);
71: }
72:
73: public int hashCode() {
74: return this .beanName.hashCode();
75: }
76:
77: public String toString() {
78: return '<' + getBeanName() + '>';
79: }
80:
81: }
|