001: /*
002: * Copyright 2002-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.beans.factory.config;
018:
019: /**
020: * Interface that defines a registry for shared bean instances.
021: * Can be implemented by {@link org.springframework.beans.factory.BeanFactory}
022: * implementations in order to expose their singleton management facility
023: * in a uniform manner.
024: *
025: * <p>The {@link ConfigurableBeanFactory} interface extends this interface.
026: *
027: * @author Juergen Hoeller
028: * @since 2.0
029: * @see ConfigurableBeanFactory
030: * @see org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
031: * @see org.springframework.beans.factory.support.AbstractBeanFactory
032: */
033: public interface SingletonBeanRegistry {
034:
035: /**
036: * Register the given existing object as singleton in the bean registry,
037: * under the given bean name.
038: * <p>The given instance is supposed to be fully initialized; the registry
039: * will not perform any initialization callbacks (in particular, it won't
040: * call InitializingBean's <code>afterPropertiesSet</code> method).
041: * The given instance will not receive any destruction callbacks
042: * (like DisposableBean's <code>destroy</code> method) either.
043: * <p>If running within a full BeanFactory: <b>Register a bean definition
044: * instead of an existing instance if your bean is supposed to receive
045: * initialization and/or destruction callbacks.</b>
046: * <p>Typically invoked during registry configuration, but can also be used
047: * for runtime registration of singletons. As a consequence, a registry
048: * implementation should synchronize singleton access; it will have to do
049: * this anyway if it supports a BeanFactory's lazy initialization of singletons.
050: * @param beanName the name of the bean
051: * @param singletonObject the existing singleton object
052: * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet
053: * @see org.springframework.beans.factory.DisposableBean#destroy
054: * @see org.springframework.beans.factory.support.BeanDefinitionRegistry#registerBeanDefinition
055: */
056: void registerSingleton(String beanName, Object singletonObject);
057:
058: /**
059: * Return the (raw) singleton object registered under the given name.
060: * <p>Only checks already instantiated singletons; does not return an Object
061: * for singleton bean definitions which have not been instantiated yet.
062: * <p>The main purpose of this method is to access manually registered singletons
063: * (see {@link #registerSingleton}). Can also be used to access a singleton
064: * defined by a bean definition that already been created, in a raw fashion.
065: * @param beanName the name of the bean to look for
066: * @return the registered singleton object, or <code>null</code> if none found
067: * @see ConfigurableListableBeanFactory#getBeanDefinition
068: */
069: Object getSingleton(String beanName);
070:
071: /**
072: * Check if this registry contains a singleton instance with the given name.
073: * <p>Only checks already instantiated singletons; does not return <code>true</code>
074: * for singleton bean definitions which have not been instantiated yet.
075: * <p>The main purpose of this method is to check manually registered singletons
076: * (see {@link #registerSingleton}). Can also be used to check whether a
077: * singleton defined by a bean definition has already been created.
078: * <p>To check whether a bean factory contains a bean definition with a given name,
079: * use ListableBeanFactory's <code>containsBeanDefinition</code>. Calling both
080: * <code>containsBeanDefinition</code> and <code>containsSingleton</code> answers
081: * whether a specific bean factory contains an own bean with the given name.
082: * <p>Use BeanFactory's <code>containsBean</code> for general checks whether the
083: * factory knows about a bean with a given name (whether manually registered singleton
084: * instance or created by bean definition), also checking ancestor factories.
085: * @param beanName the name of the bean to look for
086: * @return if this bean factory contains a singleton instance with the given name
087: * @see #registerSingleton
088: * @see org.springframework.beans.factory.ListableBeanFactory#containsBeanDefinition
089: * @see org.springframework.beans.factory.BeanFactory#containsBean
090: */
091: boolean containsSingleton(String beanName);
092:
093: /**
094: * Return the names of singleton beans registered in this registry.
095: * <p>Only checks already instantiated singletons; does not return names
096: * for singleton bean definitions which have not been instantiated yet.
097: * <p>The main purpose of this method is to check manually registered singletons
098: * (see {@link #registerSingleton}). Can also be used to check which
099: * 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[] 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: }
|