Top Description Methods
jakarta.enterprise.inject.spi

public Interface BeanManager

extends BeanContainer
Imports
java.lang.annotation.Annotation, java.lang.reflect.Type, java.util.List, .Set, jakarta.el.ELResolver, .ExpressionFactory, jakarta.enterprise.context.Dependent, jakarta.enterprise.context.spi.CreationalContext, jakarta.enterprise.inject.AmbiguousResolutionException, .InjectionException, .Stereotype, .UnsatisfiedResolutionException, jakarta.enterprise.util.Nonbinding

Allows a portable extension to interact directly with the container. Provides operations for obtaining contextual references for beans, along with many other operations of use to portable extensions.

In CDI Lite environment, applications may obtain a BeanManager, but invoking methods that are not inherited from BeanContainer results in non-portable behavior.

Any bean may obtain an instance of BeanManager by injecting it:

@Inject
BeanManager manager;

Java EE components may obtain an instance of BeanManager from JNDI by looking up the name java:comp/BeanManager.

Most operations of BeanManager may be called at any time during the execution of the application.

However, the following operations must not be called before the AfterBeanDiscovery event is fired:

and the following operations must not be called before the AfterDeploymentValidation event is fired:

or the container will throw an Exception.

Authors
Gavin King, Pete Muir, Clint Popetz, David Allen, Antoine Sabot-Durand

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the two interceptor bindings are equivalent, otherwise false
areInterceptorBindingsEquivalent
(Annotation
an interceptor binding to check
interceptorBinding1
,
Annotation
an interceptor binding to check
interceptorBinding2
)

Determine if two interceptor bindings are considered equivalent for the purposes of typesafe resolution, taking into account any members annotated with Nonbinding.

public boolean

Returns:

true if the two qualifiers are equivalent, otherwise false
areQualifiersEquivalent
(Annotation
a qualifier to check
qualifier1
,
Annotation
a qualifier to check
qualifier2
)

Determine if two qualifiers are considered equivalent for the purposes of typesafe resolution, taking into account any members annotated with Nonbinding.

public <
the class or interface
T
>
AnnotatedType<T>

Returns:

the AnnotatedType
createAnnotatedType
(Class<T>
the java.lang.Class object
type
)

Obtain an AnnotatedType that may be used to read the annotations of the given class or interface.

public <
the type
T
>
Bean<T>

Returns:

a container provided implementation of Bean
createBean
(BeanAttributes<T>
a BeanAttributes which determines the bean types, qualifiers, scope, name and stereotypes of the returned Bean, and the return value of Bean#isAlternative()
attributes
,
Class<T>
a class, which determines the return value of Bean#getBeanClass()
beanClass
,
InjectionTargetFactory<T> injectionTargetFactory)

Obtains a Bean for the given BeanAttributes, bean class and InjectionTarget.

public <
the type
T
,
the type of the declaring bean
X
>
Bean<T>

Returns:

a container provided implementation of Bean
createBean
(BeanAttributes<T>
a BeanAttributes which determines the bean types, qualifiers, scope, name and stereotypes of the returned Bean, and the return value of Bean#isAlternative()
attributes
,
Class<X>
a class, which determines the return value of Bean.getClass()
beanClass
,
ProducerFactory<X>
a ProducerFactory, used to obtain a Producer
producerFactory
)

Obtains a Bean for the given BeanAttributes, bean class and Producer.

public <
the type
T
>
BeanAttributes<T>

Returns:

a container provided implementation of InjectionTarget
createBeanAttributes
(AnnotatedType<T> type)

Obtains a BeanAttributes for the given AnnotatedType.

public BeanAttributes<?>

Returns:

a container provided implementation of InjectionTarget
createBeanAttributes
(AnnotatedMember<?> type)

Obtains a BeanAttributes for the given AnnotatedType.

public InjectionPoint

Returns:

the container provided InjectionPoint
createInjectionPoint
(AnnotatedField<?>
the AnnotatedField defining the injection point
field
)

Obtains a container provided implementation of InjectionPoint for the given AnnotatedField.

public InjectionPoint

Returns:

the container provided InjectionPoint
createInjectionPoint
(AnnotatedParameter<?>
the AnnotatedParameter defining the injection point
parameter
)

Obtains a container provided implementation of InjectionPoint for the given AnnotatedParameter.

public <
type of the instance this factory will work on
T
>
InterceptionFactory<T>

Returns:

a new InterceptionFactory to add services on on instances of T
createInterceptionFactory
(CreationalContext<T> ctx, Class<T>
class of the instance this factory will work on
clazz
)

Create an InterceptionFactory for the given CreationalContext and type.

public ELResolver
getELResolver()
Deprecated for removal since 4.1. use ELAwareBeanManager, this method will be removed in CDI 5.0

Returns a jakarta.el.ELResolver that resolves beans by EL name.

public <
the type of the extension
T extends Extension
>
T

Returns:

the extension instance
getExtension
(Class<T>
the type of the extension class
extensionClass
)

Obtains the container's instance of an Extension class declared in META-INF/services.

public Object

Returns:

the injectable reference
getInjectableReference
(InjectionPoint
the target injection point
ij
,
CreationalContext<?>
a CreationalContext that may be used to destroy any object with scope Dependent that is created
ctx
)

Obtains an injectable reference for a certain injection point.

public <
the type
T
>
InjectionTargetFactory<T>
getInjectionTargetFactory(AnnotatedType<T>
the annotated type to create the injection target factory for
annotatedType
)

An implementation of InjectionTargetFactory that provides container created InjectionTarget instances.

public Set<Annotation>

Returns:

the set of meta-annotations
getInterceptorBindingDefinition
(Class<? extends Annotation> bindingType)

Obtains the set of meta-annotations for a certain interceptor binding type .

public int

Returns:

the hashCode for the interceptor binding
getInterceptorBindingHashCode
(Annotation
the interceptor binding to consider
interceptorBinding
)

Determine the hash code of an interceptor binding, using the JDK algorithm for determining an annotation hash code, ignoring any members annotated with Nonbinding.

public Bean<?>

Returns:

a Bean that implements PassivationCapable and has the given identifier, or a null value if there is no such bean
getPassivationCapableBean
(String
the identifier
id
)

Returns the PassivationCapable bean with the given identifier.

public <
the declaring type
X
>
ProducerFactory<X>

Returns:

the producer factory for the field
getProducerFactory
(AnnotatedField<? super X>
the field to create the producer factory for
field
,
Bean<X>
the bean declaring the producer. May be null if the producer is static or the declaring object is non-contextual
declaringBean
)

An implementation of ProducerFactory that provides container created Producer instances for the given field.

public <
bean type
X
>
ProducerFactory<X>

Returns:

the producer factory for the method
getProducerFactory
(AnnotatedMethod<? super X>
the method to create the producer factory for
method
,
Bean<X>
the bean declaring the producer. May be null if the producer is static or the declaring object is non-contextual
declaringBean
)

An implementation of ProducerFactory that provides container created Producer instances for the given method.

public int

Returns:

the hashCode for the qualifier
getQualifierHashCode
(Annotation
the qualifier to consider
qualifier
)

Determine the hash code of a qualifier, using the JDK algorithm for determining an annotation hash code, ignoring any members annotated with Nonbinding.

public Set<Annotation>

Returns:

the set of meta-annotations
getStereotypeDefinition
(Class<? extends Annotation> stereotype)

Obtains meta-annotations for a certain stereotype.

public boolean

Returns:

true if the annotation type is a passivating scope type
isPassivatingScope
(Class<? extends Annotation>
the annotation type
annotationType
)

Test the given annotation type to determine if it is a passivating scope type.

public List<Decorator<?>>

Returns:

the resulting set of decorators
resolveDecorators
(Set<Type>
the set of bean types of the decorated bean
types
,
Annotation...
the qualifiers declared by the decorated bean
qualifiers
)

Return an ordered list of decorators for a set of bean types and a set of qualifiers and which are enabled in the module or library containing the class into which the BeanManager was injected or the Java EE component from whose JNDI environment namespace the BeanManager was obtained.

public void
validate(InjectionPoint
the injection point to validate
injectionPoint
)

Validate a certain injection point.

public ExpressionFactory

Returns:

the wrapped jakarta.el.ExpressionFactory
wrapExpressionFactory
(ExpressionFactory expressionFactory)
Deprecated for removal since 4.1. use ELAwareBeanManager, this method will be removed in CDI 5.0

Returns a wrapper jakarta.el.ExpressionFactory that delegates jakarta.el.MethodExpression and jakarta.el.ValueExpression creation to the given jakarta.el.ExpressionFactory.

Inherited from jakarta.enterprise.inject.spi.BeanContainer:
createCreationalContextcreateInstancegetBeansgetBeansgetContextgetEventgetReferenceisInterceptorBindingisNormalScopeisQualifierisScopeisStereotyperesolveresolveInterceptorsresolveObserverMethods

Method Detail

areInterceptorBindingsEquivalentback to summary
public boolean areInterceptorBindingsEquivalent(Annotation interceptorBinding1, Annotation interceptorBinding2)

Determine if two interceptor bindings are considered equivalent for the purposes of typesafe resolution, taking into account any members annotated with Nonbinding.

Parameters
interceptorBinding1:Annotation

an interceptor binding to check

interceptorBinding2:Annotation

an interceptor binding to check

Returns:boolean

true if the two interceptor bindings are equivalent, otherwise false

Since
1.1
areQualifiersEquivalentback to summary
public boolean areQualifiersEquivalent(Annotation qualifier1, Annotation qualifier2)

Determine if two qualifiers are considered equivalent for the purposes of typesafe resolution, taking into account any members annotated with Nonbinding.

Parameters
qualifier1:Annotation

a qualifier to check

qualifier2:Annotation

a qualifier to check

Returns:boolean

true if the two qualifiers are equivalent, otherwise false

Since
1.1
createAnnotatedTypeback to summary
public <T> AnnotatedType<T> createAnnotatedType(Class<T> type)

Obtain an AnnotatedType that may be used to read the annotations of the given class or interface.

Parameters
<T>
the class or interface
type:Class<T>

the java.lang.Class object

Returns:AnnotatedType<T>

the AnnotatedType

createBeanback to summary
public <T> Bean<T> createBean(BeanAttributes<T> attributes, Class<T> beanClass, InjectionTargetFactory<T> injectionTargetFactory)

Obtains a Bean for the given BeanAttributes, bean class and InjectionTarget.

The InjectionTarget creates and destroys instances of the bean, performs dependency injection and lifecycle callbacks, and determines the return value of Bean#getInjectionPoints(). The InjectionTarget is obtained from the InjectionTargetFactory. getInjectionTargetFactory(AnnotatedType) allows use of a container created InjectionTarget.

Parameters
<T>
the type
attributes:BeanAttributes<T>

a BeanAttributes which determines the bean types, qualifiers, scope, name and stereotypes of the returned Bean, and the return value of Bean#isAlternative()

beanClass:Class<T>

a class, which determines the return value of Bean#getBeanClass()

injectionTargetFactory:InjectionTargetFactory<T>

an InjectionTargetFactory, used to obtain an InjectionTarget

Returns:Bean<T>

a container provided implementation of Bean

Since
1.1
createBeanback to summary
public <T, X> Bean<T> createBean(BeanAttributes<T> attributes, Class<X> beanClass, ProducerFactory<X> producerFactory)

Obtains a Bean for the given BeanAttributes, bean class and Producer.

The Producer creates and destroys instances of the decorator, and determines the return value of Bean#getInjectionPoints(). The Producer is obtained from the ProducerFactory. getProducerFactory(AnnotatedMethod, Bean) or getProducerFactory(AnnotatedField, Bean) allows use of a container created Producer.

Parameters
<T>
the type
<X>
the type of the declaring bean
attributes:BeanAttributes<T>

a BeanAttributes which determines the bean types, qualifiers, scope, name and stereotypes of the returned Bean, and the return value of Bean#isAlternative()

beanClass:Class<X>

a class, which determines the return value of Bean.getClass()

producerFactory:ProducerFactory<X>

a ProducerFactory, used to obtain a Producer

Returns:Bean<T>

a container provided implementation of Bean

Since
1.1
createBeanAttributesback to summary
public <T> BeanAttributes<T> createBeanAttributes(AnnotatedType<T> type)

Obtains a BeanAttributes for the given AnnotatedType. The container ignores the annotations and types declared by the elements of the actual Java class and uses the metadata provided via the Annotated interface instead.

Parameters
<T>
the type
type:AnnotatedType<T>

the AnnotatedType

Returns:BeanAttributes<T>

a container provided implementation of InjectionTarget

Since
1.1
createBeanAttributesback to summary
public BeanAttributes<?> createBeanAttributes(AnnotatedMember<?> type)

Obtains a BeanAttributes for the given AnnotatedType. The container ignores the annotations and types declared by the elements of the actual Java class and uses the metadata provided via the Annotated interface instead.

Parameters
type:AnnotatedMember<?>

the AnnotatedType

Returns:BeanAttributes<?>

a container provided implementation of InjectionTarget

Since
1.1
createInjectionPointback to summary
public InjectionPoint createInjectionPoint(AnnotatedField<?> field)

Obtains a container provided implementation of InjectionPoint for the given AnnotatedField.

Parameters
field:AnnotatedField<?>

the AnnotatedField defining the injection point

Returns:InjectionPoint

the container provided InjectionPoint

Exceptions
IllegalArgumentException:
if there is a definition error associated with the injection point
Since
1.1
createInjectionPointback to summary
public InjectionPoint createInjectionPoint(AnnotatedParameter<?> parameter)

Obtains a container provided implementation of InjectionPoint for the given AnnotatedParameter.

Parameters
parameter:AnnotatedParameter<?>

the AnnotatedParameter defining the injection point

Returns:InjectionPoint

the container provided InjectionPoint

Exceptions
IllegalArgumentException:
if there is a definition error associated with the injection point
Since
1.1
createInterceptionFactoryback to summary
public <T> InterceptionFactory<T> createInterceptionFactory(CreationalContext<T> ctx, Class<T> clazz)

Create an InterceptionFactory for the given CreationalContext and type.

Parameters
<T>
type of the instance this factory will work on
ctx:CreationalContext<T>

CreationalContext for the InterceptionFactory to create

clazz:Class<T>

class of the instance this factory will work on

Returns:InterceptionFactory<T>

a new InterceptionFactory to add services on on instances of T

Since
2.0
getELResolverback to summary
public ELResolver getELResolver()

Deprecated

for removal since 4.1.

use ELAwareBeanManager, this method will be removed in CDI 5.0

Returns a jakarta.el.ELResolver that resolves beans by EL name.

Returns:ELResolver

the jakarta.el.ELResolver

Annotations
@Deprecated
since:4.1
forRemoval:true
getExtensionback to summary
public <T extends Extension> T getExtension(Class<T> extensionClass)

Obtains the container's instance of an Extension class declared in META-INF/services.

Parameters
<T>
the type of the extension
extensionClass:Class<T>

the type of the extension class

Returns:T

the extension instance

Exceptions
IllegalArgumentException:
if the container has no instance of the given class
Since
1.1
getInjectableReferenceback to summary
public Object getInjectableReference(InjectionPoint ij, CreationalContext<?> ctx)

Obtains an injectable reference for a certain injection point.

Parameters
ij:InjectionPoint

the target injection point

ctx:CreationalContext<?>

a CreationalContext that may be used to destroy any object with scope Dependent that is created

Returns:Object

the injectable reference

Exceptions
UnsatisfiedResolutionException:
if typesafe resolution results in an unsatisfied dependency
AmbiguousResolutionException:
typesafe resolution results in an unresolvable ambiguous dependency
IllegalStateException:
if called during application initialization, before the AfterDeploymentValidation event is fired.
getInjectionTargetFactoryback to summary
public <T> InjectionTargetFactory<T> getInjectionTargetFactory(AnnotatedType<T> annotatedType)

An implementation of InjectionTargetFactory that provides container created InjectionTarget instances.

This factory can be wrapped to add behavior to container created injection targets.

Parameters
<T>
the type
annotatedType:AnnotatedType<T>

the annotated type to create the injection target factory for

Returns:InjectionTargetFactory<T>

an InjectionTargetFactory

Since
1.1
getInterceptorBindingDefinitionback to summary
public Set<Annotation> getInterceptorBindingDefinition(Class<? extends Annotation> bindingType)

Obtains the set of meta-annotations for a certain interceptor binding type .

Parameters
bindingType:Class<? extends Annotation>

the interceptor binding type

Returns:Set<Annotation>

the set of meta-annotations

getInterceptorBindingHashCodeback to summary
public int getInterceptorBindingHashCode(Annotation interceptorBinding)

Determine the hash code of an interceptor binding, using the JDK algorithm for determining an annotation hash code, ignoring any members annotated with Nonbinding.

Parameters
interceptorBinding:Annotation

the interceptor binding to consider

Returns:int

the hashCode for the interceptor binding

Since
1.1
getPassivationCapableBeanback to summary
public Bean<?> getPassivationCapableBean(String id)

Returns the PassivationCapable bean with the given identifier. Note that when called during invocation of an AfterBeanDiscovery event observer, this method will only return beans discovered by the container before the AfterBeanDiscovery event is fired.

Parameters
id:String

the identifier

Returns:Bean<?>

a Bean that implements PassivationCapable and has the given identifier, or a null value if there is no such bean

Exceptions
IllegalStateException:
if called during application initialization, before the AfterBeanDiscovery event is fired.
getProducerFactoryback to summary
public <X> ProducerFactory<X> getProducerFactory(AnnotatedField<? super X> field, Bean<X> declaringBean)

An implementation of ProducerFactory that provides container created Producer instances for the given field.

This factory can be wrapped to add behavior to container created producers.

Parameters
<X>
the declaring type
field:AnnotatedField<? super X>

the field to create the producer factory for

declaringBean:Bean<X>

the bean declaring the producer. May be null if the producer is static or the declaring object is non-contextual

Returns:ProducerFactory<X>

the producer factory for the field

Since
1.1
getProducerFactoryback to summary
public <X> ProducerFactory<X> getProducerFactory(AnnotatedMethod<? super X> method, Bean<X> declaringBean)

An implementation of ProducerFactory that provides container created Producer instances for the given method.

This factory can be wrapped to add behavior to container created producers.

Parameters
<X>
bean type
method:AnnotatedMethod<? super X>

the method to create the producer factory for

declaringBean:Bean<X>

the bean declaring the producer. May be null if the producer is static or the declaring object is non-contextual

Returns:ProducerFactory<X>

the producer factory for the method

Since
1.1
getQualifierHashCodeback to summary
public int getQualifierHashCode(Annotation qualifier)

Determine the hash code of a qualifier, using the JDK algorithm for determining an annotation hash code, ignoring any members annotated with Nonbinding.

Parameters
qualifier:Annotation

the qualifier to consider

Returns:int

the hashCode for the qualifier

Since
1.1
getStereotypeDefinitionback to summary
public Set<Annotation> getStereotypeDefinition(Class<? extends Annotation> stereotype)

Obtains meta-annotations for a certain stereotype.

Parameters
stereotype:Class<? extends Annotation>

the stereotype

Returns:Set<Annotation>

the set of meta-annotations

isPassivatingScopeback to summary
public boolean isPassivatingScope(Class<? extends Annotation> annotationType)

Test the given annotation type to determine if it is a passivating scope type.

Parameters
annotationType:Class<? extends Annotation>

the annotation type

Returns:boolean

true if the annotation type is a passivating scope type

resolveDecoratorsback to summary
public List<Decorator<?>> resolveDecorators(Set<Type> types, Annotation... qualifiers)

Return an ordered list of decorators for a set of bean types and a set of qualifiers and which are enabled in the module or library containing the class into which the BeanManager was injected or the Java EE component from whose JNDI environment namespace the BeanManager was obtained. Note that when called during invocation of an AfterBeanDiscovery event observer, this method will only return decorators discovered by the container before the AfterBeanDiscovery event is fired.

Parameters
types:Set<Type>

the set of bean types of the decorated bean

qualifiers:Annotation[]

the qualifiers declared by the decorated bean

Returns:List<Decorator<?>>

the resulting set of decorators

Exceptions
IllegalArgumentException:
  • if the set of bean types is empty
  • if an annotation which is not a binding type is passed
  • if two instances of the same binding type are passed
IllegalStateException:
if called during application initialization, before the AfterBeanDiscovery event is fired.
validateback to summary
public void validate(InjectionPoint injectionPoint)

Validate a certain injection point. Note that when called during invocation of an AfterBeanDiscovery event observer, this method will only validate injection points discovered by the container before the AfterBeanDiscovery event is fired.

Parameters
injectionPoint:InjectionPoint

the injection point to validate

Exceptions
InjectionException:
if there is a deployment problem (for example, an unsatisfied or unresolvable ambiguous dependency) associated with the injection point
IllegalStateException:
if called during application initialization, before the AfterBeanDiscovery event is fired.
wrapExpressionFactoryback to summary
public ExpressionFactory wrapExpressionFactory(ExpressionFactory expressionFactory)

Deprecated

for removal since 4.1.

use ELAwareBeanManager, this method will be removed in CDI 5.0

Returns a wrapper jakarta.el.ExpressionFactory that delegates jakarta.el.MethodExpression and jakarta.el.ValueExpression creation to the given jakarta.el.ExpressionFactory. When a Unified EL expression is evaluated using a jakarta.el.MethodExpression or jakarta.el.ValueExpression returned by the wrapper jakarta.el.ExpressionFactory, the container handles destruction of objects with scope Dependent.

Parameters
expressionFactory:ExpressionFactory

the jakarta.el.ExpressionFactory to wrap

Returns:ExpressionFactory

the wrapped jakarta.el.ExpressionFactory

Annotations
@Deprecated
since:4.1
forRemoval:true