/** * Creates a scoped instance (a proxy for normal scoped beans) for the given bean-name and class * @param beanManager current bean-manager * @param beanName name of the bean * @param optionalBeanAllowed flag which indicates if it's an optional bean * @param targetClass class of the bean * @param <T> target type * @return created or resolved instance */ public static <T> T getContextualReferenceByName( BeanManager beanManager, String beanName, boolean optionalBeanAllowed, Class<T> targetClass) { Set<Bean<?>> foundBeans = beanManager.getBeans(beanName); if(foundBeans.size() >= 1) { Bean<?> bean = beanManager.resolve(foundBeans); //noinspection unchecked return (T) getContextualReference(beanManager, targetClass, bean); } if(!optionalBeanAllowed) { throw new IllegalStateException("No bean found for type: " + targetClass.getName() + " and name " + beanName); } return null; }
/** * Creates a scoped instance (a proxy for normal scoped beans) for the given bean-name and class * @param beanManager current bean-manager * @param beanName name of the bean * @param optionalBeanAllowed flag which indicates if it's an optional bean * @param targetClass class of the bean * @param <T> target type * @return created or resolved instance */ public static <T> T getContextualReferenceByName( BeanManager beanManager, String beanName, boolean optionalBeanAllowed, Class<T> targetClass) { Set<Bean<?>> foundBeans = beanManager.getBeans(beanName); if(foundBeans.size() >= 1) { Bean<?> bean = beanManager.resolve(foundBeans); //noinspection unchecked return (T) getContextualReference(beanManager, targetClass, bean); } if(!optionalBeanAllowed) { throw new IllegalStateException("No bean found for type: " + targetClass.getName() + " and name " + beanName); } return null; }
/** * Creates a scoped instance (a proxy for normal scoped beans) for the given bean-name and class * @param beanManager current bean-manager * @param beanName name of the bean * @param optionalBeanAllowed flag which indicates if it's an optional bean * @param targetClass class of the bean * @param <T> target type * @return created or resolved instance */ public static <T> T getContextualReferenceByName( BeanManager beanManager, String beanName, boolean optionalBeanAllowed, Class<T> targetClass) { Set<Bean<?>> foundBeans = beanManager.getBeans(beanName); if(foundBeans.size() >= 1) { Bean<?> bean = beanManager.resolve(foundBeans); //noinspection unchecked return (T) getContextualReference(beanManager, targetClass, bean); } if(!optionalBeanAllowed) { throw new IllegalStateException("No bean found for type: " + targetClass.getName() + " and name " + beanName); } 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; }
/** * 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; }
private synchronized void init() { // switch into paranoia mode if(this.beanCreationDecisionVoters == null) { this.beanCreationDecisionVoters = new ArrayList<BeanCreationDecisionVoter>(); Set<? extends Bean> foundBeans = this.beanManager.getBeans(BeanCreationDecisionVoter.class, new AnyLiteral()); Bean<?> foundBean; Set<Bean<?>> beanSet; for(Bean<?> currentBean : foundBeans) { beanSet = new HashSet<Bean<?>>(1); beanSet.add(currentBean); foundBean = this.beanManager.resolve(beanSet); this.beanCreationDecisionVoters.add( CodiUtils.getContextualReference(this.beanManager, BeanCreationDecisionVoter.class, (Bean<BeanCreationDecisionVoter>)foundBean)); } Collections .sort(this.beanCreationDecisionVoters, new InvocationOrderComparator<BeanCreationDecisionVoter>()); } }
private synchronized void init() { // switch into paranoia mode if(this.beanCreationDecisionVoters == null) { this.beanCreationDecisionVoters = new ArrayList<BeanCreationDecisionVoter>(); Set<? extends Bean> foundBeans = this.beanManager.getBeans(BeanCreationDecisionVoter.class, new AnyLiteral()); Bean<?> foundBean; Set<Bean<?>> beanSet; for(Bean<?> currentBean : foundBeans) { beanSet = new HashSet<Bean<?>>(1); beanSet.add(currentBean); foundBean = this.beanManager.resolve(beanSet); this.beanCreationDecisionVoters.add( CodiUtils.getContextualReference(this.beanManager, BeanCreationDecisionVoter.class, (Bean<BeanCreationDecisionVoter>)foundBean)); } Collections .sort(this.beanCreationDecisionVoters, new InvocationOrderComparator<BeanCreationDecisionVoter>()); } }
private synchronized void init() { // switch into paranoia mode if(this.beanCreationDecisionVoters == null) { this.beanCreationDecisionVoters = new ArrayList<BeanCreationDecisionVoter>(); Set<? extends Bean> foundBeans = this.beanManager.getBeans(BeanCreationDecisionVoter.class, new AnyLiteral()); Bean<?> foundBean; Set<Bean<?>> beanSet; for(Bean<?> currentBean : foundBeans) { beanSet = new HashSet<Bean<?>>(1); beanSet.add(currentBean); foundBean = this.beanManager.resolve(beanSet); this.beanCreationDecisionVoters.add( CodiUtils.getContextualReference(this.beanManager, BeanCreationDecisionVoter.class, (Bean<BeanCreationDecisionVoter>)foundBean)); } Collections .sort(this.beanCreationDecisionVoters, new InvocationOrderComparator<BeanCreationDecisionVoter>()); } }