public <T> Bean<T> createBean(final Class<T> beanClass) { try { return beanManager.getBean(beanClass); } catch (final Exception e) { LOGGER.log(Level.TRACE, "Not found bean [beanClass={0}], so to create it", beanClass); } if (Reflections.isAbstract(beanClass) || Reflections.isInterface(beanClass)) { throw new IllegalStateException("Can't create bean for class [" + beanClass.getName() + "] caused by it is an interface or an abstract class, or it dose not implement any interface"); } final String className = beanClass.getName(); final String name = className.substring(0, 1).toLowerCase() + className.substring(1); final Set<Type> beanTypes = Reflections.getBeanTypes(beanClass); final Set<Class<? extends Annotation>> stereotypes = Reflections.getStereotypes(beanClass); LOGGER.log(Level.DEBUG, "Adding a bean [name={0}, class={1}] to the bean manager", name, beanClass.getName()); final Bean<T> ret = new Bean<T>(beanManager, name, beanClass, beanTypes, stereotypes); beanManager.addBean(ret); for (final Type beanType : beanTypes) { addTypeClassBinding(beanType, beanClass); } return ret; }
public <T> Bean<T> createBean(final Class<T> beanClass) { try { return beanManager.getBean(beanClass); } catch (final Exception e) { LOGGER.log(Level.TRACE, "Not found bean [beanClass={0}], so to create it", beanClass); } if (Reflections.isAbstract(beanClass) || Reflections.isInterface(beanClass)) { throw new IllegalStateException("Can't create bean for class [" + beanClass.getName() + "] caused by it is an interface or an abstract class, or it dose not implement any interface"); } final String className = beanClass.getName(); final String name = className.substring(0, 1).toLowerCase() + className.substring(1); final Set<Type> beanTypes = Reflections.getBeanTypes(beanClass); final Set<Class<? extends Annotation>> stereotypes = Reflections.getStereotypes(beanClass); LOGGER.log(Level.DEBUG, "Adding a bean [name={0}, class={1}] to the bean manager", name, beanClass.getName()); final Bean<T> ret = new Bean<T>(beanManager, name, beanClass, beanTypes, stereotypes); beanManager.addBean(ret); for (final Type beanType : beanTypes) { addTypeClassBinding(beanType, beanClass); } return ret; }