Class CdiUtils


  • public final class CdiUtils
    extends Object
    A static utility class for CDI.
    • Method Detail

      • createConverter

        public static Converter<?> createConverter​(jakarta.enterprise.inject.spi.BeanManager beanManager,
                                                   String value)
        Create a converter using the FacesConverter value attribute.
        Parameters:
        beanManager - the bean manager.
        value - the value attribute.
        Returns:
        the converter, or null if we could not match one.
      • createConverter

        public static Converter<?> createConverter​(jakarta.enterprise.inject.spi.BeanManager beanManager,
                                                   Class<?> forClass)
        Create a converter using the FacesConverter forClass attribute.
        Parameters:
        beanManager - the bean manager.
        forClass - the for class.
        Returns:
        the converter, or null if we could not match one.
      • createBehavior

        public static Behavior createBehavior​(jakarta.enterprise.inject.spi.BeanManager beanManager,
                                              String value)
        Create a behavior using the FacesBehavior value attribute.
        Parameters:
        beanManager - the bean manager.
        value - the value attribute.
        Returns:
        the behavior, or null if we could not match one.
      • createValidator

        public static Validator<?> createValidator​(jakarta.enterprise.inject.spi.BeanManager beanManager,
                                                   String value)
        Create a validator using the FacesValidator value attribute.
        Parameters:
        beanManager - the bean manager.
        value - the value attribute.
        Returns:
        the validator, or null if we could not match one.
      • addAnnotatedTypes

        public static void addAnnotatedTypes​(jakarta.enterprise.inject.spi.BeforeBeanDiscovery beforeBean,
                                             jakarta.enterprise.inject.spi.BeanManager beanManager,
                                             Class<?>... types)
      • getBeanReference

        public static <T> T getBeanReference​(Class<T> type,
                                             Annotation... qualifiers)
      • getBeanReference

        public static <T> T getBeanReference​(jakarta.enterprise.inject.spi.BeanManager beanManager,
                                             Class<T> type,
                                             Annotation... qualifiers)
        Type Parameters:
        T - the generic bean type
        Parameters:
        beanManager - the bean manager
        type - the required bean type the reference must have
        qualifiers - the required qualifiers the reference must have
        Returns:
        a bean reference adhering to the required type and qualifiers
      • getBeanReferenceByType

        public static Object getBeanReferenceByType​(jakarta.enterprise.inject.spi.BeanManager beanManager,
                                                    Type type,
                                                    Annotation... qualifiers)
      • getBeanInstance

        public static <T> T getBeanInstance​(Class<T> type,
                                            boolean create)
        Returns concrete (non-proxied) bean instance of given class in current context.
        Type Parameters:
        T - the generic bean type
        Parameters:
        type - the required bean type the instance must have
        create - whether to auto-create bean if not exist
        Returns:
        a bean instance adhering to the required type
      • getAnnotation

        public static <A extends AnnotationOptional<A> getAnnotation​(jakarta.enterprise.inject.spi.BeanManager beanManager,
                                                                       jakarta.enterprise.inject.spi.Annotated annotated,
                                                                       Class<A> annotationType)
        Finds an annotation in an Annotated, taking stereo types into account
        Type Parameters:
        A - the generic annotation type
        Parameters:
        beanManager - the current bean manager
        annotated - the Annotated in which to search
        annotationType - the type of the annotation to search for
        Returns:
        An Optional that contains an instance of annotation type for which was searched if the annotated contained this.
      • createDataModel

        public static DataModel<?> createDataModel​(Class<?> forClass)
      • getDataModelClassesMap

        public static Map<Class<?>,​Class<? extends DataModel<?>>> getDataModelClassesMap​(jakarta.enterprise.inject.spi.CDI<Object> cdi)
      • getCurrentInjectionPoint

        public static jakarta.enterprise.inject.spi.InjectionPoint getCurrentInjectionPoint​(jakarta.enterprise.inject.spi.BeanManager beanManager,
                                                                                            jakarta.enterprise.context.spi.CreationalContext<?> creationalContext)
        Returns the current injection point.
        Parameters:
        beanManager - the involved bean manager
        creationalContext - the involved creational context
        Returns:
        the current injection point
      • getQualifier

        public static <A extends Annotation> A getQualifier​(jakarta.enterprise.inject.spi.InjectionPoint injectionPoint,
                                                            Class<A> qualifierClass)
        Returns the qualifier annotation of the given qualifier class from the given injection point.
        Type Parameters:
        A - the type of given qualifier class
        Parameters:
        injectionPoint - the injection point
        qualifierClass - the qualifier class to be filtered
        Returns:
        the qualifier annotation
      • isScopeActive

        public static <S extends Annotation> boolean isScopeActive​(Class<S> scope)
        Returns true if given scope is active in current context.
        Type Parameters:
        S - the type of given scope
        Parameters:
        scope - the scope to be checked
        Returns:
        whether given scope is active