當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。