public final class Beans extends Object
BeanManager
.
If you need a dependency-free way of obtaining the CDI managed bean instance (e.g. when you want to write code which
should also run on Tomcat), use BeanManager
instead.
Constructor and Description |
---|
Beans() |
Modifier and Type | Method and Description |
---|---|
static Map<Object,String> |
getActiveInstances(BeanManager beanManager,
Class<? extends Annotation> scope)
Returns all active CDI managed bean instances in the given CDI managed bean scope.
|
static <T extends Annotation> |
getAnnotation(BeanManager beanManager,
Annotated annotated,
Class<T> annotationType)
Get program element annotation of a certain annotation type.
|
static <T extends Annotation> |
getAnnotation(BeanManager beanManager,
Collection<Annotation> initialAnnotations,
Class<T> annotationType)
Get program element annotation of a certain annotation type from a collection of annotations.
|
static <T> T |
getInstance(BeanManager beanManager,
Bean<T> bean,
boolean create)
Returns the CDI managed bean instance of the given resolved bean from the given bean manager and creates one if
one doesn't exist and
create argument is true , otherwise don't create one and return
null if there's no current instance. |
static <T> T |
getInstance(BeanManager beanManager,
Class<T> beanClass)
Returns the CDI managed bean instance of the given class from the given bean manager and creates one if
one doesn't exist.
|
static <T> T |
getInstance(BeanManager beanManager,
Class<T> beanClass,
boolean create)
Returns the CDI managed bean instance of the given class from the given bean manager and creates one if
one doesn't exist and
create argument is true , otherwise don't create one and return
null if there's no current instance. |
static <T> T |
getReference(BeanManager beanManager,
Bean<T> bean)
Returns the CDI managed bean reference of the given resolved bean from the given bean manager.
|
static <T> T |
getReference(BeanManager beanManager,
Class<T> beanClass)
Returns the CDI managed bean reference of the given class from the given bean manager.
|
static <T> Bean<T> |
resolve(BeanManager beanManager,
Class<T> beanClass)
Resolve and returns the CDI managed bean of the given class from the given bean manager.
|
public static <T> Bean<T> resolve(BeanManager beanManager, Class<T> beanClass)
beanManager
- The involved CDI bean manager.beanClass
- The type of the CDI managed bean instance.public static <T> T getReference(BeanManager beanManager, Class<T> beanClass)
beanManager
- The involved CDI bean manager.beanClass
- The type of the CDI managed bean instance.public static <T> T getReference(BeanManager beanManager, Bean<T> bean)
beanManager
- The involved CDI bean manager.bean
- The resolved bean of the CDI managed bean instance.public static <T> T getInstance(BeanManager beanManager, Class<T> beanClass)
beanManager
- The involved CDI bean manager.beanClass
- The type of the CDI managed bean instance.public static <T> T getInstance(BeanManager beanManager, Class<T> beanClass, boolean create)
create
argument is true
, otherwise don't create one and return
null
if there's no current instance.beanManager
- The involved CDI bean manager.beanClass
- The type of the CDI managed bean instance.create
- If true
, then create one if one doesn't exist, otherwise don't create one and return
null
if there's no current instance.public static <T> T getInstance(BeanManager beanManager, Bean<T> bean, boolean create)
create
argument is true
, otherwise don't create one and return
null
if there's no current instance.beanManager
- The involved CDI bean manager.bean
- The resolved bean of the CDI managed bean instance.create
- If true
, then create one if one doesn't exist, otherwise don't create one and return
null
if there's no current instance.public static Map<Object,String> getActiveInstances(BeanManager beanManager, Class<? extends Annotation> scope)
beanManager
- The involved CDI bean manager.scope
- The CDI managed bean scope, e.g. RequestScoped.class
.public static <T extends Annotation> T getAnnotation(BeanManager beanManager, Annotated annotated, Class<T> annotationType)
The difference with Annotated.getAnnotation(Class)
is that this method will recursively search inside
all Stereotype
annotations.
beanManager
- The involved CDI bean manager.annotated
- a Java program element that can be annotatedannotationType
- the class of the annotation typenull
public static <T extends Annotation> T getAnnotation(BeanManager beanManager, Collection<Annotation> initialAnnotations, Class<T> annotationType)
This method will investigate the list of the initial annotations and for every such annotation that's a stereo type will recursively investigate the annotations represented by the stereo type as long as the given annotation type hasn't been encountered.
beanManager
- The involved CDI bean manager.initialAnnotations
- collection of annotations to investigateannotationType
- the class of the annotation typenull