Search in sources :

Example 1 with ProcessInjectionPoint

use of jakarta.enterprise.inject.spi.ProcessInjectionPoint in project core by weld.

the class ModifyingExtension method overrideFieldInjectionPoint.

public void overrideFieldInjectionPoint(@Observes ProcessInjectionPoint<InjectingBean, Dog> event) {
    final InjectionPoint delegate = event.getInjectionPoint();
    event.setInjectionPoint(new ForwardingInjectionPoint() {

        @Override
        protected InjectionPoint delegate() {
            return delegate;
        }

        @Override
        public boolean isTransient() {
            return true;
        }

        @Override
        public Type getType() {
            return Hound.class;
        }

        @Override
        public Set<Annotation> getQualifiers() {
            return Collections.<Annotation>singleton(Fast.Literal.INSTANCE);
        }
    });
}
Also used : Type(java.lang.reflect.Type) Set(java.util.Set) ForwardingInjectionPoint(org.jboss.weld.injection.ForwardingInjectionPoint) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) ForwardingInjectionPoint(org.jboss.weld.injection.ForwardingInjectionPoint)

Example 2 with ProcessInjectionPoint

use of jakarta.enterprise.inject.spi.ProcessInjectionPoint 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) ContainerLifecycleObserver.beforeBeanDiscovery(org.jboss.weld.environment.se.ContainerLifecycleObserver.beforeBeanDiscovery) ProcessObserverMethod(jakarta.enterprise.inject.spi.ProcessObserverMethod) ContainerLifecycleObserver.afterBeanDiscovery(org.jboss.weld.environment.se.ContainerLifecycleObserver.afterBeanDiscovery) ProcessSyntheticObserverMethod(jakarta.enterprise.inject.spi.ProcessSyntheticObserverMethod) ContainerLifecycleObserver.afterTypeDiscovery(org.jboss.weld.environment.se.ContainerLifecycleObserver.afterTypeDiscovery) AfterTypeDiscovery(jakarta.enterprise.inject.spi.AfterTypeDiscovery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AfterDeploymentValidation(jakarta.enterprise.inject.spi.AfterDeploymentValidation) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) ContainerLifecycleObserver.processProducer(org.jboss.weld.environment.se.ContainerLifecycleObserver.processProducer) ProcessManagedBean(jakarta.enterprise.inject.spi.ProcessManagedBean) ProcessSyntheticAnnotatedType(jakarta.enterprise.inject.spi.ProcessSyntheticAnnotatedType) ContainerLifecycleObserver.processBean(org.jboss.weld.environment.se.ContainerLifecycleObserver.processBean) ContainerLifecycleObserver.beforeShutdown(org.jboss.weld.environment.se.ContainerLifecycleObserver.beforeShutdown) ProcessBeanAttributes(jakarta.enterprise.inject.spi.ProcessBeanAttributes) TypeLiteral(jakarta.enterprise.util.TypeLiteral) ProcessBean(jakarta.enterprise.inject.spi.ProcessBean) ProcessProducerMethod(jakarta.enterprise.inject.spi.ProcessProducerMethod) Extension(jakarta.enterprise.inject.spi.Extension) ProcessAnnotatedType(jakarta.enterprise.inject.spi.ProcessAnnotatedType) BeforeBeanDiscovery(jakarta.enterprise.inject.spi.BeforeBeanDiscovery) ActionSequence(org.jboss.weld.test.util.ActionSequence) ContainerLifecycleObserver.processInjectionPoint(org.jboss.weld.environment.se.ContainerLifecycleObserver.processInjectionPoint) 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) ContainerLifecycleObserver.processSyntheticObserverMethod(org.jboss.weld.environment.se.ContainerLifecycleObserver.processSyntheticObserverMethod) BeforeShutdown(jakarta.enterprise.inject.spi.BeforeShutdown) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ContainerLifecycleObserver.processManagedBean(org.jboss.weld.environment.se.ContainerLifecycleObserver.processManagedBean) WeldContainer(org.jboss.weld.environment.se.WeldContainer) ProcessSyntheticBean(jakarta.enterprise.inject.spi.ProcessSyntheticBean) ContainerLifecycleObserver.afterDeploymentValidation(org.jboss.weld.environment.se.ContainerLifecycleObserver.afterDeploymentValidation) ContainerLifecycleObserver.processProducerMethod(org.jboss.weld.environment.se.ContainerLifecycleObserver.processProducerMethod) AfterBeanDiscovery(jakarta.enterprise.inject.spi.AfterBeanDiscovery) ContainerLifecycleObserver(org.jboss.weld.environment.se.ContainerLifecycleObserver) Assert.assertFalse(org.junit.Assert.assertFalse) ActionSequence.addAction(org.jboss.weld.test.util.ActionSequence.addAction) ProcessProducerField(jakarta.enterprise.inject.spi.ProcessProducerField) ContainerLifecycleObserver.processAnnotatedType(org.jboss.weld.environment.se.ContainerLifecycleObserver.processAnnotatedType) ProcessProducer(jakarta.enterprise.inject.spi.ProcessProducer) Assert(org.junit.Assert) ContainerLifecycleObserver.processBeanAttributes(org.jboss.weld.environment.se.ContainerLifecycleObserver.processBeanAttributes) RequestScoped(jakarta.enterprise.context.RequestScoped) WeldContainer(org.jboss.weld.environment.se.WeldContainer) AfterDeploymentValidation(jakarta.enterprise.inject.spi.AfterDeploymentValidation) ProcessObserverMethod(jakarta.enterprise.inject.spi.ProcessObserverMethod) ProcessSyntheticAnnotatedType(jakarta.enterprise.inject.spi.ProcessSyntheticAnnotatedType) Weld(org.jboss.weld.environment.se.Weld) Extension(jakarta.enterprise.inject.spi.Extension) ProcessManagedBean(jakarta.enterprise.inject.spi.ProcessManagedBean) ProcessSyntheticBean(jakarta.enterprise.inject.spi.ProcessSyntheticBean) TypeLiteral(jakarta.enterprise.util.TypeLiteral) ProcessProducer(jakarta.enterprise.inject.spi.ProcessProducer) AfterBeanDiscovery(jakarta.enterprise.inject.spi.AfterBeanDiscovery) Test(org.junit.Test)

Example 3 with ProcessInjectionPoint

use of jakarta.enterprise.inject.spi.ProcessInjectionPoint in project helidon by oracle.

the class OciCdiExtension method updateInjectionPoints.

/**
 * Add internal qualifier.
 *
 * @param event CDI event
 */
void updateInjectionPoints(@Observes ProcessInjectionPoint<?, ?> event) {
    InjectionPoint injectionPoint = event.getInjectionPoint();
    Annotated annotated = injectionPoint.getAnnotated();
    Type type = injectionPoint.getType();
    if (supportedTypes.contains(type)) {
        Named name = annotated.getAnnotation(Named.class);
        OciInternal internal = OciInternal.Literal.create((name == null ? "" : name.value()));
        event.configureInjectionPoint().addQualifier(internal);
    }
}
Also used : Annotated(jakarta.enterprise.inject.spi.Annotated) Named(jakarta.inject.Named) Type(java.lang.reflect.Type) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint)

Example 4 with ProcessInjectionPoint

use of jakarta.enterprise.inject.spi.ProcessInjectionPoint in project helidon by oracle.

the class JedisExtension method processJedisInjectionPoint.

private <T extends Jedis> void processJedisInjectionPoint(@Observes final ProcessInjectionPoint<?, T> e) {
    if (e != null) {
        final InjectionPoint injectionPoint = e.getInjectionPoint();
        if (injectionPoint != null) {
            final Type type = injectionPoint.getType();
            assert type instanceof Class;
            assert Jedis.class.isAssignableFrom((Class<?>) type);
            final Set<Annotation> qualifiers = injectionPoint.getQualifiers();
            for (final Annotation qualifier : qualifiers) {
                final String instanceName;
                if (qualifier instanceof Default) {
                    instanceName = "default";
                } else if (qualifier instanceof Named) {
                    instanceName = ((Named) qualifier).value();
                } else {
                    instanceName = null;
                }
                if (instanceName != null && !instanceName.isEmpty()) {
                    this.instanceNames.add(instanceName);
                }
            }
        }
    }
}
Also used : Named(jakarta.inject.Named) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) Default(jakarta.enterprise.inject.Default) Annotation(java.lang.annotation.Annotation)

Example 5 with ProcessInjectionPoint

use of jakarta.enterprise.inject.spi.ProcessInjectionPoint in project helidon by oracle.

the class JedisExtension method processJedisProviderInjectionPoint.

private <T extends Provider<Jedis>> void processJedisProviderInjectionPoint(@Observes final ProcessInjectionPoint<?, T> e) {
    if (e != null) {
        final InjectionPoint injectionPoint = e.getInjectionPoint();
        if (injectionPoint != null) {
            final Type type = injectionPoint.getType();
            assert type instanceof ParameterizedType;
            assert Provider.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType());
            final Set<Annotation> qualifiers = injectionPoint.getQualifiers();
            for (final Annotation qualifier : qualifiers) {
                final String instanceName;
                if (qualifier instanceof Default) {
                    instanceName = "default";
                } else if (qualifier instanceof Named) {
                    instanceName = ((Named) qualifier).value();
                } else {
                    instanceName = null;
                }
                if (instanceName != null && !instanceName.isEmpty()) {
                    this.instanceNames.add(instanceName);
                }
            }
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Named(jakarta.inject.Named) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) Default(jakarta.enterprise.inject.Default) Annotation(java.lang.annotation.Annotation)

Aggregations

ProcessInjectionPoint (jakarta.enterprise.inject.spi.ProcessInjectionPoint)14 InjectionPoint (jakarta.enterprise.inject.spi.InjectionPoint)13 Type (java.lang.reflect.Type)11 Named (jakarta.inject.Named)7 Annotation (java.lang.annotation.Annotation)7 ParameterizedType (java.lang.reflect.ParameterizedType)7 Default (jakarta.enterprise.inject.Default)6 Annotated (jakarta.enterprise.inject.spi.Annotated)2 RequestScoped (jakarta.enterprise.context.RequestScoped)1 InjectionException (jakarta.enterprise.inject.InjectionException)1 AfterBeanDiscovery (jakarta.enterprise.inject.spi.AfterBeanDiscovery)1 AfterDeploymentValidation (jakarta.enterprise.inject.spi.AfterDeploymentValidation)1 AfterTypeDiscovery (jakarta.enterprise.inject.spi.AfterTypeDiscovery)1 BeforeBeanDiscovery (jakarta.enterprise.inject.spi.BeforeBeanDiscovery)1 BeforeShutdown (jakarta.enterprise.inject.spi.BeforeShutdown)1 DeploymentException (jakarta.enterprise.inject.spi.DeploymentException)1 Extension (jakarta.enterprise.inject.spi.Extension)1 ProcessAnnotatedType (jakarta.enterprise.inject.spi.ProcessAnnotatedType)1 ProcessBean (jakarta.enterprise.inject.spi.ProcessBean)1 ProcessBeanAttributes (jakarta.enterprise.inject.spi.ProcessBeanAttributes)1