javax.enterprise.inject.spi
Interface BeanManager


public interface BeanManager

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.

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.

Any operation of BeanManager may be called at any time during the execution of the application.

Author:
Gavin King, Pete Muir, Clint Popetz, David Allen

Method Summary
<T> AnnotatedType<T>
createAnnotatedType(java.lang.Class<T> type)
          Get an AnnotatedType for the given class
<T> CreationalContext<T>
createCreationalContext(Contextual<T> contextual)
          Obtain an instance of a CreationalContext for the given contextual
<T> InjectionTarget<T>
createInjectionTarget(AnnotatedType<T> type)
          Returns an InjectionTarget to allow injection into custom beans or non-contextual instances by portable extensions.
 void fireEvent(java.lang.Object event, java.lang.annotation.Annotation... qualifiers)
          Fires an event and notifies observers.
 java.util.Set<Bean<?>> getBeans(java.lang.String name)
          Returns the set of beans which have the given EL name and are available for injection 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, according to the rules of EL name resolution.
 java.util.Set<Bean<?>> getBeans(java.lang.reflect.Type beanType, java.lang.annotation.Annotation... qualifiers)
          Returns the set of beans which have the given required type and qualifiers and are available for injection 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, according to the rules of typesafe resolution.
 Context getContext(java.lang.Class<? extends java.lang.annotation.Annotation> scopeType)
          Obtains an active context instance for the given scope type.
 javax.el.ELResolver getELResolver()
          Returns the ELResolver for integration with the servlet engine and JSF implementation.
 java.lang.Object getInjectableReference(InjectionPoint ij, CreationalContext<?> ctx)
          Obtains an instance of bean for a given injection point.
 java.util.Set<java.lang.annotation.Annotation> getInterceptorBindingTypeDefinition(java.lang.Class<? extends java.lang.annotation.Annotation> bindingType)
          Obtains the set of meta-annotations for an interceptor binding type.
<X> Bean<? extends X>
getMostSpecializedBean(Bean<X> bean)
          Returns the Bean object representing the most specialized enabled bean registered with the container that specializes the given bean,
 Bean<?> getPassivationCapableBean(java.lang.String id)
          Returns the PassivationCapableBean with the given identifier.
 java.lang.Object getReference(Bean<?> bean, java.lang.reflect.Type beanType, CreationalContext<?> ctx)
          Obtains a contextual reference for a given bean and a given bean type.
 java.util.Set<java.lang.annotation.Annotation> getStereotypeDefinition(java.lang.Class<? extends java.lang.annotation.Annotation> stereotype)
          Obtains meta-annotations for a stereotype.
 boolean isInterceptorBindingType(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
          Tests the given annotationType to determine if it is an interceptor binding type.
 boolean isNormalScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
          Tests the given annotationType to determine if it is a normal scope type.
 boolean isPassivatingScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
          Tests the given annotationType to determine if it is a passivating scope type.
 boolean isQualifier(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
          Tests the given annotationType to determine if it is a qualifier type.
 boolean isScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
          Tests the given annotationType to determine if it is a scope type.
 boolean isStereotype(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
          Tests the given annotationType to determine if it is a stereotype.
<X> Bean<? extends X>
resolve(java.util.Set<Bean<? extends X>> beans)
          Apply the ambiguous dependency resolution rules
 java.util.List<Decorator<?>> resolveDecorators(java.util.Set<java.lang.reflect.Type> types, java.lang.annotation.Annotation... qualifiers)
          Obtains an ordered list of enabled decorators for a set of bean types and a set of qualifiers.
 java.util.List<Interceptor<?>> resolveInterceptors(InterceptionType type, java.lang.annotation.Annotation... interceptorBindings)
          Obtains an ordered list of enabled interceptors for a set of interceptor bindings.
<T> java.util.Set<ObserverMethod<?,T>>
resolveObserverMethods(T event, java.lang.annotation.Annotation... qualifiers)
          Obtains observers for an event by considering event type and qualifiers.
 void validate(InjectionPoint injectionPoint)
          Validates the injection point dependency.
 javax.el.ExpressionFactory wrapExpressionFactory(javax.el.ExpressionFactory expressionFactory)
          Returns a wrapper ExpressionFactory that delegates MethodExpression and ValueExpression creation to the given ExpressionFactory.
 

Method Detail

getReference

java.lang.Object getReference(Bean<?> bean,
                              java.lang.reflect.Type beanType,
                              CreationalContext<?> ctx)
Obtains a contextual reference for a given bean and a given bean type.

Parameters:
bean - the Bean object representing the bean
beanType - a bean type that must be implemented by any proxy that is returned
Returns:
a contextual reference representing the bean
Throws:
java.lang.IllegalArgumentException - if the given type is not a bean type of the given bean

getInjectableReference

java.lang.Object getInjectableReference(InjectionPoint ij,
                                        CreationalContext<?> ctx)
Obtains an instance of bean for a given injection point. This method should not be called by an application.

Parameters:
ij - the injection point the instance is needed for
ctx - the context in which the injection is occurring
Returns:
an instance of the bean
Throws:
UnsatisfiedResolutionException - if no bean can be resolved for the given type and bindings
AmbiguousResolutionException - if more than one bean is resolved for the given type and bindings

createCreationalContext

<T> CreationalContext<T> createCreationalContext(Contextual<T> contextual)
Obtain an instance of a CreationalContext for the given contextual

Parameters:
contextual - the contextual to create a creational context for
Returns:
the CreationalContext instance

getBeans

java.util.Set<Bean<?>> getBeans(java.lang.reflect.Type beanType,
                                java.lang.annotation.Annotation... qualifiers)
Returns the set of beans which have the given required type and qualifiers and are available for injection 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, according to the rules of typesafe resolution.

Parameters:
beanType - the type of the beans to be resolved
qualifiers - the qualifiers used to restrict the matched beans. If no qualifiers are passed to getBeans(), the default binding @Current is assumed.
Returns:
the matched beans
Throws:
java.lang.IllegalArgumentException - if the given type represents a type variable
java.lang.IllegalArgumentException - if two instances of the same binding type are
java.lang.IllegalArgumentException - if an instance of an annotation that is not a binding type is given

getBeans

java.util.Set<Bean<?>> getBeans(java.lang.String name)
Returns the set of beans which have the given EL name and are available for injection 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, according to the rules of EL name resolution.

Parameters:
name - the name used to restrict the beans matched
Returns:
the matched beans

getMostSpecializedBean

<X> Bean<? extends X> getMostSpecializedBean(Bean<X> bean)
Returns the Bean object representing the most specialized enabled bean registered with the container that specializes the given bean,

Type Parameters:
X - the type of the bean
Parameters:
bean - the Bean representation of the bean.
Returns:
the most specialized enabled bean

getPassivationCapableBean

Bean<?> getPassivationCapableBean(java.lang.String id)
Returns the PassivationCapableBean with the given identifier.


resolve

<X> Bean<? extends X> resolve(java.util.Set<Bean<? extends X>> beans)
Apply the ambiguous dependency resolution rules

Type Parameters:
X - the type of the bean
Parameters:
beans - a set of beans of the given type
Throws:
AmbiguousResolutionException - if the ambiguous dependency resolution rules fail

validate

void validate(InjectionPoint injectionPoint)
Validates the injection point dependency.

Parameters:
injectionPoint - the injection point to validate
Throws:
an - InjectionException if there is a deployment problem (for example, an unsatisfied or unresolvable ambiguous dependency) associated with the injection point.

fireEvent

void fireEvent(java.lang.Object event,
               java.lang.annotation.Annotation... qualifiers)
Fires an event and notifies observers.

Parameters:
event - the event object
qualifiers - the event qualifiers used to restrict the observers matched
Throws:
java.lang.IllegalArgumentException - if the runtime type of the event object contains a type variable
java.lang.IllegalArgumentException - if two instances of the same binding type are given
java.lang.IllegalArgumentException - if an instance of an annotation that is not a binding type is given,

resolveObserverMethods

<T> java.util.Set<ObserverMethod<?,T>> resolveObserverMethods(T event,
                                                              java.lang.annotation.Annotation... qualifiers)
Obtains observers for an event by considering event type and qualifiers.

Type Parameters:
T - the type of the event to obtain
Parameters:
event - the event object
qualifiers - the qualifiers used to restrict the matched observers
Returns:
the resolved observers
Throws:
java.lang.IllegalArgumentException - if a parameterized type with a type parameter or a wildcard is passed
java.lang.IllegalArgumentException - if an annotation which is not a event binding type is passed
java.lang.IllegalArgumentException - if two instances of the same binding type are passed

resolveDecorators

java.util.List<Decorator<?>> resolveDecorators(java.util.Set<java.lang.reflect.Type> types,
                                               java.lang.annotation.Annotation... qualifiers)
Obtains an ordered list of enabled decorators for a set of bean types and a set of qualifiers.

Parameters:
types - the set of bean types of the decorated bean
qualifiers - the qualifiers declared by the decorated bean
Returns:
the resolved decorators
Throws:
java.lang.IllegalArgumentException - if the set of bean types is empty
java.lang.IllegalArgumentException - if an annotation which is not a binding type is passed
java.lang.IllegalArgumentException - if two instances of the same binding type are passed

resolveInterceptors

java.util.List<Interceptor<?>> resolveInterceptors(InterceptionType type,
                                                   java.lang.annotation.Annotation... interceptorBindings)
Obtains an ordered list of enabled interceptors for a set of interceptor bindings.

Parameters:
type - the type of the interception
interceptorBindings - the bindings used to restrict the matched interceptors
Returns:
the resolved interceptors
Throws:
java.lang.IllegalArgumentException - if no interceptor binding type is passed
java.lang.IllegalArgumentException - if an annotation which is not a interceptor binding type is passed
java.lang.IllegalArgumentException - if two instances of the same binding type are passed

isScope

boolean isScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Tests the given annotationType to determine if it is a scope type.

Parameters:
annotationType - the annotation to test
Returns:
true if the annotation is a scope type

isNormalScope

boolean isNormalScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Tests the given annotationType to determine if it is a normal scope type.

Parameters:
annotationType - the annotation to test
Returns:
true if the annotation is a normal scope type

isPassivatingScope

boolean isPassivatingScope(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Tests the given annotationType to determine if it is a passivating scope type.

Parameters:
annotationType - the annotation to test
Returns:
true if the annotation is a passivating scope type

isQualifier

boolean isQualifier(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Tests the given annotationType to determine if it is a qualifier type.

Parameters:
annotationType - the annotation to test
Returns:
true if the annotation is a qualifier type

isInterceptorBindingType

boolean isInterceptorBindingType(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Tests the given annotationType to determine if it is an interceptor binding type.

Parameters:
annotationType - the annotation to test
Returns:
true if the annotationType is a interceptor binding type

isStereotype

boolean isStereotype(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Tests the given annotationType to determine if it is a stereotype.

Parameters:
annotationType - the annotation to test
Returns:
true if the annotationType is a stereotype

getInterceptorBindingTypeDefinition

java.util.Set<java.lang.annotation.Annotation> getInterceptorBindingTypeDefinition(java.lang.Class<? extends java.lang.annotation.Annotation> bindingType)
Obtains the set of meta-annotations for an interceptor binding type.

Parameters:
bindingType - the annotation for which to obtain meta-annotations
Returns:
the set of meta-annotations for the given interceptor binding type

getStereotypeDefinition

java.util.Set<java.lang.annotation.Annotation> getStereotypeDefinition(java.lang.Class<? extends java.lang.annotation.Annotation> stereotype)
Obtains meta-annotations for a stereotype.

Parameters:
stereotype - the stereotype for which to obtain meta-annotations
Returns:
the set of meta-annotations for the given stereotype

getContext

Context getContext(java.lang.Class<? extends java.lang.annotation.Annotation> scopeType)
Obtains an active context instance for the given scope type.

Parameters:
scopeType - the scope to get the context instance for
Returns:
the context instance
Throws:
ContextNotActiveException - if no active contexts exist for the given scope type
java.lang.IllegalArgumentException - if more than one active context exists for the given scope type

getELResolver

javax.el.ELResolver getELResolver()
Returns the ELResolver for integration with the servlet engine and JSF implementation. This resolver will return a contextual instance of a bean if the name for resolution resolves to exactly one bean.


wrapExpressionFactory

javax.el.ExpressionFactory wrapExpressionFactory(javax.el.ExpressionFactory expressionFactory)
Returns a wrapper ExpressionFactory that delegates MethodExpression and ValueExpression creation to the given ExpressionFactory. When a Unified EL expression is evaluated using a MethodExpression or ValueExpression returned by the wrapper ExpressionFactory

Parameters:
expressionFactory - the expression factory to wrap
Returns:
the wrapped ExpressionFactory

createAnnotatedType

<T> AnnotatedType<T> createAnnotatedType(java.lang.Class<T> type)
Get an AnnotatedType for the given class

Type Parameters:
T - the type
Parameters:
type - the type
Returns:
the AnnotatedType

createInjectionTarget

<T> InjectionTarget<T> createInjectionTarget(AnnotatedType<T> type)
Returns an InjectionTarget to allow injection into custom beans or non-contextual instances by portable extensions. 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.

Type Parameters:
T - the type of the AnnotatedType to inspect
Parameters:
type - the AnnotatedType to inspect
Throws:
java.lang.IllegalArgumentException - if there is a definition error associated with any injection point of the type.


Copyright © 2008-2009 Seam Framework. All Rights Reserved.