KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
20  * Interface that defines a registry for shared bean instances.
21  * Can be implemented by {@link org.springframework.beans.factory.BeanFactory}
22  * implementations in order to expose their singleton management facility
23  * in a uniform manner.
24  *
25  * <p>The {@link ConfigurableBeanFactory} interface extends this interface.
26  *
27  * @author Juergen Hoeller
28  * @since 2.0
29  * @see ConfigurableBeanFactory
30  * @see org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
31  * @see org.springframework.beans.factory.support.AbstractBeanFactory
32  */

33 public interface SingletonBeanRegistry {
34
35     /**
36      * Register the given existing object as singleton in the bean registry,
37      * under the given bean name.
38      * <p>The given instance is supposed to be fully initialized; the registry
39      * will not perform any initialization callbacks (in particular, it won't
40      * call InitializingBean's <code>afterPropertiesSet</code> method).
41      * The given instance will not receive any destruction callbacks
42      * (like DisposableBean's <code>destroy</code> method) either.
43      * <p>If running within a full BeanFactory: <b>Register a bean definition
44      * instead of an existing instance if your bean is supposed to receive
45      * initialization and/or destruction callbacks.</b>
46      * <p>Typically invoked during registry configuration, but can also be used
47      * for runtime registration of singletons. As a consequence, a registry
48      * implementation should synchronize singleton access; it will have to do
49      * this anyway if it supports a BeanFactory's lazy initialization of singletons.
50      * @param beanName the name of the bean
51      * @param singletonObject the existing singleton object
52      * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet
53      * @see org.springframework.beans.factory.DisposableBean#destroy
54      * @see org.springframework.beans.factory.support.BeanDefinitionRegistry#registerBeanDefinition
55      */

56     void registerSingleton(String JavaDoc beanName, Object JavaDoc singletonObject);
57
58     /**
59      * Return the (raw) singleton object registered under the given name.
60      * <p>Only checks already instantiated singletons; does not return an Object
61      * for singleton bean definitions which have not been instantiated yet.
62      * <p>The main purpose of this method is to access manually registered singletons
63      * (see {@link #registerSingleton}). Can also be used to access a singleton
64      * defined by a bean definition that already been created, in a raw fashion.
65      * @param beanName the name of the bean to look for
66      * @return the registered singleton object, or <code>null</code> if none found
67      * @see ConfigurableListableBeanFactory#getBeanDefinition
68      */

69     Object JavaDoc getSingleton(String JavaDoc beanName);
70
71     /**
72      * Check if this registry contains a singleton instance with the given name.
73      * <p>Only checks already instantiated singletons; does not return <code>true</code>
74      * for singleton bean definitions which have not been instantiated yet.
75      * <p>The main purpose of this method is to check manually registered singletons
76      * (see {@link #registerSingleton}). Can also be used to check whether a
77      * singleton defined by a bean definition has already been created.
78      * <p>To check whether a bean factory contains a bean definition with a given name,
79      * use ListableBeanFactory's <code>containsBeanDefinition</code>. Calling both
80      * <code>containsBeanDefinition</code> and <code>containsSingleton</code> answers
81      * whether a specific bean factory contains an own bean with the given name.
82      * <p>Use BeanFactory's <code>containsBean</code> for general checks whether the
83      * factory knows about a bean with a given name (whether manually registered singleton
84      * instance or created by bean definition), also checking ancestor factories.
85      * @param beanName the name of the bean to look for
86      * @return if this bean factory contains a singleton instance with the given name
87      * @see #registerSingleton
88      * @see org.springframework.beans.factory.ListableBeanFactory#containsBeanDefinition
89      * @see org.springframework.beans.factory.BeanFactory#containsBean
90      */

91     boolean containsSingleton(String JavaDoc beanName);
92
93     /**
94      * Return the names of singleton beans registered in this registry.
95      * <p>Only checks already instantiated singletons; does not return names
96      * for singleton bean definitions which have not been instantiated yet.
97      * <p>The main purpose of this method is to check manually registered singletons
98      * (see {@link #registerSingleton}). Can also be used to check which
99      * singletons defined by a bean definition have already been created.
100      * @return the list of names as String array (never <code>null</code>)
101      * @see #registerSingleton
102      * @see org.springframework.beans.factory.support.BeanDefinitionRegistry#getBeanDefinitionNames
103      * @see org.springframework.beans.factory.ListableBeanFactory#getBeanDefinitionNames
104      */

105     String JavaDoc[] getSingletonNames();
106
107     /**
108      * Return the number of singleton beans registered in this registry.
109      * <p>Only checks already instantiated singletons; does not count
110      * singleton bean definitions which have not been instantiated yet.
111      * <p>The main purpose of this method is to check manually registered singletons
112      * (see {@link #registerSingleton}). Can also be used to count the number of
113      * singletons defined by a bean definition that have already been created.
114      * @return the number of singleton beans
115      * @see #registerSingleton
116      * @see org.springframework.beans.factory.support.BeanDefinitionRegistry#getBeanDefinitionCount
117      * @see org.springframework.beans.factory.ListableBeanFactory#getBeanDefinitionCount
118      */

119     int getSingletonCount();
120
121 }
122
Popular Tags