Search in sources :

Example 1 with ProcessBeanAttributes

use of javax.enterprise.inject.spi.ProcessBeanAttributes in project core by weld.

the class ContainerLifecyleObserverTest method testExtensionBuilder.

@SuppressWarnings({ "serial" })
@Test
public void testExtensionBuilder() {
    ActionSequence.reset();
    Extension myExtension = ContainerLifecycleObserver.extensionBuilder().add(beforeBeanDiscovery((e) -> addAction(BeforeBeanDiscovery.class.getSimpleName()))).add(afterTypeDiscovery().notify((e, b) -> {
        addAction(AfterTypeDiscovery.class.getSimpleName());
        e.addAnnotatedType(b.createAnnotatedType(Charlie.class), Charlie.class.getName());
    })).add(afterBeanDiscovery((e) -> {
        addAction(AfterBeanDiscovery.class.getSimpleName());
        e.addObserverMethod().beanClass(Foo.class).observedType(Foo.class).notifyWith((ctx) -> {
        });
        e.addBean().beanClass(Integer.class).addType(Integer.class).addQualifier(Juicy.Literal.INSTANCE).createWith((ctx) -> Integer.valueOf(10));
    })).add(afterDeploymentValidation((e) -> addAction(AfterDeploymentValidation.class.getSimpleName()))).add(beforeShutdown((e) -> addAction(BeforeShutdown.class.getSimpleName()))).build();
    Extension myExtension2 = ContainerLifecycleObserver.extensionBuilder().add(processAnnotatedType().withAnnotations(RequestScoped.class).notify((e) -> e.veto())).add(processBeanAttributes().notify((e) -> addAction(ProcessBeanAttributes.class.getSimpleName()))).add(processSyntheticAnnotatedType(new TypeLiteral<ProcessSyntheticAnnotatedType<?>>() {
    }.getType()).notify((e) -> addAction(ProcessSyntheticAnnotatedType.class.getSimpleName()))).add(processInjectionPoint().notify((e) -> addAction(ProcessInjectionPoint.class.getSimpleName()))).add(processProducer().notify((e) -> addAction(ProcessProducer.class.getSimpleName()))).add(processBean().notify((e) -> addAction(ProcessBean.class.getSimpleName()))).add(processManagedBean().notify((e) -> addAction(ProcessManagedBean.class.getSimpleName()))).add(processProducerField().notify((e) -> addAction(ProcessProducerField.class.getSimpleName()))).add(processProducerMethod().notify((e) -> {
        // Weld SE defines some producer methods, e.g. ParametersFactory
        addAction(ProcessProducerMethod.class.getSimpleName());
    })).add(processBeanAttributes().notify((e) -> addAction(ProcessBeanAttributes.class.getSimpleName()))).add(processObserverMethod().notify((e) -> addAction(ProcessObserverMethod.class.getSimpleName()))).add(processObserverMethod(new TypeLiteral<ProcessObserverMethod<String, ?>>() {
    }.getType()).notify((e) -> addAction(ProcessObserverMethod.class.getSimpleName() + String.class.getSimpleName()))).add(processSyntheticObserverMethod(new TypeLiteral<ProcessSyntheticObserverMethod<Foo, ?>>() {
    }.getType()).notify((e) -> addAction(ProcessSyntheticObserverMethod.class.getSimpleName() + Foo.class.getSimpleName()))).add(processSyntheticBean(new TypeLiteral<ProcessSyntheticBean<Integer>>() {
    }.getType()).notify((e) -> addAction(ProcessSyntheticBean.class.getSimpleName() + Integer.class.getSimpleName()))).build();
    try (WeldContainer container = new Weld().disableDiscovery().beanClasses(Foo.class, Bravo.class).addExtension(myExtension).addExtension(myExtension2).initialize()) {
        assertTrue(container.select(Foo.class).isUnsatisfied());
        assertFalse(container.select(Bravo.class).isUnsatisfied());
        Assert.assertEquals(Integer.valueOf(10), container.select(Integer.class, Juicy.Literal.INSTANCE).get());
    }
    ActionSequence.assertSequenceDataContainsAll(BeforeBeanDiscovery.class, AfterTypeDiscovery.class, AfterBeanDiscovery.class, AfterDeploymentValidation.class, BeforeShutdown.class);
    ActionSequence.assertSequenceDataContainsAll(ProcessBeanAttributes.class, ProcessSyntheticAnnotatedType.class, ProcessInjectionPoint.class, ProcessObserverMethod.class, ProcessBeanAttributes.class, ProcessProducer.class);
    ActionSequence.assertSequenceDataContainsAll(ProcessObserverMethod.class.getSimpleName() + String.class.getSimpleName(), ProcessSyntheticObserverMethod.class.getSimpleName() + Foo.class.getSimpleName(), ProcessSyntheticBean.class.getSimpleName() + Integer.class.getSimpleName());
    ActionSequence.assertSequenceDataContainsAll(ProcessBean.class, ProcessManagedBean.class, ProcessProducerMethod.class, ProcessProducerField.class);
}
Also used : ContainerLifecycleObserver.processObserverMethod(org.jboss.weld.environment.se.ContainerLifecycleObserver.processObserverMethod) ContainerLifecycleObserver.processSyntheticBean(org.jboss.weld.environment.se.ContainerLifecycleObserver.processSyntheticBean) AfterBeanDiscovery(javax.enterprise.inject.spi.AfterBeanDiscovery) ContainerLifecycleObserver.beforeBeanDiscovery(org.jboss.weld.environment.se.ContainerLifecycleObserver.beforeBeanDiscovery) ContainerLifecycleObserver.afterBeanDiscovery(org.jboss.weld.environment.se.ContainerLifecycleObserver.afterBeanDiscovery) ContainerLifecycleObserver.afterTypeDiscovery(org.jboss.weld.environment.se.ContainerLifecycleObserver.afterTypeDiscovery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProcessSyntheticBean(javax.enterprise.inject.spi.ProcessSyntheticBean) ProcessBean(javax.enterprise.inject.spi.ProcessBean) ContainerLifecycleObserver.processProducer(org.jboss.weld.environment.se.ContainerLifecycleObserver.processProducer) ContainerLifecycleObserver.processBean(org.jboss.weld.environment.se.ContainerLifecycleObserver.processBean) ContainerLifecycleObserver.beforeShutdown(org.jboss.weld.environment.se.ContainerLifecycleObserver.beforeShutdown) ProcessProducer(javax.enterprise.inject.spi.ProcessProducer) ProcessProducerField(javax.enterprise.inject.spi.ProcessProducerField) BeforeBeanDiscovery(javax.enterprise.inject.spi.BeforeBeanDiscovery) TypeLiteral(javax.enterprise.util.TypeLiteral) ActionSequence(org.jboss.weld.test.util.ActionSequence) ContainerLifecycleObserver.processInjectionPoint(org.jboss.weld.environment.se.ContainerLifecycleObserver.processInjectionPoint) ProcessObserverMethod(javax.enterprise.inject.spi.ProcessObserverMethod) AfterDeploymentValidation(javax.enterprise.inject.spi.AfterDeploymentValidation) ContainerLifecycleObserver.processSyntheticAnnotatedType(org.jboss.weld.environment.se.ContainerLifecycleObserver.processSyntheticAnnotatedType) ContainerLifecycleObserver.processProducerField(org.jboss.weld.environment.se.ContainerLifecycleObserver.processProducerField) Weld(org.jboss.weld.environment.se.Weld) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) ContainerLifecycleObserver.processSyntheticObserverMethod(org.jboss.weld.environment.se.ContainerLifecycleObserver.processSyntheticObserverMethod) Extension(javax.enterprise.inject.spi.Extension) ProcessManagedBean(javax.enterprise.inject.spi.ProcessManagedBean) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ContainerLifecycleObserver.processManagedBean(org.jboss.weld.environment.se.ContainerLifecycleObserver.processManagedBean) ProcessSyntheticAnnotatedType(javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType) WeldContainer(org.jboss.weld.environment.se.WeldContainer) ProcessProducerMethod(javax.enterprise.inject.spi.ProcessProducerMethod) ContainerLifecycleObserver.afterDeploymentValidation(org.jboss.weld.environment.se.ContainerLifecycleObserver.afterDeploymentValidation) ContainerLifecycleObserver.processProducerMethod(org.jboss.weld.environment.se.ContainerLifecycleObserver.processProducerMethod) AfterTypeDiscovery(javax.enterprise.inject.spi.AfterTypeDiscovery) ContainerLifecycleObserver(org.jboss.weld.environment.se.ContainerLifecycleObserver) Assert.assertFalse(org.junit.Assert.assertFalse) RequestScoped(javax.enterprise.context.RequestScoped) BeforeShutdown(javax.enterprise.inject.spi.BeforeShutdown) ActionSequence.addAction(org.jboss.weld.test.util.ActionSequence.addAction) ProcessBeanAttributes(javax.enterprise.inject.spi.ProcessBeanAttributes) ContainerLifecycleObserver.processAnnotatedType(org.jboss.weld.environment.se.ContainerLifecycleObserver.processAnnotatedType) Assert(org.junit.Assert) ContainerLifecycleObserver.processBeanAttributes(org.jboss.weld.environment.se.ContainerLifecycleObserver.processBeanAttributes) ProcessSyntheticObserverMethod(javax.enterprise.inject.spi.ProcessSyntheticObserverMethod) WeldContainer(org.jboss.weld.environment.se.WeldContainer) AfterDeploymentValidation(javax.enterprise.inject.spi.AfterDeploymentValidation) ProcessObserverMethod(javax.enterprise.inject.spi.ProcessObserverMethod) ProcessSyntheticAnnotatedType(javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType) Weld(org.jboss.weld.environment.se.Weld) Extension(javax.enterprise.inject.spi.Extension) ProcessManagedBean(javax.enterprise.inject.spi.ProcessManagedBean) ProcessSyntheticBean(javax.enterprise.inject.spi.ProcessSyntheticBean) TypeLiteral(javax.enterprise.util.TypeLiteral) ProcessProducer(javax.enterprise.inject.spi.ProcessProducer) AfterBeanDiscovery(javax.enterprise.inject.spi.AfterBeanDiscovery) Test(org.junit.Test)

Example 2 with ProcessBeanAttributes

use of javax.enterprise.inject.spi.ProcessBeanAttributes in project core by weld.

the class ProbeExtension method processBeanAttributes.

public <T> void processBeanAttributes(@Observes ProcessBeanAttributes<T> event, BeanManager beanManager) {
    probe.getBootstrapStats().increment(EventType.PBA);
    final BeanAttributes<T> beanAttributes = event.getBeanAttributes();
    final WeldManager weldManager = (WeldManager) beanManager;
    if (isMonitored(event.getAnnotated(), beanAttributes, weldManager)) {
        event.setBeanAttributes(new ForwardingBeanAttributes<T>() {

            @Override
            public Set<Class<? extends Annotation>> getStereotypes() {
                return ImmutableSet.<Class<? extends Annotation>>builder().addAll(attributes().getStereotypes()).add(MonitoredComponent.class).build();
            }

            @Override
            protected BeanAttributes<T> attributes() {
                return beanAttributes;
            }

            @Override
            public String toString() {
                return beanAttributes.toString();
            }
        });
        ProbeLogger.LOG.monitoringStereotypeAdded(event.getAnnotated());
    }
    if (eventMonitorContainerLifecycleEvents) {
        addContainerLifecycleEvent(event, "Types: [" + Formats.formatTypes(event.getBeanAttributes().getTypes()) + "], qualifiers: [" + Formats.formatAnnotations(event.getBeanAttributes().getQualifiers()) + "]", beanManager);
    }
}
Also used : ImmutableSet(org.jboss.weld.util.collections.ImmutableSet) Set(java.util.Set) ForwardingBeanAttributes(org.jboss.weld.util.bean.ForwardingBeanAttributes) ProcessBeanAttributes(javax.enterprise.inject.spi.ProcessBeanAttributes) BeanAttributes(javax.enterprise.inject.spi.BeanAttributes) Annotation(java.lang.annotation.Annotation) WeldManager(org.jboss.weld.manager.api.WeldManager)

Example 3 with ProcessBeanAttributes

use of javax.enterprise.inject.spi.ProcessBeanAttributes in project wildfly-swarm by wildfly-swarm.

the class MPJWTExtension method addTypeToClaimProducer.

/**
 * Replace the general producer method BeanAttributes with one bound to the collected injection site
 * types to properly reflect all of the type locations the producer method applies to.
 *
 * @param pba the ProcessBeanAttributes
 * @see ClaimProviderBeanAttributes
 */
public void addTypeToClaimProducer(@Observes ProcessBeanAttributes pba) {
    if (pba.getAnnotated().isAnnotationPresent(Claim.class)) {
        Claim claim = pba.getAnnotated().getAnnotation(Claim.class);
        if (claim.value().length() == 0 && claim.standard() == Claims.UNKNOWN) {
            log.debugf("addTypeToClaimProducer: %s\n", pba.getAnnotated());
            BeanAttributes delegate = pba.getBeanAttributes();
            String name = delegate.getName();
            if (delegate.getTypes().contains(Optional.class)) {
                if (providerOptionalTypes.size() == 0) {
                    providerOptionalTypes.add(Optional.class);
                }
                pba.setBeanAttributes(new ClaimProviderBeanAttributes(delegate, providerOptionalTypes, providerQualifiers));
            // This is
            } else if (name != null && name.startsWith("RawClaimTypeProducer#")) {
                if (rawTypes.size() == 0) {
                    rawTypes.add(Object.class);
                }
                pba.setBeanAttributes(new ClaimProviderBeanAttributes(delegate, rawTypes, rawTypeQualifiers));
                log.debugf("Setup RawClaimTypeProducer BeanAttributes");
            }
        }
    }
}
Also used : BeanAttributes(javax.enterprise.inject.spi.BeanAttributes) ProcessBeanAttributes(javax.enterprise.inject.spi.ProcessBeanAttributes) Claim(org.eclipse.microprofile.jwt.Claim)

Aggregations

ProcessBeanAttributes (javax.enterprise.inject.spi.ProcessBeanAttributes)3 BeanAttributes (javax.enterprise.inject.spi.BeanAttributes)2 Annotation (java.lang.annotation.Annotation)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 RequestScoped (javax.enterprise.context.RequestScoped)1 AfterBeanDiscovery (javax.enterprise.inject.spi.AfterBeanDiscovery)1 AfterDeploymentValidation (javax.enterprise.inject.spi.AfterDeploymentValidation)1 AfterTypeDiscovery (javax.enterprise.inject.spi.AfterTypeDiscovery)1 BeforeBeanDiscovery (javax.enterprise.inject.spi.BeforeBeanDiscovery)1 BeforeShutdown (javax.enterprise.inject.spi.BeforeShutdown)1 Extension (javax.enterprise.inject.spi.Extension)1 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)1 ProcessBean (javax.enterprise.inject.spi.ProcessBean)1 ProcessInjectionPoint (javax.enterprise.inject.spi.ProcessInjectionPoint)1 ProcessManagedBean (javax.enterprise.inject.spi.ProcessManagedBean)1 ProcessObserverMethod (javax.enterprise.inject.spi.ProcessObserverMethod)1 ProcessProducer (javax.enterprise.inject.spi.ProcessProducer)1 ProcessProducerField (javax.enterprise.inject.spi.ProcessProducerField)1 ProcessProducerMethod (javax.enterprise.inject.spi.ProcessProducerMethod)1