KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.beans.PropertyEditor JavaDoc;
20
21 import org.springframework.beans.PropertyEditorRegistrar;
22 import org.springframework.beans.TypeConverter;
23 import org.springframework.beans.factory.BeanDefinitionStoreException;
24 import org.springframework.beans.factory.BeanFactory;
25 import org.springframework.beans.factory.HierarchicalBeanFactory;
26
27 /**
28  * Configuration interface to be implemented by most bean factories. Provides
29  * facilities to configure a bean factory, in addition to the bean factory
30  * client methods in the {@link org.springframework.beans.factory.BeanFactory}
31  * interface.
32  *
33  * <p>This bean factory interface is not meant to be used in normal application
34  * code: Stick to {@link org.springframework.beans.factory.BeanFactory} or
35  * {@link org.springframework.beans.factory.ListableBeanFactory} for typical
36  * needs. This extended interface is just meant to allow for framework-internal
37  * plug'n'play and for special access to bean factory configuration methods.
38  *
39  * @author Juergen Hoeller
40  * @since 03.11.2003
41  * @see org.springframework.beans.factory.BeanFactory
42  * @see org.springframework.beans.factory.ListableBeanFactory
43  * @see ConfigurableListableBeanFactory
44  */

45 public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, SingletonBeanRegistry {
46
47     /**
48      * Scope identifier for the standard singleton scope: "singleton".
49      * Custom scopes can be added via <code>registerScope</code>.
50      * @see #registerScope
51      */

52     String JavaDoc SCOPE_SINGLETON = "singleton";
53
54     /**
55      * Scope identifier for the standard prototype scope: "prototype".
56      * Custom scopes can be added via <code>registerScope</code>.
57      * @see #registerScope
58      */

59     String JavaDoc SCOPE_PROTOTYPE = "prototype";
60
61
62     /**
63      * Set the parent of this bean factory.
64      * <p>Note that the parent cannot be changed: It should only be set outside
65      * a constructor if it isn't available at the time of factory instantiation.
66      * @param parentBeanFactory the parent BeanFactory
67      * @throws IllegalStateException if this factory is already associated with
68      * a parent BeanFactory
69      * @see #getParentBeanFactory()
70      */

71     void setParentBeanFactory(BeanFactory parentBeanFactory) throws IllegalStateException JavaDoc;
72
73     /**
74      * Set the class loader to use for loading bean classes.
75      * Default is the thread context class loader.
76      * <p>Note that this class loader will only apply to bean definitions
77      * that do not carry a resolved bean class yet. This is the case as of
78      * Spring 2.0 by default: Bean definitions only carry bean class names,
79      * to be resolved once the factory processes the bean definition.
80      * @param beanClassLoader the class loader to use,
81      * or <code>null</code> to suggest the default class loader
82      */

83     void setBeanClassLoader(ClassLoader JavaDoc beanClassLoader);
84
85     /**
86      * Return this factory's class loader for loading bean classes.
87      */

88     ClassLoader JavaDoc getBeanClassLoader();
89
90     /**
91      * Set whether to cache bean metadata such as given bean definitions
92      * (in merged fashion) and resolved bean classes. Default is on.
93      * <p>Turn this flag off to enable hot-refreshing of bean definition objects
94      * and in particular bean classes. If this flag is off, any creation of a bean
95      * instance will re-query the bean class loader for newly resolved classes.
96      */

97     void setCacheBeanMetadata(boolean cacheBeanMetadata);
98
99     /**
100      * Return whether to cache bean metadata such as given bean definitions
101      * (in merged fashion) and resolved bean classes.
102      */

103     boolean isCacheBeanMetadata();
104
105     /**
106      * Add a PropertyEditorRegistrar to be applied to all bean creation processes.
107      * <p>Such a registrar creates new PropertyEditor instances and registers them
108      * on the given registry, fresh for each bean creation attempt. This avoids
109      * the need for synchronization on custom editors; hence, it is generally
110      * preferable to use this method instead of <code>registerCustomEditor</code>.
111      * @param registrar the PropertyEditorRegistrar to register
112      * @see #registerCustomEditor
113      */

114     void addPropertyEditorRegistrar(PropertyEditorRegistrar registrar);
115
116     /**
117      * Register the given custom property editor for all properties of the
118      * given type. To be invoked during factory configuration.
119      * <p>Note that this method will register a shared custom editor instance;
120      * access to that instance will be synchronized for thread-safety. It is
121      * generally prefable to use <code>addPropertyEditorRegistrar</code> instead
122      * of this method, to avoid for the need for synchronization on custom editors.
123      * @param requiredType type of the property
124      * @param propertyEditor editor to register
125      * @see #addPropertyEditorRegistrar
126      */

127     void registerCustomEditor(Class JavaDoc requiredType, PropertyEditor JavaDoc propertyEditor);
128
129     /**
130      * Obtain a type converter as used by this BeanFactory. This is typically a fresh
131      * instance for each call, since TypeConverters are usually <i>not</i> thread-safe.
132      */

133     TypeConverter getTypeConverter();
134
135     /**
136      * Add a new BeanPostProcessor that will get applied to beans created
137      * by this factory. To be invoked during factory configuration.
138      * @param beanPostProcessor the bean processor to register
139      */

140     void addBeanPostProcessor(BeanPostProcessor beanPostProcessor);
141
142     /**
143      * Return the current number of registered BeanPostProcessors, if any.
144      */

145     int getBeanPostProcessorCount();
146
147     /**
148      * Register the given scope, backed by the given Scope implementation.
149      * @param scopeName the scope identifier
150      * @param scope the backing Scope implementation
151      */

152     void registerScope(String JavaDoc scopeName, Scope scope);
153
154     /**
155      * Return the names of all currently registered scopes.
156      * <p>This will only return the names of explicitly registered scopes.
157      * Built-in scopes such as "singleton" and "prototype" won't be exposed.
158      * @return the array of scope names, or an empty array if none
159      * @see #registerScope
160      */

161     String JavaDoc[] getRegisteredScopeNames();
162
163     /**
164      * Return the Scope implementation for the given scope name, if any.
165      * <p>This will only return explicitly registered scopes.
166      * Built-in scopes such as "singleton" and "prototype" won't be exposed.
167      * @param scopeName the name of the scope
168      * @return the registered Scope implementation, or <code>null</code> if none
169      * @see #registerScope
170      */

171     Scope getRegisteredScope(String JavaDoc scopeName);
172
173     /**
174      * Copy all relevant configuration from the given other factory.
175      * <p>Should include all standard configuration settings as well as
176      * BeanPostProcessors, Scopes, and factory-specific internal settings.
177      * Should not include any metadata of actual bean definitions,
178      * such as BeanDefinition objects and bean name aliases.
179      * @param otherFactory the other BeanFactory to copy from
180      */

181     void copyConfigurationFrom(ConfigurableBeanFactory otherFactory);
182
183     /**
184      * Given a bean name, create an alias. We typically use this method to
185      * support names that are illegal within XML ids (used for bean names).
186      * <p>Typically invoked during factory configuration, but can also be
187      * used for runtime registration of aliases. Therefore, a factory
188      * implementation should synchronize alias access.
189      * @param beanName the canonical name of the bean
190      * @param alias the alias to be registered for the bean
191      * @throws BeanDefinitionStoreException if the alias is already in use
192      */

193     void registerAlias(String JavaDoc beanName, String JavaDoc alias) throws BeanDefinitionStoreException;
194
195     /**
196      * Return whether the specified bean is currently in creation.
197      * @param beanName the name of the bean
198      */

199     boolean isCurrentlyInCreation(String JavaDoc beanName);
200
201     /**
202      * Destroy the given bean instance (usually a prototype instance
203      * obtained from this factory) according to its bean definition.
204      * <p>Any exception that arises during destruction should be caught
205      * and logged instead of propagated to the caller of this method.
206      * @param beanName the name of the bean definition
207      * @param beanInstance the bean instance to destroy
208      */

209     void destroyBean(String JavaDoc beanName, Object JavaDoc beanInstance);
210
211     /**
212      * Destroy the specified scoped bean in the current target scope, if any.
213      * <p>Any exception that arises during destruction should be caught
214      * and logged instead of propagated to the caller of this method.
215      * @param beanName the name of the scoped bean
216      */

217     void destroyScopedBean(String JavaDoc beanName);
218
219     /**
220      * Destroy all singleton beans in this factory, including inner beans that have
221      * been registered as disposable. To be called on shutdown of a factory.
222      * <p>Any exception that arises during destruction should be caught
223      * and logged instead of propagated to the caller of this method.
224      */

225     void destroySingletons();
226
227 }
228
Popular Tags