Package org.openbravo.base.weld
Class WeldUtils
- java.lang.Object
-
- org.openbravo.base.weld.WeldUtils
-
@ApplicationScoped public class WeldUtils extends Object
Provides weld utilities.- Author:
- mtaal
-
-
Field Summary
Fields Modifier and Type Field Description static javax.enterprise.util.AnnotationLiteral<javax.enterprise.inject.Any>
ANY_LITERAL
-
Constructor Summary
Constructors Constructor Description WeldUtils()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
getInstance(Class<T> type)
Return an instance which has the requested class.static <T> T
getInstanceFromStaticBeanManager(Class<T> type)
Method which uses the static instance of the bean manager cached in this class.static <T> List<T>
getInstances(Class<T> type)
Returns a set of instances for a specified type/classstatic <T> List<T>
getInstances(Class<T> type, javax.enterprise.util.AnnotationLiteral<?>... selectors)
Returns a set of instances for a specified type/class annotated with theselectors
AnnotationLiteral
.static <P extends Prioritizable>
List<P>getInstancesSortedByPriority(Class<P> type)
Returns a set of instances for a specified type/class that implement thePrioritizable
.static <P extends Prioritizable>
List<P>getInstancesSortedByPriority(Class<P> type, javax.enterprise.util.AnnotationLiteral<?>... selectors)
Returns a set of instances for a specified type/class that implement thePrioritizable
, that match with the provided selectors and sorted by priority.static javax.enterprise.inject.spi.BeanManager
getStaticInstanceBeanManager()
void
setBeanManager(javax.enterprise.inject.spi.BeanManager beanManager)
Sets bean manager.static void
setStaticInstanceBeanManager(javax.enterprise.inject.spi.BeanManager theBeanManager)
-
-
-
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 theselectors
AnnotationLiteral
. Example:WeldUtils.getInstances(Something.class, new ComponentProvider.Selector("Selector_Value"));
- Parameters:
type
- the expected classselectors
- the selectors that define the class annotations
-
getInstancesSortedByPriority
public static <P extends Prioritizable> List<P> getInstancesSortedByPriority(Class<P> type)
Returns a set of instances for a specified type/class that implement thePrioritizable
. Note that those with a lower priority value are sorted first.
-
getInstancesSortedByPriority
public static <P extends Prioritizable> List<P> getInstancesSortedByPriority(Class<P> type, javax.enterprise.util.AnnotationLiteral<?>... selectors)
Returns a set of instances for a specified type/class that implement thePrioritizable
, that match with the provided selectors and sorted by priority. Note that those with a lower priority value are sorted first.
-
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.
-
-