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);
}
});
}
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);
}
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);
}
}
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);
}
}
}
}
}
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);
}
}
}
}
}
Aggregations