use of javax.enterprise.context.spi.CreationalContext in project wildfly-swarm by wildfly-swarm.
the class OutboundSocketBindingExtension method afterBeanDiscovery.
@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(Pre.Literal.INSTANCE).addQualifier(AnyLiteral.INSTANCE).createSupplier(customizerSupplier).addType(Customizer.class).addType(Object.class).build();
abd.addBean(customizerBean);
}
}
}
use of javax.enterprise.context.spi.CreationalContext in project wildfly-swarm by wildfly-swarm.
the class SocketBindingExtension method afterBeanDiscovery.
@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(Pre.Literal.INSTANCE).addQualifier(AnyLiteral.INSTANCE).createSupplier(supplier).addType(Customizer.class).addType(Object.class).build();
abd.addBean(customizerBean);
}
}
}
use of javax.enterprise.context.spi.CreationalContext in project spring-data-commons by spring-projects.
the class CdiRepositoryBeanUnitTests method passesCorrectBeanNameToTheImplementationDetector.
// DATACMNS-764
@Test
public void passesCorrectBeanNameToTheImplementationDetector() {
CustomRepositoryImplementationDetector detector = mock(CustomRepositoryImplementationDetector.class);
CdiRepositoryBean<SampleRepository> bean = new //
CdiRepositoryBean<SampleRepository>(//
SINGLE_ANNOTATION, //
SampleRepository.class, //
beanManager, //
Optional.of(detector)) {
@Override
protected //
SampleRepository create(//
CreationalContext<SampleRepository> creationalContext, //
Class<SampleRepository> repositoryType, //
Optional<Object> customImplementation) {
return null;
}
};
bean.create(mock(CreationalContext.class), SampleRepository.class);
//
verify(detector).detectCustomImplementation(//
eq("CdiRepositoryBeanUnitTests.SampleRepositoryImpl"), //
eq("CdiRepositoryBeanUnitTests.SampleRepositoryImpl"), //
anySet(), //
anySet(), //
Mockito.any(Function.class));
}
use of javax.enterprise.context.spi.CreationalContext in project indy by Commonjava.
the class CdiInjectorFactoryImpl method lookupBeanManager.
@Override
protected BeanManager lookupBeanManager() {
final BeanManager bmgr = CDI.current().getBeanManager();
Logger logger = LoggerFactory.getLogger(getClass());
if (logger.isDebugEnabled()) {
Set<Bean<?>> mappers = bmgr.getBeans(ObjectMapper.class);
mappers.forEach(bean -> {
CreationalContext ctx = bmgr.createCreationalContext(null);
logger.debug("Found ObjectMapper: {}", bean.create(ctx));
ctx.release();
});
logger.debug("\n\n\n\nRESTEasy CDI Injector Factory Using BeanManager: {} (@{})\n\n\n\n", bmgr, bmgr.hashCode());
}
return bmgr;
}
use of javax.enterprise.context.spi.CreationalContext in project wildfly by wildfly.
the class WeldClassIntrospector method createFactory.
@Override
public ManagedReferenceFactory createFactory(Class<?> clazz) {
final BeanManager beanManager = this.beanManagerSupplier.get();
final InjectionTarget injectionTarget = getInjectionTarget(clazz);
return new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
final CreationalContext context = beanManager.createCreationalContext(null);
Object instance;
BasicInjectionTarget target = injectionTarget instanceof BasicInjectionTarget ? (BasicInjectionTarget) injectionTarget : null;
if (target != null && target.getBean() != null) {
instance = beanManager.getReference(target.getBean(), target.getAnnotatedType().getBaseType(), context);
} else {
instance = injectionTarget.produce(context);
}
injectionTarget.inject(instance, context);
injectionTarget.postConstruct(instance);
return new WeldManagedReference(injectionTarget, context, instance);
}
};
}
Aggregations