Search in sources :

Example 16 with CreationalContext

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);
        }
    }
}
Also used : OutboundSocketBindingRequest(org.wildfly.swarm.internal.OutboundSocketBindingRequest) CreationalContext(javax.enterprise.context.spi.CreationalContext) Customizer(org.wildfly.swarm.spi.api.Customizer) CommonBean(org.wildfly.swarm.spi.api.cdi.CommonBean) Bean(javax.enterprise.inject.spi.Bean)

Example 17 with CreationalContext

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);
        }
    }
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) SocketBindingRequest(org.wildfly.swarm.internal.SocketBindingRequest) Customizer(org.wildfly.swarm.spi.api.Customizer) CommonBean(org.wildfly.swarm.spi.api.cdi.CommonBean) Bean(javax.enterprise.inject.spi.Bean)

Example 18 with CreationalContext

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));
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) Function(java.util.function.Function) Optional(java.util.Optional) CustomRepositoryImplementationDetector(org.springframework.data.repository.config.CustomRepositoryImplementationDetector) Test(org.junit.Test)

Example 19 with CreationalContext

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;
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) Logger(org.slf4j.Logger) BeanManager(javax.enterprise.inject.spi.BeanManager) Bean(javax.enterprise.inject.spi.Bean)

Example 20 with CreationalContext

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);
        }
    };
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget) BasicInjectionTarget(org.jboss.weld.injection.producer.BasicInjectionTarget) BeanManager(javax.enterprise.inject.spi.BeanManager) BasicInjectionTarget(org.jboss.weld.injection.producer.BasicInjectionTarget)

Aggregations

CreationalContext (javax.enterprise.context.spi.CreationalContext)132 Bean (javax.enterprise.inject.spi.Bean)113 Test (org.junit.Test)83 URL (java.net.URL)67 Path (org.uberfire.backend.vfs.Path)67 KieModuleService (org.kie.workbench.common.services.shared.project.KieModuleService)66 Package (org.guvnor.common.services.project.model.Package)43 Module (org.guvnor.common.services.project.model.Module)13 BeanManager (javax.enterprise.inject.spi.BeanManager)11 BuildResults (org.guvnor.common.services.project.builder.model.BuildResults)6 IncrementalBuildResults (org.guvnor.common.services.project.builder.model.IncrementalBuildResults)6 Before (org.junit.Before)6 Weld (org.jboss.weld.environment.se.Weld)5 Context (javax.enterprise.context.spi.Context)4 InjectionTarget (javax.enterprise.inject.spi.InjectionTarget)4 WebBeansContext (org.apache.webbeans.config.WebBeansContext)4 Fabric8Extension (io.fabric8.cdi.Fabric8Extension)3 Annotation (java.lang.annotation.Annotation)3 Method (java.lang.reflect.Method)3 Type (java.lang.reflect.Type)3