Class WeldUtils


  • @ApplicationScoped
    public class WeldUtils
    extends Object
    Provides weld utilities.
    Author:
    mtaal
    • Field Detail

      • ANY_LITERAL

        public static final javax.enterprise.util.AnnotationLiteral<javax.enterprise.inject.Any> ANY_LITERAL
    • Constructor Detail

      • WeldUtils

        public WeldUtils()
    • Method Detail

      • getStaticInstanceBeanManager

        public static javax.enterprise.inject.spi.BeanManager getStaticInstanceBeanManager()
      • setStaticInstanceBeanManager

        public static void setStaticInstanceBeanManager​(javax.enterprise.inject.spi.BeanManager theBeanManager)
      • getInstanceFromStaticBeanManager

        public static <T> T getInstanceFromStaticBeanManager​(Class<T> type)
        Method which uses the static instance of the bean manager cached in this class. This method should only be used by objects which are not created by Weld. Objects created by Weld should preferably use the @Inject annotation to get an instance of the WeldUtils injected.
        See Also:
        getInstance(Class)
      • getInstance

        public <T> T getInstance​(Class<T> type)
        Return an instance which has the requested class. Ignores inheritance, so if a class A extends a class B, if B is requested then an instance of B is returned and not an instance of A.
        Type Parameters:
        T - the expected class
        Parameters:
        type - the type to search, this type and all its subtypes are searched
        Returns:
        an instance of the requested type
      • getInstances

        public static <T> List<T> getInstances​(Class<T> type)
        Returns a set of instances for a specified type/class
      • getInstances

        public static <T> List<T> getInstances​(Class<T> type,
                                               javax.enterprise.util.AnnotationLiteral<?>... selectors)
        Returns a set of instances for a specified type/class annotated with the selectors AnnotationLiteral. Example:

        WeldUtils.getInstances(Something.class, new ComponentProvider.Selector("Selector_Value"));

        Parameters:
        type - the expected class
        selectors - the selectors that define the class annotations
      • getInstancesSortedByPriority

        public static <P extends PrioritizableList<P> getInstancesSortedByPriority​(Class<P> type)
        Returns a set of instances for a specified type/class that implement the Prioritizable. Note that those with a lower priority value are sorted first.
      • getInstancesSortedByPriority

        public static <P extends PrioritizableList<P> getInstancesSortedByPriority​(Class<P> type,
                                                                                     javax.enterprise.util.AnnotationLiteral<?>... selectors)
        Returns a set of instances for a specified type/class that implement the Prioritizable, that match with the provided selectors and sorted by priority. Note that those with a lower priority value are sorted first.
        See Also:
        getInstances(Class, AnnotationLiteral...)
      • setBeanManager

        public void setBeanManager​(javax.enterprise.inject.spi.BeanManager beanManager)
        Sets bean manager. The purpose of this setter is to be used just in jUnit test cases. When working within a container, bean manager should be handled by container.