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> 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,
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, 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
.