public final class CDIUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
fireEvent(Object event,
Annotation... qualifiers)
Fire an event and notify observers.
|
static javax.enterprise.inject.spi.BeanManager |
getBeanManager()
Returns the
BeanManager which is basically a shorthand for CDI.current().getBeanManager(). |
static void |
registerProducerMethod(Method producerMethod)
Keeps track of all the CDI Bean producer methods.
|
static <T> T |
retrieveInstance(Class<T> classType,
Annotation... qualifiers)
Retrieve the single CDI instance which has the classType in the bean definition.
|
static <T> T |
retrieveInstanceByName(String beanName,
Class<T> targetClass)
Retrieve the CDI bean assigned the bean name in the context.
|
static <T> List<T> |
retrieveInstances(Class<T> classType,
Annotation... qualifiers)
Retrieve all CDI instances which have the classType in their bean definition.
|
static <T> T |
retrieveOptionalInstance(Class<T> classType,
Annotation... qualifiers)
Retrieve the Single CDI instance which has the classType in the bean definition or null when no CDI beans found.
|
public static <T> List<T> retrieveInstances(Class<T> classType, Annotation... qualifiers)
T - Generic Type argumentclassType - a Class representing the required type.qualifiers - the additional required qualifiers.public static <T> T retrieveInstance(Class<T> classType, Annotation... qualifiers)
T - Generic Type argumentclassType - a Class representing the required typequalifiers - the additional required qualifiers.javax.enterprise.inject.AmbiguousResolutionException - When more then 1 bean is found in the matchjavax.enterprise.inject.UnsatisfiedResolutionException - When no bean is found in the match.public static <T> T retrieveOptionalInstance(Class<T> classType, Annotation... qualifiers)
T - Generic Type argumentclassType - a Class representing the required typequalifiers - the additional required qualifiers.javax.enterprise.inject.AmbiguousResolutionException - When more then 1 bean is found in the matchpublic static javax.enterprise.inject.spi.BeanManager getBeanManager()
BeanManager which is basically a shorthand for CDI.current().getBeanManager().BeanManager for the current CDI context.public static <T> T retrieveInstanceByName(String beanName, Class<T> targetClass)
UnsatisfiedResolutionException is thrown (instead of the
ClassCastException by the JVM). When no bean is found, UnsatisfiedResolutionException is also thrown.T - Generic Type argumentbeanName - The name of the bean we are interested in.targetClass - The class this bean must have (or subclass)javax.enterprise.inject.UnsatisfiedResolutionException - When instance cannot be found or is assignable to the requested type.public static void fireEvent(Object event, Annotation... qualifiers)
CDI.current().getBeanManager().fireEvent.event - the event objectqualifiers - the event qualifierspublic static void registerProducerMethod(Method producerMethod)
producerMethod - Method which produces a CDI bean (@Produces present)Copyright © 2014–2019. All rights reserved.