public enum BeanManager extends Enum<BeanManager>
This configuration enum allows you to get a reference to CDI managed beans without having any direct CDI dependency.
It will during initialization grab the CDI bean manager instance from JNDI and if it's not null
, then
it's using reflection to get and store the necessary methods in the enum instance which are then invoked on instance
methods such as getReference()
.
// Get the CDI managed bean instance of the given bean class. SomeBean someBean = BeanManager.INSTANCE.getReference(SomeBean.class);
If you however already have a CDI bean manager instance at hands via @Inject
, use
BeansLocal.getReference(javax.enterprise.inject.spi.BeanManager, Class)
instead.
Enum Constant and Description |
---|
INSTANCE
Returns the lazily loaded enum singleton instance.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
get()
Returns the CDI bean manager.
|
<T> T |
getReference(Class<T> beanClass)
Returns the CDI managed bean reference (proxy) of the given class.
|
static BeanManager |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static BeanManager[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final BeanManager INSTANCE
IllegalStateException
when initialization fails.public static BeanManager[] values()
for (BeanManager c : BeanManager.values()) System.out.println(c);
public static BeanManager valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic <T> T get()
T
- The javax.enterprise.inject.spi.BeanManager
.ClassCastException
- When you assign it to a variable which is not declared as CDI BeanManager.public <T> T getReference(Class<T> beanClass)
T
- The expected return type.beanClass
- The CDI managed bean class.null
if there is none.UnsupportedOperationException
- When obtaining the CDI managed bean reference failed with an exception.Copyright © 2012–2014 OmniFaces. All rights reserved.