* The bean under construction.
*/
protected void createBeanFactoryBean(final Bean bean) {
Checker.notNull("parameter:bean", bean);
final GeneratorContext context = this.getGeneratorContext();
final String beanName = bean.getId();
if (Tester.isNullOrEmpty(beanName)) {
throwBeanIdIsMissing(bean);
}
this.checkIdIsUnique(bean);
final String className = bean.getTypeName();
final Type beanType = this.getConcreteType(beanName, className);
bean.setType(beanType);
context.debug(beanType.getName());
final boolean singleton = bean.isSingleton();
bean.setSingleton(singleton);
context.debug(singleton ? "singleton" : "prototype");
// process the eager/lazy attribute
final boolean eager = bean.isEagerLoaded();
bean.setEagerLoaded(eager);
this.checkPrototypesAreNotMarkedAsEager(bean);
if (singleton) {
context.debug(eager ? "eager" : "lazyloaded");
}
if (false == singleton) {
final String destroyMethod = bean.getDestroyMethod();
if (false == Tester.isNullOrEmpty(destroyMethod)) {
throwPrototypeCantBeContainerDestroyed(bean);
}
final Type disposableBean = this.getDisposableBean();
if (beanType.isAssignableTo(disposableBean)) {
context.warn("Ignoring the fact the bean implements DisposableBean (because its a prototype)"
+ (context.isDebugEnabled() ? "." : ", bean: " + bean));
}
}
// start creating the factory bean...
final Type superType = singleton ? this.getSingletonFactoryBean() : this.getPrototypeFactoryBean();
final NewConcreteType beanFactory = this.getBeanFactory();
final NewNestedType factoryBean = beanFactory.newNestedType();
factoryBean.setStatic(false);
factoryBean.setNestedName(this.escapeBeanIdToBeClassNameSafe(beanName) + Constants.FACTORY_BEAN_SUFFIX);
factoryBean.setSuperType(superType);
factoryBean.setVisibility(Visibility.PRIVATE);
// add an annotation that declares the actual bean type.
factoryBean.addMetaData(Constants.FACTORY_BEAN_OBJECT_TYPE, bean.getType().getName());
bean.setFactoryBean(factoryBean);
context.debug("FactoryBean: " + factoryBean.getName());
this.addBean(bean);
}