Interface BeanManager


  • public interface BeanManager

    The interface BeanManager is the central point for dealing with CDI. The BeanManager provides operations for resolving CDI Beans, obtaining the Contextual References of them, etc. There are operations related with;

    • Firing observer events
    • Creating CreationalContexts
    • Resolution of beans, interceptors, decorators and observers
    • Other utility methods etc..
    • 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 getting
        beanType - bean api type that is implemented by the proxy
        ctx - 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 object
        java.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 type
        qualifiers - required qualifiers
        Returns:
        set of beans
        Throws:
        java.lang.IllegalArgumentException - given bean type is a TypeVariable
        java.lang.IllegalArgumentException - given qualifier annotation is not a qualifier
        java.lang.IllegalArgumentException - same qualifier is given
        java.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 exists
        java.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 object
        qualifiers - event qualifiers
        Throws:
        java.lang.IllegalArgumentException - event object contains a TypeVariable
        java.lang.IllegalArgumentException - given qualifier annotation is not a qualifier
        java.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 object
        qualifiers - 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 bean
        qualifiers - decorated bean qualifiers
        Returns:
        list of decorator
        Throws:
        java.lang.IllegalArgumentException - given qualifier annotation is not a qualifier
        java.lang.IllegalArgumentException - same qualifier is given
        java.lang.IllegalArgumentException - if types is empty set
        java.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 type
        interceptorBindings - interceptor bindings
        Returns:
        list of interceptor
        Throws:
        java.lang.IllegalArgumentException - given binding annotation is not a binding
        java.lang.IllegalArgumentException - same binding is given
        java.lang.IllegalArgumentException - binding is not an interceptor binding
        java.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 exist
        java.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 takes Nonbinding 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 takes Nonbinding 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 a AnnotatedType 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 an InjectionPoint 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 an InjectionPoint 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 InjectionTargets 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 Producers 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 Producers for the given AnnotatedMethod.
      • createBean

        <T> Bean<T> createBean​(BeanAttributes<T> attributes,
                               java.lang.Class<T> beanClass,
                               InjectionTargetFactory<T> injectionTargetFactory)
        Create a Bean from the given bean attributes. This version of the method uses a given InjectionTargetFactory.
        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 a Bean from the given bean attributes. This version of the method uses a given ProducerFactory.
        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 given extensionClass 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