KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > config > RuntimeBeanReference


1 /*
2  * Copyright 2002-2006 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.config;
18
19 import org.springframework.util.Assert;
20
21 /**
22  * Immutable placeholder class used for a property value object when it's
23  * a reference to another bean in the factory, to be resolved at runtime.
24  *
25  * @author Rod Johnson
26  * @author Juergen Hoeller
27  * @see BeanDefinition#getPropertyValues()
28  * @see org.springframework.beans.factory.BeanFactory#getBean
29  */

30 public class RuntimeBeanReference implements BeanReference {
31     
32     private final String JavaDoc beanName;
33
34     private final boolean toParent;
35
36     private Object JavaDoc source;
37
38
39     /**
40      * Create a new RuntimeBeanReference to the given bean name,
41      * without explicitly marking it as reference to a bean in
42      * the parent factory.
43      * @param beanName name of the target bean
44      */

45     public RuntimeBeanReference(String JavaDoc beanName) {
46         this(beanName, false);
47     }
48
49     /**
50      * Create a new RuntimeBeanReference to the given bean name,
51      * with the option to mark it as reference to a bean in
52      * the parent factory.
53      * @param beanName name of the target bean
54      * @param toParent whether this is an explicit reference to
55      * a bean in the parent factory
56      */

57     public RuntimeBeanReference(String JavaDoc beanName, boolean toParent) {
58         Assert.hasText(beanName, "'beanName' must not be empty");
59         this.beanName = beanName;
60         this.toParent = toParent;
61     }
62
63
64     public String JavaDoc getBeanName() {
65         return beanName;
66     }
67
68     /**
69      * Return whether this is an explicit reference to a bean
70      * in the parent factory.
71      */

72     public boolean isToParent() {
73         return toParent;
74     }
75
76     /**
77      * Set the configuration source <code>Object</code> for this metadata element.
78      * <p>The exact type of the object will depend on the configuration mechanism used.
79      */

80     public void setSource(Object JavaDoc source) {
81         this.source = source;
82     }
83
84     public Object JavaDoc getSource() {
85         return source;
86     }
87
88
89     public boolean equals(Object JavaDoc other) {
90         if (this == other) {
91             return true;
92         }
93         if (!(other instanceof RuntimeBeanReference)) {
94             return false;
95         }
96         RuntimeBeanReference that = (RuntimeBeanReference) other;
97         return (this.beanName.equals(that.beanName) && this.toParent == that.toParent);
98     }
99
100     public int hashCode() {
101         int result = this.beanName.hashCode();
102         result = 29 * result + (this.toParent ? 1 : 0);
103         return result;
104     }
105
106     public String JavaDoc toString() {
107        return '<' + getBeanName() + '>';
108     }
109
110 }
111
Popular Tags