/** * Creates a scoped instance (a proxy for normal scoped beans) for the given bean-class and qualifiers. * Compared to the other util methods it allows optional beans. * @param beanManager current bean-manager * @param targetClass class of the bean * @param optionalBeanAllowed flag which indicates if it's an optional bean * @param qualifier optional qualifiers * @param <T> target type * @return created or resolved instance if such a bean exists, null otherwise */ public static <T> T getContextualReferenceByClass(BeanManager beanManager, Class<T> targetClass, boolean optionalBeanAllowed, Annotation... qualifier) { Bean<?> foundBean = getOrCreateBeanByClass(beanManager, targetClass, optionalBeanAllowed, qualifier); if(foundBean != null) { //noinspection unchecked return (T) getContextualReference(beanManager, targetClass, foundBean); } return null; }
/** * Creates a scoped instance (a proxy for normal scoped beans) for the given bean-class and qualifiers. * Compared to the other util methods it allows optional beans. * @param beanManager current bean-manager * @param targetClass class of the bean * @param optionalBeanAllowed flag which indicates if it's an optional bean * @param qualifier optional qualifiers * @param <T> target type * @return created or resolved instance if such a bean exists, null otherwise */ public static <T> T getContextualReferenceByClass(BeanManager beanManager, Class<T> targetClass, boolean optionalBeanAllowed, Annotation... qualifier) { Bean<?> foundBean = getOrCreateBeanByClass(beanManager, targetClass, optionalBeanAllowed, qualifier); if(foundBean != null) { //noinspection unchecked return (T) getContextualReference(beanManager, targetClass, foundBean); } return null; }
/** * Creates a scoped instance (a proxy for normal scoped beans) for the given bean-class and qualifiers. * Compared to the other util methods it allows optional beans. * @param beanManager current bean-manager * @param targetClass class of the bean * @param optionalBeanAllowed flag which indicates if it's an optional bean * @param qualifier optional qualifiers * @param <T> target type * @return created or resolved instance if such a bean exists, null otherwise */ public static <T> T getContextualReferenceByClass(BeanManager beanManager, Class<T> targetClass, boolean optionalBeanAllowed, Annotation... qualifier) { Bean<?> foundBean = getOrCreateBeanByClass(beanManager, targetClass, optionalBeanAllowed, qualifier); if(foundBean != null) { //noinspection unchecked return (T) getContextualReference(beanManager, targetClass, foundBean); } return null; }