Skip to content
Permalink
Browse files

Add Beans#resolveExact

  • Loading branch information...
BalusC committed Feb 25, 2018
1 parent c04e0eb commit 2123aa7048b080cd5d5116025b9b0bd43d58c36b
Showing with 24 additions and 0 deletions.
  1. +15 −0 src/main/java/org/omnifaces/util/Beans.java
  2. +9 −0 src/main/java/org/omnifaces/util/BeansLocal.java
@@ -100,6 +100,21 @@ public static BeanManager getManager() {
return BeansLocal.resolve(getManager(), beanClass, qualifiers);
}

/**
* Returns the CDI managed bean representation of exactly the given bean class, optionally with the given qualifiers.
* This will ignore any subclasses.
* @param <T> The generic CDI managed bean type.
* @param beanClass The CDI managed bean class.
* @param qualifiers The CDI managed bean qualifiers, if any.
* @return The CDI managed bean representation of the given bean class, or <code>null</code> if there is none.
* @see BeanManager#getBeans(java.lang.reflect.Type, Annotation...)
* @see BeanManager#resolve(java.util.Set)
* @since 3.1
*/
public static <T> Bean<T> resolveExact(Class<T> beanClass, Annotation... qualifiers) {
return BeansLocal.resolveExact(getManager(), beanClass, qualifiers);
}

/**
* Returns the CDI managed bean reference (proxy) of the given bean class, optionally with the given qualifiers.
* Note that this actually returns a client proxy and the underlying actual instance is thus always auto-created.
@@ -77,6 +77,15 @@ private BeansLocal() {
return (Bean<T>) beanManager.resolve(beans);
}

/**
* @see Beans#resolve(Class, Annotation...)
*/
@SuppressWarnings("unchecked")
public static <T> Bean<T> resolveExact(BeanManager beanManager, Class<T> beanClass, Annotation... qualifiers) {
Bean<T> bean = resolve(beanManager, beanClass, qualifiers);
return (bean != null) && (bean.getBeanClass() == beanClass) ? bean : null;
}

/**
* @see Beans#getReference(Class, Annotation...)
*/

0 comments on commit 2123aa7

Please sign in to comment.
You can’t perform that action at this time.