Java Code Examples for org.springframework.beans.factory.BeanFactory.FACTORY_BEAN_PREFIX

The following are Jave code examples for showing how to use FACTORY_BEAN_PREFIX of the org.springframework.beans.factory.BeanFactory class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: gemini.blueprint   File: MandatoryDependencyBeanPostProcessor.java   Source Code and License Vote up 6 votes
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	// disable publication until all the dependencies have been fulfilled
	
	// ignore inner beans
	if (bean instanceof OsgiServiceFactoryBean && beanFactory.containsLocalBean(beanName)) {
		String exporterName = beanName;
		if (beanFactory.isFactoryBean(beanName)) {
			exporterName = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
		}
		// if it's a singleton, then disable publication, otherwise ignore it
		if (beanFactory.isSingleton(exporterName)) {
			// get controller
			ExporterInternalActions controller = ExporterControllerUtils.getControllerFor(bean);
			controller.registerServiceAtStartup(false);
		}
	}
	return bean;
}
 
Example 2
Project: lams   File: DefaultLifecycleProcessor.java   Source Code and License Vote up 6 votes
/**
 * Retrieve all applicable Lifecycle beans: all singletons that have already been created,
 * as well as all SmartLifecycle beans (even if they are marked as lazy-init).
 * @return the Map of applicable beans, with bean names as keys and bean instances as values
 */
protected Map<String, Lifecycle> getLifecycleBeans() {
	Map<String, Lifecycle> beans = new LinkedHashMap<String, Lifecycle>();
	String[] beanNames = this.beanFactory.getBeanNamesForType(Lifecycle.class, false, false);
	for (String beanName : beanNames) {
		String beanNameToRegister = BeanFactoryUtils.transformedBeanName(beanName);
		boolean isFactoryBean = this.beanFactory.isFactoryBean(beanNameToRegister);
		String beanNameToCheck = (isFactoryBean ? BeanFactory.FACTORY_BEAN_PREFIX + beanName : beanName);
		if ((this.beanFactory.containsSingleton(beanNameToRegister) &&
				(!isFactoryBean || Lifecycle.class.isAssignableFrom(this.beanFactory.getType(beanNameToCheck)))) ||
				SmartLifecycle.class.isAssignableFrom(this.beanFactory.getType(beanNameToCheck))) {
			Lifecycle bean = this.beanFactory.getBean(beanNameToCheck, Lifecycle.class);
			if (bean != this) {
				beans.put(beanNameToRegister, bean);
			}
		}
	}
	return beans;
}
 
Example 3
Project: lams   File: DeprecatedBeanWarner.java   Source Code and License Vote up 6 votes
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
	if (isLogEnabled()) {
		String[] beanNames = beanFactory.getBeanDefinitionNames();
		for (String beanName : beanNames) {
			String nameToLookup = beanName;
			if (beanFactory.isFactoryBean(beanName)) {
				nameToLookup = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
			}
			Class<?> beanType = ClassUtils.getUserClass(beanFactory.getType(nameToLookup));
			if (beanType != null && beanType.isAnnotationPresent(Deprecated.class)) {
				BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
				logDeprecatedBean(beanName, beanType, beanDefinition);
			}
		}
	}
}
 
Example 4
Project: gemini.blueprint   File: DefaultMandatoryDependencyManager.java   Source Code and License Vote up 5 votes
public void addServiceExporter(Object exporter, String exporterBeanName) {
	Assert.hasText(exporterBeanName);

	if (exportersSeen.putIfAbsent(exporterBeanName, VALUE) == null) {

		String beanName = exporterBeanName;

		if (beanFactory.isFactoryBean(exporterBeanName))
			beanName = BeanFactory.FACTORY_BEAN_PREFIX + exporterBeanName;

		// check if it's factory bean (no need to check for abstract
		// definition since we're called by a BPP)
		if (!beanFactory.isSingleton(beanName)) {
			log.info("Exporter [" + beanName + "] is not singleton and will not be tracked");
		}

		else {
			if (log.isDebugEnabled())
				log.debug("Exporter [" + beanName + "] is being tracked for dependencies");

			exporterToName.put(exporter, exporterBeanName);
			// retrieve associated controller
			ExporterInternalActions controller = ExporterControllerUtils.getControllerFor(exporter);

			// disable publication at startup
			controller.registerServiceAtStartup(false);

			// populate the dependency maps
			discoverDependentImporterFor(exporterBeanName, exporter);
		}
	}
}
 
Example 5
Project: lams   File: RefreshableScriptTargetSource.java   Source Code and License Vote up 4 votes
/**
 * Obtain a fresh target object, retrieving a FactoryBean if necessary.
 */
@Override
protected Object obtainFreshBean(BeanFactory beanFactory, String beanName) {
	return super.obtainFreshBean(beanFactory,
			(this.isFactoryBean ? BeanFactory.FACTORY_BEAN_PREFIX + beanName : beanName));
}
 
Example 6
Project: lams   File: ScriptFactoryPostProcessor.java   Source Code and License Vote up 4 votes
@Override
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) {
	// We only apply special treatment to ScriptFactory implementations here.
	if (!ScriptFactory.class.isAssignableFrom(beanClass)) {
		return null;
	}

	BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);
	String scriptFactoryBeanName = SCRIPT_FACTORY_NAME_PREFIX + beanName;
	String scriptedObjectBeanName = SCRIPTED_OBJECT_NAME_PREFIX + beanName;
	prepareScriptBeans(bd, scriptFactoryBeanName, scriptedObjectBeanName);

	ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
	ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
	boolean isFactoryBean = false;
	try {
		Class<?> scriptedObjectType = scriptFactory.getScriptedObjectType(scriptSource);
		// Returned type may be null if the factory is unable to determine the type.
		if (scriptedObjectType != null) {
			isFactoryBean = FactoryBean.class.isAssignableFrom(scriptedObjectType);
		}
	}
	catch (Exception ex) {
		throw new BeanCreationException(beanName,
				"Could not determine scripted object type for " + scriptFactory, ex);
	}

	long refreshCheckDelay = resolveRefreshCheckDelay(bd);
	if (refreshCheckDelay >= 0) {
		Class<?>[] interfaces = scriptFactory.getScriptInterfaces();
		RefreshableScriptTargetSource ts = new RefreshableScriptTargetSource(this.scriptBeanFactory,
				scriptedObjectBeanName, scriptFactory, scriptSource, isFactoryBean);
		boolean proxyTargetClass = resolveProxyTargetClass(bd);
		String language = (String) bd.getAttribute(LANGUAGE_ATTRIBUTE);
		if (proxyTargetClass && (language == null || !language.equals("groovy"))) {
			throw new BeanDefinitionValidationException(
					"Cannot use proxyTargetClass=true with script beans where language is not 'groovy': '" +
					language + "'");
		}
		ts.setRefreshCheckDelay(refreshCheckDelay);
		return createRefreshableProxy(ts, interfaces, proxyTargetClass);
	}

	if (isFactoryBean) {
		scriptedObjectBeanName = BeanFactory.FACTORY_BEAN_PREFIX + scriptedObjectBeanName;
	}
	return this.scriptBeanFactory.getBean(scriptedObjectBeanName);
}
 
Example 7
Project: lams   File: AbstractEntityManagerFactoryBean.java   Source Code and License Vote up 4 votes
public SerializedEntityManagerFactoryBeanReference(BeanFactory beanFactory, String beanName) {
	this.beanFactory = beanFactory;
	this.lookupName = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
}