本文整理汇总了Java中javax.enterprise.inject.spi.BeanManager.getReference方法的典型用法代码示例。如果您正苦于以下问题:Java BeanManager.getReference方法的具体用法?Java BeanManager.getReference怎么用?Java BeanManager.getReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.enterprise.inject.spi.BeanManager
的用法示例。
在下文中一共展示了BeanManager.getReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstancesByType
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> List<T> getInstancesByType(Class<T> clazz) {
BeanManager beanManager = getBeanManager();
Type type = clazz;
if (clazz == JsonApiExceptionMapper.class) {
TypeLiteral<JsonApiExceptionMapper<?>> typeLiteral = new TypeLiteral<JsonApiExceptionMapper<?>>() {
};
type = typeLiteral.getType();
}
Set<Bean<?>> beans = beanManager.getBeans(type);
List<T> list = new ArrayList<>();
for (Bean<?> bean : beans) {
CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
T object = (T) beanManager.getReference(bean, type, creationalContext);
list.add(object);
}
return list;
}
示例2: getInstancesByAnnotation
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@Override
public <A extends Annotation> List<Object> getInstancesByAnnotation(Class<A> annotationClass) {
BeanManager beanManager = getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans(Object.class);
List<Object> list = new ArrayList<>();
for (Bean<?> bean : beans) {
Class<?> beanClass = bean.getBeanClass();
Optional<A> annotation = ClassUtils.getAnnotation(beanClass, annotationClass);
if (annotation.isPresent()) {
CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
Object object = beanManager.getReference(bean, beanClass, creationalContext);
list.add(object);
}
}
return list;
}
示例3: getBean
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T getBean(Class<T> clazz) {
BeanManager bm = getBeanManager();
Set<Bean<?>> beans = bm.getBeans(clazz);
if (beans == null || beans.isEmpty()) {
return null;
}
Bean<T> bean = (Bean<T>) beans.iterator().next();
CreationalContext<T> ctx = bm.createCreationalContext(bean);
T o = (T) bm.getReference(bean, clazz, ctx);
return o;
}
示例4: getInstancesByAnnotation
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@Override
public <A extends Annotation> List<Object> getInstancesByAnnotation(Class<A> annotationClass) {
BeanManager beanManager = CDI.current().getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans(Object.class);
List<Object> list = new ArrayList<>();
for (Bean<?> bean : beans) {
Class<?> beanClass = bean.getBeanClass();
Optional<A> annotation = ClassUtils.getAnnotation(beanClass, annotationClass);
if (annotation.isPresent()) {
CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
Object object = beanManager.getReference(bean, beanClass, creationalContext);
list.add(object);
}
}
return list;
}
示例5: getDrinkWaterApplication
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
public ServiceRepository getDrinkWaterApplication() {
BeanManager mgr = cdiContainer.getBeanManager();
ServiceRepository dwapp =
(ServiceRepository) mgr.getReference(
mgr.resolve(mgr.getBeans(DrinkWaterApplication.class)),
DrinkWaterApplication.class,
mgr.createCreationalContext(null)
);
return dwapp;
}
示例6: getInstanceFromStaticBeanManager
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
/**
* 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 WeldUtils#getInstance(Class)
*/
@SuppressWarnings("unchecked")
public static <T> T getInstanceFromStaticBeanManager(Class<T> type) {
final BeanManager theBeanManager = getStaticInstanceBeanManager();
final Set<Bean<?>> beans = theBeanManager.getBeans(type, ANY_LITERAL);
for (Bean<?> bean : beans) {
if (bean.getBeanClass() == type) {
return (T) theBeanManager.getReference(bean, type,
theBeanManager.createCreationalContext(bean));
}
}
throw new IllegalArgumentException("No bean found for type " + type);
}
示例7: locate
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@Override
public JsonDriver locate(Annotation[] fieldAnnotations, Optional<String> name) {
final BeanManager bm = CDI.current().getBeanManager();
final Annotation[] qualifiers = Arrays.stream(fieldAnnotations).filter(a -> searchAnnotation(a, Qualifier.class).isPresent()).toArray(n -> new Annotation[n]);
JsonDriverNotFound.failIf(qualifiers.length > 0 && name.isPresent(), "found both @Qualifiers and @WithDriver.value()");
final Set<Bean<?>> beans = name.map(n -> bm.getBeans(n)).orElseGet(() -> bm.getBeans(JsonDriver.class, qualifiers));
JsonDriverNotFound.failIf(beans.isEmpty(), "no JsonDriver found in BeanManager");
JsonDriverNotFound.failIf(beans.size() > 1, "more than one JsonDriver found in BeanManager, use @JsonType.WithDriver to disambiguate");
final Bean<?> bean = beans.iterator().next();
final CreationalContext<?> ctx = bm.createCreationalContext(bean);
return (JsonDriver) bm.getReference(bean, JsonDriver.class, ctx);
}
示例8: getInstancesByType
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> List<T> getInstancesByType(Class<T> clazz) {
BeanManager beanManager = CDI.current().getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans(clazz);
List<T> list = new ArrayList<>();
for (Bean<?> bean : beans) {
CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
T object = (T) beanManager.getReference(bean, clazz, creationalContext);
list.add(object);
}
return list;
}
示例9: get
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
protected CamelContext get(String name) {
BeanManager beanManager = BeanManagerLookup.getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans(name);
if(beans.isEmpty())
return null;
@SuppressWarnings("unchecked")
Bean<CamelContext> bean = (Bean<CamelContext>) beans.iterator().next();
CreationalContext<CamelContext> ctx = beanManager.createCreationalContext(bean);
return (CamelContext) beanManager.getReference(bean, CamelContext.class, ctx);
}
示例10: lookup
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T lookup(Class<T> clazz, BeanManager bm) {
Iterator<Bean<?>> iter = bm.getBeans(clazz).iterator();
if (!iter.hasNext()) {
throw new IllegalStateException("CDI BeanManager cannot find an instance of requested type " + clazz.getName());
}
Bean<T> bean = (Bean<T>) iter.next();
CreationalContext<T> ctx = bm.createCreationalContext(bean);
T dao = (T) bm.getReference(bean, clazz, ctx);
return dao;
}
示例11: createTest
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@Override
protected Object createTest() {
BeanManager manager = context.getBeanManager();
Set<Bean<?>> beans = manager.getBeans(getTestClass().getJavaClass(), AnyLiteral.INSTANCE);
Bean<?> bean = beans.iterator().next();
// TODO: manage lifecycle of @Dependent beans
return manager.getReference(bean, bean.getBeanClass(), manager.createCreationalContext(bean));
}
示例12: onStartup
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public void onStartup(@Observes @Initialized WebApplication webApplication, BeanManager beanManager)
{
for( Bean bean : beanManager.getBeans(Startup.class) )
{
CreationalContext context = beanManager.createCreationalContext(bean);
Startup st = (Startup) beanManager.getReference(bean, Startup.class, context);
st.init();
}
}
示例13: getReference
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> T getReference(BeanManager manager, Type type, Bean<?> bean) {
return (T) manager.getReference(bean, type, manager.createCreationalContext(bean));
}
示例14: getCalledMethods
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
private CalledMethods getCalledMethods() {
final BeanManager beanManager = CDI.current().getBeanManager();
final Bean<?> resolve = beanManager.resolve(beanManager.getBeans(CalledMethods.class));
return (CalledMethods) beanManager.getReference(resolve, CalledMethods.class, beanManager.createCreationalContext(resolve));
}
示例15: getCamelContextById
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
static CamelContext getCamelContextById(BeanManager manager, String camelContextId) {
Bean<?> bean = manager.resolve(manager.getBeans(camelContextId));
return (CamelContext) manager.getReference(bean, CamelContext.class, manager.createCreationalContext(bean));
}