/** * Get the Contextual Reference for the given bean. * * @param type the type of the bean in question * @param bean bean-definition for the contextual-reference * @param <T> target type * @return the resolved Contextual Reference */ public static <T> T getContextualReference(Class<T> type, Bean<T> bean) { return getContextualReference(type, getBeanManager(), bean); }
public static <T> DependentProvider<T> getDependent(Class<T> type, Annotation... qualifiers) { BeanManager beanManager = getBeanManager(); return getDependent(beanManager, type, qualifiers); }
public static <T> DependentProvider<T> getDependent(String name) { BeanManager beanManager = getBeanManager(); return getDependent(beanManager, name); }
public static <T> DependentProvider<T> getDependent(Class<T> type, Annotation... qualifiers) { BeanManager beanManager = getBeanManager(); Set<Bean<?>> beans = beanManager.getBeans(type, qualifiers); Bean<?> bean = beanManager.resolve(beans); return createDependentProvider(beanManager, type, (Bean<T>) bean); }
public static <T> DependentProvider<T> getDependent(String name) { BeanManager beanManager = getBeanManager(); return getDependent(beanManager, name); }
public static <T> DependentProvider<T> getDependent(Class<T> type, Annotation... qualifiers) { BeanManager beanManager = getBeanManager(); return getDependent(beanManager, type, qualifiers); }
/** * Get a set of {@link Bean} definitions by type independent of the qualifier. * * @param type the type of the bean in question * @param optional if <code>true</code> it will return an empty set if no bean could be found. * Otherwise it will throw an {@code IllegalStateException} * @param includeDefaultScopedBeans specifies if dependent scoped beans should be included in the result * @param <T> target type * @return the resolved set of {@link Bean} definitions or an empty-set if optional is true */ public static <T> Set<Bean<T>> getBeanDefinitions(Class<T> type, boolean optional, boolean includeDefaultScopedBeans) { BeanManager beanManager = getBeanManager(); return getBeanDefinitions(type, optional, includeDefaultScopedBeans, beanManager); }
/** * Get the Contextual Reference for the given bean. * * <p> * <b>Attention:</b> please see the notes on manually resolving @Dependent beans in * {@link #getContextualReference(Class, java.lang.annotation.Annotation...)}!</p> * * @param type the type of the bean in question * @param bean bean definition for the contextual reference * @param <T> target type * * @return the resolved Contextual Reference */ public static <T> T getContextualReference(Class<T> type, Bean<T> bean) { return getContextualReference(type, getBeanManager(), bean); }
public static <T> DependentProvider<T> getDependent(String name) { BeanManager beanManager = getBeanManager(); Set<Bean<?>> beans = beanManager.getBeans(name); Bean<?> bean = beanManager.resolve(beans); Class beanClass = bean.getBeanClass(); return createDependentProvider(beanManager, (Class<T>) beanClass, (Bean<T>) bean); }
/** * Get the Contextual Reference for the given bean. * * <p> * <b>Attention:</b> please see the notes on manually resolving @Dependent beans in * {@link #getContextualReference(Class, java.lang.annotation.Annotation...)}!</p> * * @param type the type of the bean in question * @param bean bean definition for the contextual reference * @param <T> target type * * @return the resolved Contextual Reference */ public static <T> T getContextualReference(Class<T> type, Bean<T> bean) { return getContextualReference(type, getBeanManager(), bean); }
/** * Get a set of {@link Bean} definitions by type, regardless of qualifiers. * * @param type the type of the bean in question * @param optional if <code>true</code> it will return an empty set if no bean could be found. * Otherwise it will throw an {@code IllegalStateException} * @param includeDefaultScopedBeans specifies whether dependent scoped beans should be included in the result * @param <T> target type * * @return the resolved set of {@link Bean} definitions or an empty set if optional is true */ public static <T> Set<Bean<T>> getBeanDefinitions(Class<T> type, boolean optional, boolean includeDefaultScopedBeans) { BeanManager beanManager = getBeanManager(); return getBeanDefinitions(type, optional, includeDefaultScopedBeans, beanManager); }
/** * {@link #getContextualReference(Class, Annotation...)} which returns <code>null</code> if the * 'optional' parameter is set to <code>true</code>. * * @param type the type of the bean in question * @param optional if <code>true</code> it will return <code>null</code> if no bean could be found or created. * Otherwise it will throw an {@code IllegalStateException} * @param qualifiers additional qualifiers which further distinct the resolved bean * @param <T> target type * @return the resolved Contextual Reference * @see #getContextualReference(Class, Annotation...) */ public static <T> T getContextualReference(Class<T> type, boolean optional, Annotation... qualifiers) { BeanManager beanManager = getBeanManager(); return getContextualReference(beanManager, type, optional, qualifiers); }
/** * Get a set of {@link Bean} definitions by type, regardless of qualifiers. * * @param type the type of the bean in question * @param optional if <code>true</code> it will return an empty set if no bean could be found. * Otherwise it will throw an {@code IllegalStateException} * @param includeDefaultScopedBeans specifies whether dependent scoped beans should be included in the result * @param <T> target type * * @return the resolved set of {@link Bean} definitions or an empty set if optional is true */ public static <T> Set<Bean<T>> getBeanDefinitions(Class<T> type, boolean optional, boolean includeDefaultScopedBeans) { BeanManager beanManager = getBeanManager(); return getBeanDefinitions(type, optional, includeDefaultScopedBeans, beanManager); }
/** * {@link #getContextualReference(Class, Annotation...)} which returns <code>null</code> if the 'optional' parameter * is set to <code>true</code>. * * @param type the type of the bean in question * @param optional if <code>true</code> it will return <code>null</code> if no bean could be found or created. * Otherwise it will throw an {@code IllegalStateException} * @param qualifiers additional qualifiers which distinguish the resolved bean * @param <T> target type * * @return the resolved Contextual Reference * * @see #getContextualReference(Class, Annotation...) */ public static <T> T getContextualReference(Class<T> type, boolean optional, Annotation... qualifiers) { BeanManager beanManager = getBeanManager(); return getContextualReference(beanManager, type, optional, qualifiers); }
/** * Get a Contextual Reference by its EL Name. This only works for beans with the @Named annotation. * * <p> * <b>Attention:</b> please see the notes on manually resolving @Dependent beans in * {@link #getContextualReference(Class, java.lang.annotation.Annotation...)}!</p> * * @param name the EL name of the bean * @param optional if <code>true</code> it will return <code>null</code> if no bean could be found or created. * Otherwise it will throw an {@code IllegalStateException} * @param type the type of the bean in question - use {@link #getContextualReference(String, boolean)} if the * type is unknown e.g. in dyn. use-cases * @param <T> target type * * @return the resolved Contextual Reference */ public static <T> T getContextualReference(String name, boolean optional, Class<T> type) { return getContextualReference(getBeanManager(), name, optional, type); }
/** * {@link #getContextualReference(Class, Annotation...)} which returns <code>null</code> if the 'optional' parameter * is set to <code>true</code>. * * @param type the type of the bean in question * @param optional if <code>true</code> it will return <code>null</code> if no bean could be found or created. * Otherwise it will throw an {@code IllegalStateException} * @param qualifiers additional qualifiers which distinguish the resolved bean * @param <T> target type * * @return the resolved Contextual Reference * * @see #getContextualReference(Class, Annotation...) */ public static <T> T getContextualReference(Class<T> type, boolean optional, Annotation... qualifiers) { BeanManager beanManager = getBeanManager(); return getContextualReference(beanManager, type, optional, qualifiers); }
/** * Get a Contextual Reference by its EL Name. This only works for beans with the @Named annotation. * * <p> * <b>Attention:</b> please see the notes on manually resolving @Dependent beans in * {@link #getContextualReference(Class, java.lang.annotation.Annotation...)}!</p> * * @param name the EL name of the bean * @param optional if <code>true</code> it will return <code>null</code> if no bean could be found or created. * Otherwise it will throw an {@code IllegalStateException} * @param type the type of the bean in question - use {@link #getContextualReference(String, boolean)} if the * type is unknown e.g. in dyn. use-cases * @param <T> target type * * @return the resolved Contextual Reference */ public static <T> T getContextualReference(String name, boolean optional, Class<T> type) { return getContextualReference(getBeanManager(), name, optional, type); }
/** * Performs dependency injection on an instance. Useful for instances which aren't managed by CDI. * <p/> * <b>Attention:</b><br/> * The resulting instance isn't managed by CDI; only fields annotated with @Inject get initialized. * * @param instance current instance * @param <T> current type * * @return instance with injected fields (if possible - or null if the given instance is null) */ @SuppressWarnings("unchecked") public static <T> T injectFields(T instance) { if (instance == null) { return null; } BeanManager beanManager = getBeanManager(); CreationalContext<T> creationalContext = beanManager.createCreationalContext(null); AnnotatedType<T> annotatedType = beanManager.createAnnotatedType((Class<T>) instance.getClass()); InjectionTarget<T> injectionTarget = beanManager.createInjectionTarget(annotatedType); injectionTarget.inject(instance, creationalContext); return instance; }
/** * Allows to perform dependency injection for instances which aren't managed by CDI. * <p/> * Attention:<br/> * The resulting instance isn't managed by CDI; only fields annotated with @Inject get initialized. * * @param instance current instance * @param <T> current type * @return instance with injected fields (if possible - or null if the given instance is null) */ @SuppressWarnings("unchecked") public static <T> T injectFields(T instance) { if (instance == null) { return null; } BeanManager beanManager = getBeanManager(); CreationalContext creationalContext = beanManager.createCreationalContext(null); AnnotatedType annotatedType = beanManager.createAnnotatedType(instance.getClass()); InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType); injectionTarget.inject(instance, creationalContext); return instance; }
/** * Performs dependency injection on an instance. Useful for instances which aren't managed by CDI. * <p/> * <b>Attention:</b><br/> * The resulting instance isn't managed by CDI; only fields annotated with @Inject get initialized. * * @param instance current instance * @param <T> current type * * @return instance with injected fields (if possible - or null if the given instance is null) */ @SuppressWarnings("unchecked") public static <T> T injectFields(T instance) { if (instance == null) { return null; } BeanManager beanManager = getBeanManager(); CreationalContext<T> creationalContext = beanManager.createCreationalContext(null); AnnotatedType<T> annotatedType = beanManager.createAnnotatedType((Class<T>) instance.getClass()); InjectionTarget<T> injectionTarget = beanManager.createInjectionTarget(annotatedType); injectionTarget.inject(instance, creationalContext); return instance; }