本文整理汇总了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;
}
示例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: 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);
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}
}
示例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);
}
示例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);
}
示例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!");
}
}
示例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));
}