Search in sources :

Example 11 with ProcessInjectionPoint

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

the class JedisExtension method processJedisPoolConfigInjectionPoint.

private <T extends JedisPoolConfig> void processJedisPoolConfigInjectionPoint(@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 JedisPoolConfig.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 12 with ProcessInjectionPoint

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

the class JpaExtension method saveEntityManagerQualifiers.

/**
 * Stores {@link Set}s of qualifiers that annotate {@link
 * EntityManager}-typed injection points.
 *
 * <p>{@link EntityManager}-typed beans will be added for each
 * such {@link Set}.</p>
 *
 * @param event a {@link ProcessInjectionPoint} container
 * lifecycle event; must not be {@code null}
 *
 * @exception NullPointerException if {@code event} is {@code
 * null}
 */
private <T extends EntityManager> void saveEntityManagerQualifiers(@Observes final ProcessInjectionPoint<?, T> event) {
    final String cn = JpaExtension.class.getName();
    final String mn = "saveEntityManagerQualifiers";
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.entering(cn, mn, event);
    }
    Objects.requireNonNull(event);
    final InjectionPoint injectionPoint = event.getInjectionPoint();
    assert injectionPoint != null;
    final Set<Annotation> qualifiers = injectionPoint.getQualifiers();
    assert qualifiers != null;
    boolean error = false;
    if (qualifiers.contains(JpaTransactionScoped.Literal.INSTANCE)) {
        if (qualifiers.contains(CdiTransactionScoped.Literal.INSTANCE) || qualifiers.contains(Extended.Literal.INSTANCE) || qualifiers.contains(NonTransactional.Literal.INSTANCE)) {
            error = true;
        }
    } else if (qualifiers.contains(Extended.Literal.INSTANCE)) {
        if (qualifiers.contains(CdiTransactionScoped.Literal.INSTANCE) || qualifiers.contains(NonTransactional.Literal.INSTANCE)) {
            error = true;
        }
    } else if (qualifiers.contains(NonTransactional.Literal.INSTANCE)) {
        if (qualifiers.contains(CdiTransactionScoped.Literal.INSTANCE)) {
            error = true;
        }
    } else if (qualifiers.contains(Synchronized.Literal.INSTANCE)) {
        if (qualifiers.contains(Unsynchronized.Literal.INSTANCE)) {
            error = true;
        }
    }
    if (error) {
        event.addDefinitionError(new InjectionException("Invalid injection point; some qualifiers are mutually exclusive: " + qualifiers));
    } else {
        this.persistenceContextQualifiers.add(qualifiers);
    }
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.exiting(cn, mn);
    }
}
Also used : InjectionException(jakarta.enterprise.inject.InjectionException) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) Annotation(java.lang.annotation.Annotation)

Example 13 with ProcessInjectionPoint

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

the class JpaExtension method saveEntityManagerFactoryQualifiers.

/**
 * Stores {@link Set}s of qualifiers that annotate {@link
 * EntityManagerFactory}-typed injection points.
 *
 * <p>{@link EntityManagerFactory}-typed beans will be added for
 * each such {@link Set}.</p>
 *
 * @param event a {@link ProcessInjectionPoint} container
 * lifecycle event; must not be {@code null}
 *
 * @exception NullPointerException if {@code event} is {@code
 * null}
 */
private <T extends EntityManagerFactory> void saveEntityManagerFactoryQualifiers(@Observes final ProcessInjectionPoint<?, T> event) {
    final String cn = JpaExtension.class.getName();
    final String mn = "saveEntityManagerFactoryQualifiers";
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.entering(cn, mn, event);
    }
    Objects.requireNonNull(event);
    final InjectionPoint injectionPoint = event.getInjectionPoint();
    assert injectionPoint != null;
    this.persistenceUnitQualifiers.add(injectionPoint.getQualifiers());
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.exiting(cn, mn);
    }
}
Also used : ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint)

Example 14 with ProcessInjectionPoint

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

the class JwtAuthCdiExtension method collectClaimProducer.

/**
 * Process each injection point for {@link Claim}.
 *
 * @param pip event from CDI container
 */
void collectClaimProducer(@Observes ProcessInjectionPoint<?, ?> pip) {
    Claim claim = pip.getInjectionPoint().getAnnotated().getAnnotation(Claim.class);
    if (claim != null) {
        if ((claim.standard() != Claims.UNKNOWN) && !claim.value().isEmpty()) {
            throw new DeploymentException("Claim annotation should not have both values at value and standard! " + "@Claim(value=" + claim.value() + ", standard=Claims." + claim.standard().name() + ")");
        }
        InjectionPoint ip = pip.getInjectionPoint();
        Type type = ip.getType();
        FieldTypes ft = FieldTypes.forType(type);
        ClaimLiteral q = new ClaimLiteral((claim.standard() == Claims.UNKNOWN) ? claim.value() : claim.standard().name(), ip.getMember().getDeclaringClass().getName() + "." + getFieldName(ip), ft.isOptional(), ft.isClaimValue(), ft.getField0().getRawType(), ft.getField1().getRawType(), ft.getField2().getRawType(), ft.getField3().getRawType(), type.toString());
        pip.configureInjectionPoint().addQualifier(q);
        if (ft.getField0().getRawType().equals(ClaimValue.class)) {
            claimValueQualifiers.add(new ClaimIP(q, type));
        } else {
            qualifiers.add(new ClaimIP(q, type));
        }
    }
}
Also used : Type(java.lang.reflect.Type) ParameterizedType(java.lang.reflect.ParameterizedType) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) DeploymentException(jakarta.enterprise.inject.spi.DeploymentException) Claim(org.eclipse.microprofile.jwt.Claim)

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