当前位置: 首页>>代码示例>>Java>>正文


Java BeanManager.getReference方法代码示例

本文整理汇总了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;
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:22,代码来源:CdiServiceDiscovery.java

示例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;
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:17,代码来源:CdiServiceDiscovery.java

示例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;
}
 
开发者ID:marcelothebuilder,项目名称:webpedidos,代码行数:17,代码来源:CDIServiceLocator.java

示例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;
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:17,代码来源:CdiServiceDiscovery.java

示例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;

}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:13,代码来源:Main.java

示例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);
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:20,代码来源:WeldUtils.java

示例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);	        
}
 
开发者ID:optionfactory,项目名称:hibernate-json,代码行数:13,代码来源:CdiDriverLocator.java

示例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;
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:14,代码来源:CdiServiceDiscovery.java

示例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);
  }
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:11,代码来源:CdiCamelBehavior.java

示例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;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:12,代码来源:ProgrammaticBeanLookup.java

示例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));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:CamelCdiRunner.java

示例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();
   	}
   }
 
开发者ID:Inspiredsoft,项目名称:parco,代码行数:12,代码来源:BeanStartupHelper.java

示例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));
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:5,代码来源:MetricCdiInjectionExtension.java

示例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));
}
 
开发者ID:eclipse,项目名称:yasson,代码行数:6,代码来源:CdiInjectionTest.java

示例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));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:5,代码来源:BeanManagerHelper.java


注:本文中的javax.enterprise.inject.spi.BeanManager.getReference方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。