Package javax.enterprise.inject.spi
Interface BeanManager
-
public interface BeanManager
The interface
BeanManager
is the central point for dealing with CDI. The BeanManager provides operations for resolving CDIBean
s, obtaining the Contextual References of them, etc. There are operations related with;- Firing observer events
- Creating
CreationalContext
s - Resolution of beans, interceptors, decorators and observers
- Other utility methods etc..
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
areInterceptorBindingsEquivalent(java.lang.annotation.Annotation interceptorBinding1, java.lang.annotation.Annotation interceptorBinding2)
Check whether the 2 given Interceptor Binding annotations are the same.boolean
areQualifiersEquivalent(java.lang.annotation.Annotation qualifier1, java.lang.annotation.Annotation qualifier2)
Check whether the 2 given qualifiers are the same.<T> AnnotatedType<T>
createAnnotatedType(java.lang.Class<T> type)
Returns aAnnotatedType
instance for the given class.<T> Bean<T>
createBean(BeanAttributes<T> attributes, java.lang.Class<T> beanClass, InjectionTargetFactory<T> injectionTargetFactory)
Create aBean
from the given bean attributes.<T,X>
Bean<T>createBean(BeanAttributes<T> attributes, java.lang.Class<X> beanClass, ProducerFactory<X> producerFactory)
Create aBean
from the given bean attributes.BeanAttributes<?>
createBeanAttributes(AnnotatedMember<?> member)
This method creates bean meta information from a givenAnnotatedMember
.<T> BeanAttributes<T>
createBeanAttributes(AnnotatedType<T> type)
This method creates bean meta information from a givenAnnotatedType
.<T> CreationalContext<T>
createCreationalContext(Contextual<T> contextual)
Returns a new creational context implementation.InjectionPoint
createInjectionPoint(AnnotatedField<?> field)
Create anInjectionPoint
for an annotated field.InjectionPoint
createInjectionPoint(AnnotatedParameter<?> parameter)
Create anInjectionPoint
for an annotated parameter.<T> InjectionTarget<T>
createInjectionTarget(AnnotatedType<T> type)
Creates a new instance of injection target Bean.void
fireEvent(java.lang.Object event, java.lang.annotation.Annotation... qualifiers)
Fires an event with given even object and qualifiers.java.util.Set<Bean<?>>
getBeans(java.lang.reflect.Type beanType, java.lang.annotation.Annotation... qualifiers)
Returns set of beans that their api types contain given bean type and given qualifiers.java.util.Set<Bean<?>>
getBeans(java.lang.String name)
Returns set of beans with given Expression Language name.Context
getContext(java.lang.Class<? extends java.lang.annotation.Annotation> scope)
Returns a context with given scope type.javax.el.ELResolver
getELResolver()
Returns CDI container Expression Language resolver.<T extends Extension>
TgetExtension(java.lang.Class<T> extensionClass)
Resolves the Extension instance which gets used by this very BeanManager.java.lang.Object
getInjectableReference(InjectionPoint injectionPoint, CreationalContext<?> ctx)
Gets injection point bean reference.<T> InjectionTargetFactory<T>
getInjectionTargetFactory(AnnotatedType<T> type)
java.util.Set<java.lang.annotation.Annotation>
getInterceptorBindingDefinition(java.lang.Class<? extends java.lang.annotation.Annotation> qualifier)
Returns a set of meta-annotations that are defined on the bindingint
getInterceptorBindingHashCode(java.lang.annotation.Annotation interceptorBinding)
Bean<?>
getPassivationCapableBean(java.lang.String id)
Returns passivation capable bean given id.<X> ProducerFactory<X>
getProducerFactory(AnnotatedField<? super X> field, Bean<X> declaringBean)
<X> ProducerFactory<X>
getProducerFactory(AnnotatedMethod<? super X> method, Bean<X> declaringBean)
int
getQualifierHashCode(java.lang.annotation.Annotation qualifier)
java.lang.Object
getReference(Bean<?> bean, java.lang.reflect.Type beanType, CreationalContext<?> ctx)
Returns a bean instance reference for the given bean.java.util.Set<java.lang.annotation.Annotation>
getStereotypeDefinition(java.lang.Class<? extends java.lang.annotation.Annotation> stereotype)
Returns a set of meta-annotations that are defined on the stereotype type.boolean
isInterceptorBinding(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a interceptor binding, false otherwise.boolean
isNormalScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a normal scope type, false otherwise.boolean
isPassivatingScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a passivating scope type, false otherwise.boolean
isQualifier(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a qualifier, false otherwise.boolean
isScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a scope type, false otherwise.boolean
isStereotype(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a stereotype type, false otherwise.<X> Bean<? extends X>
resolve(java.util.Set<Bean<? extends X>> beans)
Returns a bean object that is resolved according to the type safe resolution rules.java.util.List<Decorator<?>>
resolveDecorators(java.util.Set<java.lang.reflect.Type> types, java.lang.annotation.Annotation... qualifiers)
Returns a list of decorator.java.util.List<Interceptor<?>>
resolveInterceptors(InterceptionType type, java.lang.annotation.Annotation... interceptorBindings)
Returns a list of interceptor.<T> java.util.Set<ObserverMethod<? super T>>
resolveObserverMethods(T event, java.lang.annotation.Annotation... qualifiers)
Returns set of observer methods.void
validate(InjectionPoint injectionPoint)
Validates injection point.javax.el.ExpressionFactory
wrapExpressionFactory(javax.el.ExpressionFactory expressionFactory)
Wrapped around given expression factory and add CDI functionality.
-
-
-
Method Detail
-
getReference
java.lang.Object getReference(Bean<?> bean, java.lang.reflect.Type beanType, CreationalContext<?> ctx)
Returns a bean instance reference for the given bean.- Parameters:
bean
- bean that its reference is gettingbeanType
- bean api type that is implemented by the proxyctx
- creational context is used to destroy any object with scope@Dependent
- Returns:
- bean reference
- Throws:
java.lang.IllegalArgumentException
- if given bean type is not api type of the given bean objectjava.lang.IllegalStateException
- if this method gets called before the AfterDeploymentValidation event is fired.
-
getInjectableReference
java.lang.Object getInjectableReference(InjectionPoint injectionPoint, CreationalContext<?> ctx)
Gets injection point bean reference.- Parameters:
injectionPoint
- injection point definitionctx
- creational context that is passed to theContextual.create(CreationalContext)
method- Returns:
- bean reference
- Throws:
UnsatisfiedResolutionException
- if no bean found for the given injection pointAmbiguousResolutionException
- if more than one bean foundjava.lang.IllegalStateException
- if this method gets called before the AfterDeploymentValidation event is fired.
-
createCreationalContext
<T> CreationalContext<T> createCreationalContext(Contextual<T> contextual)
Returns a new creational context implementation.- Returns:
- new creational context
-
getBeans
java.util.Set<Bean<?>> getBeans(java.lang.reflect.Type beanType, java.lang.annotation.Annotation... qualifiers)
Returns set of beans that their api types contain given bean type and given qualifiers.If no qualifier is given,
@Current
is assumed.- Parameters:
beanType
- required bean typequalifiers
- required qualifiers- Returns:
- set of beans
- Throws:
java.lang.IllegalArgumentException
- given bean type is aTypeVariable
java.lang.IllegalArgumentException
- given qualifier annotation is not a qualifierjava.lang.IllegalArgumentException
- same qualifier is givenjava.lang.IllegalStateException
- if this method gets called before the AfterBeanDiscovery event is fired.
-
getBeans
java.util.Set<Bean<?>> getBeans(java.lang.String name)
Returns set of beans with given Expression Language name.- Parameters:
name
- name of the bean- Returns:
- set of beans with given name
- Throws:
java.lang.IllegalStateException
- if this method gets called before the AfterBeanDiscovery event is fired.
-
getPassivationCapableBean
Bean<?> getPassivationCapableBean(java.lang.String id)
Returns passivation capable bean given id.- Parameters:
id
- bean id- Returns:
- passivation capable bean given id
- Throws:
java.lang.IllegalStateException
- if this method gets called before the AfterBeanDiscovery event is fired.
-
resolve
<X> Bean<? extends X> resolve(java.util.Set<Bean<? extends X>> beans)
Returns a bean object that is resolved according to the type safe resolution rules.- Type Parameters:
X
- bean class info- Parameters:
beans
- set of beans- Returns:
- bean that is resolved according to the type safe resolution rules
- Throws:
AmbiguousResolutionException
- if ambigious existsjava.lang.IllegalStateException
- if this method gets called before the AfterBeanDiscovery event is fired.
-
fireEvent
void fireEvent(java.lang.Object event, java.lang.annotation.Annotation... qualifiers)
Fires an event with given even object and qualifiers.- Parameters:
event
- observer event objectqualifiers
- event qualifiers- Throws:
java.lang.IllegalArgumentException
- event object contains aTypeVariable
java.lang.IllegalArgumentException
- given qualifier annotation is not a qualifierjava.lang.IllegalArgumentException
- same qualifier is given
-
resolveObserverMethods
<T> java.util.Set<ObserverMethod<? super T>> resolveObserverMethods(T event, java.lang.annotation.Annotation... qualifiers)
Returns set of observer methods.- Type Parameters:
T
- event type- Parameters:
event
- even objectqualifiers
- event qualifiers- Returns:
- set of observer methods
- Throws:
java.lang.IllegalStateException
- if this method gets called before the AfterBeanDiscovery event is fired.
-
resolveDecorators
java.util.List<Decorator<?>> resolveDecorators(java.util.Set<java.lang.reflect.Type> types, java.lang.annotation.Annotation... qualifiers)
Returns a list of decorator.- Parameters:
types
- bean types of the decorated beanqualifiers
- decorated bean qualifiers- Returns:
- list of decorator
- Throws:
java.lang.IllegalArgumentException
- given qualifier annotation is not a qualifierjava.lang.IllegalArgumentException
- same qualifier is givenjava.lang.IllegalArgumentException
- if types is empty setjava.lang.IllegalStateException
- if this method gets called before the AfterBeanDiscovery event is fired.
-
resolveInterceptors
java.util.List<Interceptor<?>> resolveInterceptors(InterceptionType type, java.lang.annotation.Annotation... interceptorBindings)
Returns a list of interceptor.- Parameters:
type
- interception typeinterceptorBindings
- interceptor bindings- Returns:
- list of interceptor
- Throws:
java.lang.IllegalArgumentException
- given binding annotation is not a bindingjava.lang.IllegalArgumentException
- same binding is givenjava.lang.IllegalArgumentException
- binding is not an interceptor bindingjava.lang.IllegalStateException
- if this method gets called before the AfterBeanDiscovery event is fired.
-
validate
void validate(InjectionPoint injectionPoint)
Validates injection point.- Parameters:
injectionPoint
- injection point- Throws:
InjectionException
- if problem existjava.lang.IllegalStateException
- if this method gets called before the AfterBeanDiscovery event is fired.
-
isScope
boolean isScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a scope type, false otherwise.- Parameters:
annotationType
- annotation type- Returns:
- true if given type is a scope type, false otherwise
-
isNormalScope
boolean isNormalScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a normal scope type, false otherwise.- Parameters:
annotationType
- annotation type- Returns:
- true if given type is a scope type, false otherwise
-
isPassivatingScope
boolean isPassivatingScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a passivating scope type, false otherwise.- Parameters:
annotationType
- annotation type- Returns:
- true if given type is a scope type, false otherwise
-
isQualifier
boolean isQualifier(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a qualifier, false otherwise.- Parameters:
annotationType
- annotation type- Returns:
- true if given type is a qualifier, false otherwise
-
areQualifiersEquivalent
boolean areQualifiersEquivalent(java.lang.annotation.Annotation qualifier1, java.lang.annotation.Annotation qualifier2)
Check whether the 2 given qualifiers are the same. This takesNonbinding
into account by ignoring those properties.- Parameters:
qualifier1
-qualifier2
-- Returns:
true
if all non-nonbinding attributes are equals,false
otherwise
-
getQualifierHashCode
int getQualifierHashCode(java.lang.annotation.Annotation qualifier)
- Parameters:
qualifier
-- Returns:
- the hashCode of the Annotation. All
Nonbinding
fields get ignored
-
isInterceptorBinding
boolean isInterceptorBinding(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a interceptor binding, false otherwise.- Parameters:
annotationType
- annotation type- Returns:
- true if given type is a interceptor binding, false otherwise
-
areInterceptorBindingsEquivalent
boolean areInterceptorBindingsEquivalent(java.lang.annotation.Annotation interceptorBinding1, java.lang.annotation.Annotation interceptorBinding2)
Check whether the 2 given Interceptor Binding annotations are the same. This takesNonbinding
into account by ignoring those properties.- Parameters:
interceptorBinding1
-interceptorBinding2
-- Returns:
true
if all non-nonbinding attributes are equals,false
otherwise
-
getInterceptorBindingHashCode
int getInterceptorBindingHashCode(java.lang.annotation.Annotation interceptorBinding)
- Parameters:
interceptorBinding
-- Returns:
- the hashCode of the Annotation. All
Nonbinding
fields get ignored
-
isStereotype
boolean isStereotype(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if given type is a stereotype type, false otherwise.- Parameters:
annotationType
- annotation type- Returns:
- true if given type is a stereotype, false otherwise
-
getInterceptorBindingDefinition
java.util.Set<java.lang.annotation.Annotation> getInterceptorBindingDefinition(java.lang.Class<? extends java.lang.annotation.Annotation> qualifier)
Returns a set of meta-annotations that are defined on the binding- Parameters:
qualifier
- binding class- Returns:
- a set of meta-annotations that are defined on the binding
-
getStereotypeDefinition
java.util.Set<java.lang.annotation.Annotation> getStereotypeDefinition(java.lang.Class<? extends java.lang.annotation.Annotation> stereotype)
Returns a set of meta-annotations that are defined on the stereotype type.- Parameters:
stereotype
- stereotype type class- Returns:
- a set of meta-annotations that are defined on the stereotype type
-
getContext
Context getContext(java.lang.Class<? extends java.lang.annotation.Annotation> scope)
Returns a context with given scope type.- Parameters:
scope
- scope type class type- Returns:
- a context with given scope type
-
getELResolver
javax.el.ELResolver getELResolver()
Returns CDI container Expression Language resolver.- Returns:
- el resolver
-
createAnnotatedType
<T> AnnotatedType<T> createAnnotatedType(java.lang.Class<T> type)
Returns aAnnotatedType
instance for the given class.- Type Parameters:
T
- class type- Parameters:
type
- class- Returns:
- a
AnnotatedType
instance
-
createInjectionTarget
<T> InjectionTarget<T> createInjectionTarget(AnnotatedType<T> type)
Creates a new instance of injection target Bean.- Type Parameters:
T
- bean type- Parameters:
type
- annotated type- Returns:
- injection target
-
createInjectionPoint
InjectionPoint createInjectionPoint(AnnotatedField<?> field)
Create anInjectionPoint
for an annotated field.- Parameters:
field
-- Returns:
- injection point
- Throws:
java.lang.IllegalArgumentException
- if there is a definition error on the given field
-
createInjectionPoint
InjectionPoint createInjectionPoint(AnnotatedParameter<?> parameter)
Create anInjectionPoint
for an annotated parameter.- Parameters:
parameter
-- Returns:
- injection point
- Throws:
java.lang.IllegalArgumentException
- if there is a definition error on the given parameter
-
getInjectionTargetFactory
<T> InjectionTargetFactory<T> getInjectionTargetFactory(AnnotatedType<T> type)
- Type Parameters:
T
-- Parameters:
type
-- Returns:
- the InjectionTargetFactory which is able to create
InjectionTarget
s for the given AnnotatedType.
-
getProducerFactory
<X> ProducerFactory<X> getProducerFactory(AnnotatedField<? super X> field, Bean<X> declaringBean)
- Type Parameters:
X
-- Parameters:
field
-declaringBean
-- Returns:
- the ProducerFactory which is able to create
Producer
s for the given AnnotatedField.
-
getProducerFactory
<X> ProducerFactory<X> getProducerFactory(AnnotatedMethod<? super X> method, Bean<X> declaringBean)
- Type Parameters:
X
-- Parameters:
method
-declaringBean
-- Returns:
- the ProducerFactory which is able to create
Producer
s for the given AnnotatedMethod.
-
createBeanAttributes
<T> BeanAttributes<T> createBeanAttributes(AnnotatedType<T> type)
This method creates bean meta information from a givenAnnotatedType
. The created BeanAttributes can later be used to create aBean
viacreateBean(BeanAttributes, Class, InjectionTargetFactory)
orcreateBean(BeanAttributes, Class, ProducerFactory)
- Type Parameters:
T
-- Parameters:
type
-- Returns:
- the BeanAttributes created from parsing the given AnnotatedType
-
createBeanAttributes
BeanAttributes<?> createBeanAttributes(AnnotatedMember<?> member)
This method creates bean meta information from a givenAnnotatedMember
. The created BeanAttributes can later be used to create aBean
viacreateBean(BeanAttributes, Class, InjectionTargetFactory)
orcreateBean(BeanAttributes, Class, ProducerFactory)
.- Parameters:
member
-- Returns:
- the BeanAttributes created from parsing the given AnnotatedType
-
createBean
<T> Bean<T> createBean(BeanAttributes<T> attributes, java.lang.Class<T> beanClass, InjectionTargetFactory<T> injectionTargetFactory)
Create aBean
from the given bean attributes. This version of the method uses a givenInjectionTargetFactory
.- Type Parameters:
T
-- Parameters:
attributes
-beanClass
-injectionTargetFactory
-- Returns:
- the container created Bean
-
createBean
<T,X> Bean<T> createBean(BeanAttributes<T> attributes, java.lang.Class<X> beanClass, ProducerFactory<X> producerFactory)
Create aBean
from the given bean attributes. This version of the method uses a givenProducerFactory
.- Type Parameters:
T
-- Parameters:
attributes
-beanClass
-producerFactory
-- Returns:
- the container created Bean
-
getExtension
<T extends Extension> T getExtension(java.lang.Class<T> extensionClass)
Resolves the Extension instance which gets used by this very BeanManager. The givenextensionClass
must be the effective class registered into META-INF/services and not some base class.- Type Parameters:
T
-- Parameters:
extensionClass
-- Returns:
- the Extension instance of this very BeanManager
-
wrapExpressionFactory
javax.el.ExpressionFactory wrapExpressionFactory(javax.el.ExpressionFactory expressionFactory)
Wrapped around given expression factory and add CDI functionality.- Parameters:
expressionFactory
- expression factory- Returns:
- wrapped expression factory
-
-