001/* 002 * Copyright 2002-2018 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 * https://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 017package org.springframework.beans.factory.support; 018 019import org.springframework.beans.factory.BeanDefinitionStoreException; 020import org.springframework.beans.factory.NoSuchBeanDefinitionException; 021import org.springframework.beans.factory.config.BeanDefinition; 022import org.springframework.core.AliasRegistry; 023 024/** 025 * Interface for registries that hold bean definitions, for example RootBeanDefinition 026 * and ChildBeanDefinition instances. Typically implemented by BeanFactories that 027 * internally work with the AbstractBeanDefinition hierarchy. 028 * 029 * <p>This is the only interface in Spring's bean factory packages that encapsulates 030 * <i>registration</i> of bean definitions. The standard BeanFactory interfaces 031 * only cover access to a <i>fully configured factory instance</i>. 032 * 033 * <p>Spring's bean definition readers expect to work on an implementation of this 034 * interface. Known implementors within the Spring core are DefaultListableBeanFactory 035 * and GenericApplicationContext. 036 * 037 * @author Juergen Hoeller 038 * @since 26.11.2003 039 * @see org.springframework.beans.factory.config.BeanDefinition 040 * @see AbstractBeanDefinition 041 * @see RootBeanDefinition 042 * @see ChildBeanDefinition 043 * @see DefaultListableBeanFactory 044 * @see org.springframework.context.support.GenericApplicationContext 045 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader 046 * @see PropertiesBeanDefinitionReader 047 */ 048public interface BeanDefinitionRegistry extends AliasRegistry { 049 050 /** 051 * Register a new bean definition with this registry. 052 * Must support RootBeanDefinition and ChildBeanDefinition. 053 * @param beanName the name of the bean instance to register 054 * @param beanDefinition definition of the bean instance to register 055 * @throws BeanDefinitionStoreException if the BeanDefinition is invalid 056 * @throws BeanDefinitionOverrideException if there is already a BeanDefinition 057 * for the specified bean name and we are not allowed to override it 058 * @see GenericBeanDefinition 059 * @see RootBeanDefinition 060 * @see ChildBeanDefinition 061 */ 062 void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) 063 throws BeanDefinitionStoreException; 064 065 /** 066 * Remove the BeanDefinition for the given name. 067 * @param beanName the name of the bean instance to register 068 * @throws NoSuchBeanDefinitionException if there is no such bean definition 069 */ 070 void removeBeanDefinition(String beanName) throws NoSuchBeanDefinitionException; 071 072 /** 073 * Return the BeanDefinition for the given bean name. 074 * @param beanName name of the bean to find a definition for 075 * @return the BeanDefinition for the given name (never {@code null}) 076 * @throws NoSuchBeanDefinitionException if there is no such bean definition 077 */ 078 BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException; 079 080 /** 081 * Check if this registry contains a bean definition with the given name. 082 * @param beanName the name of the bean to look for 083 * @return if this registry contains a bean definition with the given name 084 */ 085 boolean containsBeanDefinition(String beanName); 086 087 /** 088 * Return the names of all beans defined in this registry. 089 * @return the names of all beans defined in this registry, 090 * or an empty array if none defined 091 */ 092 String[] getBeanDefinitionNames(); 093 094 /** 095 * Return the number of beans defined in the registry. 096 * @return the number of beans defined in the registry 097 */ 098 int getBeanDefinitionCount(); 099 100 /** 101 * Determine whether the given bean name is already in use within this registry, 102 * i.e. whether there is a local bean or alias registered under this name. 103 * @param beanName the name to check 104 * @return whether the given bean name is already in use 105 */ 106 boolean isBeanNameInUse(String beanName); 107 108}