Java Code Examples for org.springframework.beans.factory.BeanFactory#isSingleton()

The following examples show how to use org.springframework.beans.factory.BeanFactory#isSingleton() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractBeanFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
	String beanName = transformedBeanName(name);

	Object beanInstance = getSingleton(beanName, false);
	if (beanInstance != null) {
		if (beanInstance instanceof FactoryBean) {
			return (BeanFactoryUtils.isFactoryDereference(name) || ((FactoryBean<?>) beanInstance).isSingleton());
		}
		else {
			return !BeanFactoryUtils.isFactoryDereference(name);
		}
	}

	// No singleton instance found -> check bean definition.
	BeanFactory parentBeanFactory = getParentBeanFactory();
	if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
		// No bean definition found in this factory -> delegate to parent.
		return parentBeanFactory.isSingleton(originalBeanName(name));
	}

	RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);

	// In case of FactoryBean, return singleton status of created object if not a dereference.
	if (mbd.isSingleton()) {
		if (isFactoryBean(beanName, mbd)) {
			if (BeanFactoryUtils.isFactoryDereference(name)) {
				return true;
			}
			FactoryBean<?> factoryBean = (FactoryBean<?>) getBean(FACTORY_BEAN_PREFIX + beanName);
			return factoryBean.isSingleton();
		}
		else {
			return !BeanFactoryUtils.isFactoryDereference(name);
		}
	}
	else {
		return false;
	}
}
 
Example 2
Source File: AbstractBeanFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
	String beanName = transformedBeanName(name);

	Object beanInstance = getSingleton(beanName, false);
	if (beanInstance != null) {
		if (beanInstance instanceof FactoryBean) {
			return (BeanFactoryUtils.isFactoryDereference(name) || ((FactoryBean<?>) beanInstance).isSingleton());
		}
		else {
			return !BeanFactoryUtils.isFactoryDereference(name);
		}
	}

	// No singleton instance found -> check bean definition.
	BeanFactory parentBeanFactory = getParentBeanFactory();
	if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
		// No bean definition found in this factory -> delegate to parent.
		return parentBeanFactory.isSingleton(originalBeanName(name));
	}

	RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);

	// In case of FactoryBean, return singleton status of created object if not a dereference.
	if (mbd.isSingleton()) {
		if (isFactoryBean(beanName, mbd)) {
			if (BeanFactoryUtils.isFactoryDereference(name)) {
				return true;
			}
			FactoryBean<?> factoryBean = (FactoryBean<?>) getBean(FACTORY_BEAN_PREFIX + beanName);
			return factoryBean.isSingleton();
		}
		else {
			return !BeanFactoryUtils.isFactoryDereference(name);
		}
	}
	else {
		return false;
	}
}
 
Example 3
Source File: CompositeBeanFactory.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Override
public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
	for (BeanFactory f : factories) {
		try {
			boolean b = f.isSingleton(name);
			if (b) {
				return b;
			}	
		} catch (BeansException e) {
			LOG.info("bean exception", e);
		}
	}
	return false;
}
 
Example 4
Source File: AbstractBeanFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
	String beanName = transformedBeanName(name);

	Object beanInstance = getSingleton(beanName, false);
	if (beanInstance != null) {
		if (beanInstance instanceof FactoryBean) {
			return (BeanFactoryUtils.isFactoryDereference(name) || ((FactoryBean<?>) beanInstance).isSingleton());
		}
		else {
			return !BeanFactoryUtils.isFactoryDereference(name);
		}
	}
	else if (containsSingleton(beanName)) {
		return true;
	}

	// No singleton instance found -> check bean definition.
	BeanFactory parentBeanFactory = getParentBeanFactory();
	if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
		// No bean definition found in this factory -> delegate to parent.
		return parentBeanFactory.isSingleton(originalBeanName(name));
	}

	RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);

	// In case of FactoryBean, return singleton status of created object if not a dereference.
	if (mbd.isSingleton()) {
		if (isFactoryBean(beanName, mbd)) {
			if (BeanFactoryUtils.isFactoryDereference(name)) {
				return true;
			}
			FactoryBean<?> factoryBean = (FactoryBean<?>) getBean(FACTORY_BEAN_PREFIX + beanName);
			return factoryBean.isSingleton();
		}
		else {
			return !BeanFactoryUtils.isFactoryDereference(name);
		}
	}
	else {
		return false;
	}
}
 
Example 5
Source File: AbstractBeanFactory.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
	String beanName = transformedBeanName(name);

	Object beanInstance = getSingleton(beanName, false);
	if (beanInstance != null) {
		if (beanInstance instanceof FactoryBean) {
			return (BeanFactoryUtils.isFactoryDereference(name) || ((FactoryBean<?>) beanInstance).isSingleton());
		}
		else {
			return !BeanFactoryUtils.isFactoryDereference(name);
		}
	}
	else if (containsSingleton(beanName)) {
		return true;
	}

	else {
		// No singleton instance found -> check bean definition.
		BeanFactory parentBeanFactory = getParentBeanFactory();
		if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
			// No bean definition found in this factory -> delegate to parent.
			return parentBeanFactory.isSingleton(originalBeanName(name));
		}

		RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);

		// In case of FactoryBean, return singleton status of created object if not a dereference.
		if (mbd.isSingleton()) {
			if (isFactoryBean(beanName, mbd)) {
				if (BeanFactoryUtils.isFactoryDereference(name)) {
					return true;
				}
				FactoryBean<?> factoryBean = (FactoryBean<?>) getBean(FACTORY_BEAN_PREFIX + beanName);
				return factoryBean.isSingleton();
			}
			else {
				return !BeanFactoryUtils.isFactoryDereference(name);
			}
		}
		else {
			return false;
		}
	}
}
 
Example 6
Source File: AbstractBeanFactory.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
	String beanName = transformedBeanName(name);

	Object beanInstance = getSingleton(beanName, false);
	if (beanInstance != null) {
		if (beanInstance instanceof FactoryBean) {
			return (BeanFactoryUtils.isFactoryDereference(name) || ((FactoryBean<?>) beanInstance).isSingleton());
		}
		else {
			return !BeanFactoryUtils.isFactoryDereference(name);
		}
	}
	else if (containsSingleton(beanName)) {
		return true;
	}

	else {
		// No singleton instance found -> check bean definition.
		BeanFactory parentBeanFactory = getParentBeanFactory();
		if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
			// No bean definition found in this factory -> delegate to parent.
			return parentBeanFactory.isSingleton(originalBeanName(name));
		}

		RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);

		// In case of FactoryBean, return singleton status of created object if not a dereference.
		if (mbd.isSingleton()) {
			if (isFactoryBean(beanName, mbd)) {
				if (BeanFactoryUtils.isFactoryDereference(name)) {
					return true;
				}
				FactoryBean<?> factoryBean = (FactoryBean<?>) getBean(FACTORY_BEAN_PREFIX + beanName);
				return factoryBean.isSingleton();
			}
			else {
				return !BeanFactoryUtils.isFactoryDereference(name);
			}
		}
		else {
			return false;
		}
	}
}