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


Java BeanManager.getBeans方法代码示例

本文整理汇总了Java中javax.enterprise.inject.spi.BeanManager.getBeans方法的典型用法代码示例。如果您正苦于以下问题:Java BeanManager.getBeans方法的具体用法?Java BeanManager.getBeans怎么用?Java BeanManager.getBeans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.enterprise.inject.spi.BeanManager的用法示例。


在下文中一共展示了BeanManager.getBeans方法的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: 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

示例6: getModuleLicenseRestrictions

import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
private List<ModuleLicenseRestrictions> getModuleLicenseRestrictions() {
  List<ModuleLicenseRestrictions> result = new ArrayList<ModuleLicenseRestrictions>();
  BeanManager bm = WeldUtils.getStaticInstanceBeanManager();
  for (Bean<?> restrictionBean : bm.getBeans(ModuleLicenseRestrictions.class)) {
    result.add((ModuleLicenseRestrictions) bm.getReference(restrictionBean,
        ModuleLicenseRestrictions.class, bm.createCreationalContext(restrictionBean)));
  }
  return result;
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:10,代码来源:ActivationKey.java

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

示例8: afterBeanDiscovery

import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
    try (AutoCloseable handle = Performance.time("SocketBindingExtension.afterBeanDiscovery")) {

        for (SocketBindingRequest each : this.bindings) {

            Supplier<Customizer> supplier = () -> (Customizer) () -> {
                Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);

                groups.stream()
                        .map((Bean<?> e) -> {
                            CreationalContext<?> ctx = beanManager.createCreationalContext(e);
                            return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx);
                        })
                        .filter(group -> group.name().equals(each.socketBindingGroup()))
                        .findFirst()
                        .ifPresent((group) -> group.socketBinding(each.socketBinding()));
            };

            CommonBean<Customizer> customizerBean = CommonBeanBuilder.newBuilder(Customizer.class)
                    .beanClass(SocketBindingExtension.class)
                    .scope(Singleton.class)
                    .addQualifier(new AnnotationLiteral<Pre>() {
                    })
                    .addQualifier(AnyLiteral.INSTANCE)
                    .createSupplier(supplier)
                    .addType(Customizer.class)
                    .addType(Object.class).build();
            abd.addBean(customizerBean);
        }
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:33,代码来源:SocketBindingExtension.java

示例9: afterBeanDiscovery

import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
    try (AutoCloseable handle = Performance.time("OutboundSocketBindingExtension.afterBeanDiscovery")) {
        for (OutboundSocketBindingRequest each : this.bindings) {

            Supplier<Customizer> customizerSupplier = () -> (Customizer) () -> {
                Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);

                groups.stream()
                        .map((Bean<?> e) -> {
                            CreationalContext<?> ctx = beanManager.createCreationalContext(e);
                            return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx);
                        })
                        .filter(group -> group.name().equals(each.socketBindingGroup()))
                        .findFirst()
                        .ifPresent((group) -> group.outboundSocketBinding(each.outboundSocketBinding()));
            };
            CommonBean<Customizer> customizerBean = CommonBeanBuilder.newBuilder(Customizer.class)
                    .beanClass(OutboundSocketBindingExtension.class)
                    .scope(Singleton.class)
                    .addQualifier(new AnnotationLiteral<Pre>() {
                    })
                    .addQualifier(AnyLiteral.INSTANCE)
                    .createSupplier(customizerSupplier)
                    .addType(Customizer.class)
                    .addType(Object.class).build();
            abd.addBean(customizerBean);
        }
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:31,代码来源:OutboundSocketBindingExtension.java

示例10: afterBeanDiscovery

import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {

    List<SimpleKey> configuredGroups = this.configView.simpleSubkeys(ROOT);
    for (SimpleKey groupName : configuredGroups) {
        Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);
        AtomicBoolean producerRequired = new AtomicBoolean(false);
        if (groups
                .stream()
                .noneMatch(e -> e.getQualifiers()
                        .stream()
                        .anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(groupName)))) {

            SocketBindingGroup group = new SocketBindingGroup(groupName.name(), null, "0");

            applyConfiguration(group);

            if (producerRequired.get()) {
                CommonBean<SocketBindingGroup> interfaceBean = CommonBeanBuilder.newBuilder(SocketBindingGroup.class)
                        .beanClass(SocketBindingGroupExtension.class)
                        .scope(ApplicationScoped.class)
                        .addQualifier(AnyLiteral.INSTANCE)
                        .addQualifier(new NamedLiteral(group.name()))
                        .createSupplier(() -> group)
                        .addType(SocketBindingGroup.class)
                        .addType(Object.class)
                        .build();

                abd.addBean(interfaceBean);
            }
        }
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:34,代码来源:SocketBindingGroupExtension.java

示例11: afterBeanDiscovery

import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {

    List<SimpleKey> configuredInterfaces = this.configView.simpleSubkeys(ROOT);

    for (SimpleKey interfaceName : configuredInterfaces) {

        Set<Bean<?>> ifaces = beanManager.getBeans(Interface.class, AnyLiteral.INSTANCE);

        AtomicBoolean producerRequired = new AtomicBoolean(false);

        if (ifaces
                .stream()
                .noneMatch(e -> e.getQualifiers()
                        .stream()
                        .anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(interfaceName + "-interface")))) {

            Interface iface = new Interface(interfaceName.name(), "0.0.0.0");
            applyConfiguration(iface);
            if (producerRequired.get()) {
                CommonBean<Interface> interfaceBean = CommonBeanBuilder.newBuilder(Interface.class)
                        .beanClass(InterfaceExtension.class)
                        .scope(ApplicationScoped.class)
                        .addQualifier(AnyLiteral.INSTANCE)
                        .addQualifier(new NamedLiteral(interfaceName.name() + "-interface"))
                        .createSupplier(() -> iface)
                        .addType(Interface.class)
                        .addType(Object.class)
                        .build();

                abd.addBean(interfaceBean);
            }
        }
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:36,代码来源:InterfaceExtension.java

示例12: 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

示例13: lookup

import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Object lookup(String name, BeanManager bm) {
    Set<Bean<?>> beans = bm.getBeans(name);
    if (beans.isEmpty()) {
        throw new IllegalStateException("CDI BeanManager cannot find an instance of requested type '" + name + "'");
    }
    Bean bean = bm.resolve(beans);
    CreationalContext ctx = bm.createCreationalContext(bean);
    // select one beantype randomly. A bean has a non-empty set of
    // beantypes.
    Type type = (Type) bean.getTypes().iterator().next();
    return bm.getReference(bean, type, ctx);
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:14,代码来源:ProgrammaticBeanLookup.java

示例14: warnIfNoCamelFound

import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
private void warnIfNoCamelFound() {
    BeanManager manager = cdiContainer.getBeanManager();
    Set<Bean<?>> contexts = manager.getBeans(CamelContext.class, ANY);
    // Warn if there is no CDI Camel contexts
    if (contexts.isEmpty()) {
        LOG.warn("Camel CDI main has started with no Camel context!");
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:Main.java

示例15: 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


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