KickJava   Java API By Example, From Geeks To Geeks.

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


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.config;
18
19 import org.springframework.beans.BeansException;
20 import org.springframework.beans.factory.BeanFactory;
21
22 /**
23  * Extension of the {@link org.springframework.beans.factory.BeanFactory}
24  * interface to be implemented by bean factories that are capable of
25  * autowiring, provided that they want to expose this functionality for
26  * existing bean instances.
27  *
28  * <p>This subinterface of BeanFactory is not meant to be used in normal
29  * application code: stick to {@link org.springframework.beans.factory.BeanFactory}
30  * or {@link org.springframework.beans.factory.ListableBeanFactory} for
31  * typical use cases.
32  *
33  * <p>Integration code for other frameworks can leverage this interface to
34  * wire and populate existing bean instances that Spring does not control
35  * the lifecycle of. This is particularly useful for WebWork Actions and
36  * Tapestry Page objects, for example.
37  *
38  * <p>Note that this interface is not implemented by
39  * {@link org.springframework.context.ApplicationContext} facades,
40  * as it is hardly ever used by application code. That said, it is available
41  * from an application context too, accessible through ApplicationContext's
42  * {@link org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()}
43  * method.
44  *
45  * <p>You may also implement the {@link org.springframework.beans.factory.BeanFactoryAware}
46  * interface, which exposes the internal BeanFactory even when running in an
47  * ApplicationContext, to get access to an AutowireCapableBeanFactory:
48  * simply cast the passed-in BeanFactory to AutowireCapableBeanFactory.
49  *
50  * @author Juergen Hoeller
51  * @since 04.12.2003
52  * @see org.springframework.beans.factory.BeanFactoryAware
53  * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory
54  * @see org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()
55  */

56 public interface AutowireCapableBeanFactory extends BeanFactory {
57
58     /**
59      * Constant that indicates no autowiring at all
60      * (other than callbacks such as BeanFactoryAware).
61      * @see #createBean
62      * @see #autowire
63      * @see #autowireBeanProperties
64      */

65     int AUTOWIRE_NO = 0;
66
67     /**
68      * Constant that indicates autowiring bean properties by name.
69      * @see #createBean
70      * @see #autowire
71      * @see #autowireBeanProperties
72      */

73     int AUTOWIRE_BY_NAME = 1;
74
75     /**
76      * Constant that indicates autowiring bean properties by type.
77      * @see #createBean
78      * @see #autowire
79      * @see #autowireBeanProperties
80      */

81     int AUTOWIRE_BY_TYPE = 2;
82
83     /**
84      * Constant that indicates autowiring a constructor.
85      * @see #createBean
86      * @see #autowire
87      */

88     int AUTOWIRE_CONSTRUCTOR = 3;
89
90     /**
91      * Constant that indicates determining an appropriate autowire strategy
92      * through introspection of the bean class.
93      * @see #createBean
94      * @see #autowire
95      */

96     int AUTOWIRE_AUTODETECT = 4;
97
98
99     /**
100      * Fully create a new bean instance of the given class with the specified
101      * autowire strategy. All constants defined in this interface are supported here.
102      * <p>Performs full initialization of the bean, including all applicable
103      * {@link BeanPostProcessor BeanPostProcessors}.
104      * @param beanClass the class of the bean to create
105      * @param autowireMode by name or type, using the constants in this interface
106      * @param dependencyCheck whether to perform a dependency check for objects
107      * (not applicable to autowiring a constructor, thus ignored there)
108      * @return the new bean instance
109      * @throws BeansException if instantiation or wiring failed
110      * @see #AUTOWIRE_NO
111      * @see #AUTOWIRE_BY_NAME
112      * @see #AUTOWIRE_BY_TYPE
113      * @see #AUTOWIRE_CONSTRUCTOR
114      * @see #AUTOWIRE_AUTODETECT
115      */

116     Object JavaDoc createBean(Class JavaDoc beanClass, int autowireMode, boolean dependencyCheck)
117             throws BeansException;
118
119     /**
120      * Instantiate a new bean instance of the given class with the specified autowire
121      * strategy. All constants defined in this interface are supported here.
122      * <p>Does <i>not</i> apply any {@link BeanPostProcessor BeanPostProcessors} or
123      * perform any further initialization of the bean. This interface offers distinct,
124      * fine-grained operations for those purposes, for example {@link #initializeBean}.
125      * @param beanClass the class of the bean to instantiate
126      * @param autowireMode by name or type, using the constants in this interface
127      * @param dependencyCheck whether to perform a dependency check for object
128      * references in the bean instance (not applicable to autowiring a constructor,
129      * thus ignored there)
130      * @return the new bean instance
131      * @throws BeansException if instantiation or wiring failed
132      * @see #AUTOWIRE_NO
133      * @see #AUTOWIRE_BY_NAME
134      * @see #AUTOWIRE_BY_TYPE
135      * @see #AUTOWIRE_CONSTRUCTOR
136      * @see #AUTOWIRE_AUTODETECT
137      * @see #initializeBean
138      * @see #applyBeanPostProcessorsBeforeInitialization
139      * @see #applyBeanPostProcessorsAfterInitialization
140      */

141     Object JavaDoc autowire(Class JavaDoc beanClass, int autowireMode, boolean dependencyCheck)
142             throws BeansException;
143
144     /**
145      * Autowire the bean properties of the given bean instance by name or type.
146      * @param existingBean the existing bean instance
147      * @param autowireMode by name or type, using the constants in this interface
148      * @param dependencyCheck whether to perform a dependency check for object
149      * references in the bean instance
150      * @throws BeansException if wiring failed
151      * @see #AUTOWIRE_BY_NAME
152      * @see #AUTOWIRE_BY_TYPE
153      */

154     void autowireBeanProperties(Object JavaDoc existingBean, int autowireMode, boolean dependencyCheck)
155             throws BeansException;
156
157     /**
158      * Apply the property values of the bean definition with the given name
159      * to the given bean instance. The bean definition can either define a
160      * fully self-contained bean, reusing its property values, or just
161      * property values meant to be used for existing bean instances.
162      * <p>Note: This method does <i>not</i> autowire bean properties;
163      * it just applies explicitly defined property values.
164      * Use the {@link #autowireBeanProperties} method to autowire
165      * an existing bean instance.
166      * @param existingBean the existing bean instance
167      * @param beanName the name of the bean definition in the bean factory
168      * (a bean definition of that name has to be available)
169      * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
170      * if there is no bean with the given name
171      * @throws BeansException if applying the property values failed
172      * @see #autowireBeanProperties
173      */

174     void applyBeanPropertyValues(Object JavaDoc existingBean, String JavaDoc beanName) throws BeansException;
175
176     /**
177      * Configure the given bean instance: autowiring bean properties, applying
178      * bean property values, applying factory callbacks such as <code>setBeanName</code>
179      * and <code>setBeanFactory</code>, and also applying all bean post processors.
180      * <p>This is effectively a superset of what <code>initializeBean</code>
181      * provides, fully applying the configuration specified by the corresponding
182      * bean definition.
183      * @param existingBean the existing bean instance
184      * @param beanName the name of the bean, to be passed to it if necessary
185      * (a bean definition of that name has to be available)
186      * @return the bean instance to use, either the original or a wrapped one
187      * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
188      * if there is no bean with the given name
189      * @throws BeansException if the initialization failed
190      * @see #initializeBean
191      */

192     Object JavaDoc configureBean(Object JavaDoc existingBean, String JavaDoc beanName) throws BeansException;
193
194     /**
195      * Initialize the given bean instance, applying factory callbacks
196      * such as <code>setBeanName</code> and <code>setBeanFactory</code>,
197      * also applying all bean post processors.
198      * <p>Note that no bean definition of the given name has to exist
199      * in the bean factory. The passed-in bean name will simply be used
200      * for callbacks but not checked against the registered bean definitions.
201      * @param existingBean the existing bean instance
202      * @param beanName the name of the bean, to be passed to it if necessary
203      * (only passed to {@link BeanPostProcessor BeanPostProcessors})
204      * @return the bean instance to use, either the original or a wrapped one
205      * @throws BeansException if the initialization failed
206      */

207     Object JavaDoc initializeBean(Object JavaDoc existingBean, String JavaDoc beanName) throws BeansException;
208
209     /**
210      * Apply {@link BeanPostProcessor BeanPostProcessors} to the given existing bean
211      * instance, invoking their <code>postProcessBeforeInitialization</code> methods.
212      * The returned bean instance may be a wrapper around the original.
213      * @param existingBean the new bean instance
214      * @param beanName the name of the bean
215      * @return the bean instance to use, either the original or a wrapped one
216      * @throws BeansException if any post-processing failed
217      * @see BeanPostProcessor#postProcessBeforeInitialization
218      */

219     Object JavaDoc applyBeanPostProcessorsBeforeInitialization(Object JavaDoc existingBean, String JavaDoc beanName)
220             throws BeansException;
221
222     /**
223      * Apply {@link BeanPostProcessor BeanPostProcessors} to the given existing bean
224      * instance, invoking their <code>postProcessAfterInitialization</code> methods.
225      * The returned bean instance may be a wrapper around the original.
226      * @param existingBean the new bean instance
227      * @param beanName the name of the bean
228      * @return the bean instance to use, either the original or a wrapped one
229      * @throws BeansException if any post-processing failed
230      * @see BeanPostProcessor#postProcessAfterInitialization
231      */

232     Object JavaDoc applyBeanPostProcessorsAfterInitialization(Object JavaDoc existingBean, String JavaDoc beanName)
233             throws BeansException;
234
235 }
236
Popular Tags