Package com.sun.faces.cdi
Class CdiUtils
- java.lang.Object
-
- com.sun.faces.cdi.CdiUtils
-
public final class CdiUtils extends Object
A static utility class for CDI.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addAnnotatedTypes(jakarta.enterprise.inject.spi.BeforeBeanDiscovery beforeBean, jakarta.enterprise.inject.spi.BeanManager beanManager, Class<?>... types)
static Behavior
createBehavior(jakarta.enterprise.inject.spi.BeanManager beanManager, String value)
Create a behavior using the FacesBehavior value attribute.static Converter<?>
createConverter(jakarta.enterprise.inject.spi.BeanManager beanManager, Class<?> forClass)
Create a converter using the FacesConverter forClass attribute.static Converter<?>
createConverter(jakarta.enterprise.inject.spi.BeanManager beanManager, String value)
Create a converter using the FacesConverter value attribute.static DataModel<?>
createDataModel(Class<?> forClass)
static Validator<?>
createValidator(jakarta.enterprise.inject.spi.BeanManager beanManager, String value)
Create a validator using the FacesValidator value attribute.static <A extends Annotation>
Optional<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 accountstatic <T> T
getBeanInstance(Class<T> type, boolean create)
Returns concrete (non-proxied) bean instance of given class in current context.static <T> T
getBeanReference(jakarta.enterprise.inject.spi.BeanManager beanManager, Class<T> type, Annotation... qualifiers)
static <T> T
getBeanReference(FacesContext facesContext, Class<T> type, Annotation... qualifiers)
static <T> T
getBeanReference(Class<T> type, Annotation... qualifiers)
static Object
getBeanReferenceByType(jakarta.enterprise.inject.spi.BeanManager beanManager, Type type, Annotation... qualifiers)
static jakarta.enterprise.inject.spi.InjectionPoint
getCurrentInjectionPoint(jakarta.enterprise.inject.spi.BeanManager beanManager, jakarta.enterprise.context.spi.CreationalContext<?> creationalContext)
Returns the current injection point.static Map<Class<?>,Class<? extends DataModel<?>>>
getDataModelClassesMap(jakarta.enterprise.inject.spi.CDI<Object> cdi)
static <A extends Annotation>
AgetQualifier(jakarta.enterprise.inject.spi.InjectionPoint injectionPoint, Class<A> qualifierClass)
Returns the qualifier annotation of the given qualifier class from the given injection point.static <S extends Annotation>
booleanisScopeActive(Class<S> scope)
Returns true if given scope is active in current context.
-
-
-
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(FacesContext facesContext, 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 managertype
- the required bean type the reference must havequalifiers
- 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 havecreate
- whether to auto-create bean if not exist- Returns:
- a bean instance adhering to the required type
-
getAnnotation
public static <A extends Annotation> Optional<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 managerannotated
- the Annotated in which to searchannotationType
- 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.
-
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 managercreationalContext
- 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 pointqualifierClass
- 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
-
-