Java Code Examples for javax.enterprise.inject.spi.ProcessAnnotatedType#getAnnotatedType()

The following examples show how to use javax.enterprise.inject.spi.ProcessAnnotatedType#getAnnotatedType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageBundleExtension.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
protected void detectInterfaces(@Observes ProcessAnnotatedType processAnnotatedType)
{
    if (!isActivated)
    {
        return;
    }

    AnnotatedType<?> type = processAnnotatedType.getAnnotatedType();

    if (type.isAnnotationPresent(MessageBundle.class))
    {
        if (validateMessageBundle(type.getJavaClass()))
        {
            messageBundleTypes.add(type);
        }
    }
}
 
Example 2
Source File: MetricCdiInjectionExtension.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
private <X> void applyMetricsBinding(@Observes @WithAnnotations({ Gauge.class }) ProcessAnnotatedType<X> pat) {
    Class<X> clazz = pat.getAnnotatedType().getJavaClass();
    Package pack = clazz.getPackage();
    if (pack == null || !pack.getName().equals(GaugeRegistrationInterceptor.class.getPackage().getName())) {
        if (!clazz.isInterface()) {
            AnnotatedTypeDecorator newPAT = new AnnotatedTypeDecorator<>(pat.getAnnotatedType(), METRICS_BINDING);
            pat.setAnnotatedType(newPAT);
        }
    }

}
 
Example 3
Source File: TestInstanceInjectionExtension.java    From weld-junit with Apache License 2.0 5 votes vote down vote up
<T> void rewriteTestClassScope(@Observes ProcessAnnotatedType<T> pat, BeanManager beanManager) {

        AnnotatedType<T> annotatedType = pat.getAnnotatedType();

        if (annotatedType.getJavaClass().equals(testClass)) {

            // Replace any test class's scope with @Singleton
            Set<Annotation> annotations = annotatedType.getAnnotations().stream()
                    .filter(annotation -> beanManager.isScope(annotation.annotationType()))
                    .collect(Collectors.toSet());
            annotations.add(SINGLETON_LITERAL);

            pat.setAnnotatedType(new AnnotationRewritingAnnotatedType<>(annotatedType, annotations));
        }
    }
 
Example 4
Source File: ServiceProxyExtension.java    From weld-vertx with Apache License 2.0 5 votes vote down vote up
void findServiceInterfaces(@Observes @WithAnnotations(ProxyGen.class) ProcessAnnotatedType<?> event, BeanManager beanManager) {
    AnnotatedType<?> annotatedType = event.getAnnotatedType();
    if (annotatedType.isAnnotationPresent(ProxyGen.class) && annotatedType.getJavaClass().isInterface()) {
        LOGGER.debug("Service interface {0} discovered", annotatedType.getJavaClass());
        serviceInterfaces.add(annotatedType.getJavaClass());
    }
}
 
Example 5
Source File: MeecrowaveExtension.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
void onPat(@Observes final ProcessAnnotatedType<?> pat, final BeanManager bm) {
    final AnnotatedType<?> at = pat.getAnnotatedType();
    if (isJaxRsEndpoint(bm, at)) {
        pat.setAnnotatedType(new JAXRSFIeldInjectionAT(this, at));
    } else if (isVetoedMeecrowaveCore(at.getJavaClass().getName())) {
        pat.veto();
    }
}
 
Example 6
Source File: BeanTestExtension.java    From BeanTest with Apache License 2.0 5 votes vote down vote up
/**
 * Adds {@link Transactional} and {@link RequestScoped} to the given annotated type and converts
 * its EJB injection points into CDI injection points (i.e. it adds the {@link Inject})
 * @param <X> the type of the annotated type
 * @param pat the process annotated type.
 */
private <X> void modifiyAnnotatedTypeMetadata(ProcessAnnotatedType<X> pat) {
    AnnotatedType at = pat.getAnnotatedType();
    
    AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<X>().readFromType(at);
    builder.addToClass(AnnotationInstances.TRANSACTIONAL).addToClass(AnnotationInstances.REQUEST_SCOPED);

    InjectionHelper.addInjectAnnotation(at, builder);
    //Set the wrapper instead the actual annotated type
    pat.setAnnotatedType(builder.create());

}
 
Example 7
Source File: JerseyCdiExtension.java    From hammock with Apache License 2.0 5 votes vote down vote up
public <T> void observeResources(@WithAnnotations({ Path.class }) @Observes ProcessAnnotatedType<T> event) {
    AnnotatedType<T> annotatedType = event.getAnnotatedType();

    if (!annotatedType.getJavaClass().isInterface()) {
        this.resources.add(annotatedType.getJavaClass());
    }
}
 
Example 8
Source File: JerseyCdiExtension.java    From hammock with Apache License 2.0 5 votes vote down vote up
public <T> void observeProviders(@WithAnnotations({ Provider.class }) @Observes ProcessAnnotatedType<T> event) {
    AnnotatedType<T> annotatedType = event.getAnnotatedType();

    if (!annotatedType.getJavaClass().isInterface()) {
        this.providers.add(annotatedType.getJavaClass());
    }
}
 
Example 9
Source File: TomEESecurityExtension.java    From tomee with Apache License 2.0 5 votes vote down vote up
void processAuthenticationMechanismDefinitions(@Observes
                                               @WithAnnotations({
                                                       BasicAuthenticationMechanismDefinition.class,
                                                       FormAuthenticationMechanismDefinition.class
                                               }) final ProcessAnnotatedType<?> processAnnotatedType) {
    final AnnotatedType<?> annotatedType = processAnnotatedType.getAnnotatedType();

    if (annotatedType.isAnnotationPresent(BasicAuthenticationMechanismDefinition.class)) {
        basicAuthentication.add(annotatedType);
    }

    if (annotatedType.isAnnotationPresent(FormAuthenticationMechanismDefinition.class)) {
        formAuthentication.add(annotatedType);
    }
}
 
Example 10
Source File: InterDynExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public void processAnnotatedType(@Observes ProcessAnnotatedType pat)
{
    if (enabled)
    {
        AnnotatedType at = pat.getAnnotatedType();
        String beanClassName = at.getJavaClass().getName();
        AnnotatedTypeBuilder atb = null;
        for (AnnotationRule rule : interceptorRules)
        {
            if (beanClassName.matches(rule.getRule()))
            {
                if (rule.requiresProxy() && !ClassUtils.isProxyableClass(at.getJavaClass()))
                {
                    logger.info("Skipping unproxyable class " + beanClassName +
                            " even if matches rule=" + rule.getRule());
                    return;
                }

                if (atb == null)
                {
                    atb = new AnnotatedTypeBuilder();
                    atb.readFromType(at);
                }
                atb.addToClass(rule.getAdditionalAnnotation());
                logger.info("Adding Dynamic Interceptor " + rule.getAdditionalAnnotation()
                        + " to class " + beanClassName );
            }
        }
        if (atb != null)
        {
            pat.setAnnotatedType(atb.create());
        }
    }
}
 
Example 11
Source File: HealthExtension.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public void observeResources(@Observes ProcessAnnotatedType<SmallRyeHealthReporter> event) {
    delegate = event.getAnnotatedType();
}
 
Example 12
Source File: BeanTestExtension.java    From BeanTest with Apache License 2.0 3 votes vote down vote up
/**
 * Adds {@link Transactional} and {@link ApplicationScoped} to the given annotated type and converts
 * its EJB injection points into CDI injection points (i.e. it adds the {@link Inject})
 * @param <X> the type of the annotated type.
 * @param pat the process annotated type.
 */
private <X> void addApplicationScopedAndTransactionalToSingleton(ProcessAnnotatedType<X> pat) {
    AnnotatedType at = pat.getAnnotatedType();
    
    AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<X>().readFromType(at);
    
    builder.addToClass(AnnotationInstances.APPLICATION_SCOPED).addToClass(AnnotationInstances.TRANSACTIONAL);
    
    InjectionHelper.addInjectAnnotation(at, builder);
    
    pat.setAnnotatedType(builder.create());
}
 
Example 13
Source File: JAXRSCdiResourceExtension.java    From cxf with Apache License 2.0 3 votes vote down vote up
/**
 * For any {@link AnnotatedType} that includes a {@link Context} injection point, this method replaces
 * the field with the following code:
 * <pre>
 *     @Inject @ContextResolved T field;
 * </pre>
 * For any usage of T that is a valid context object in JAX-RS.
 *
 * It also has a side effect of capturing the context object type, in case no
 * {@link org.apache.cxf.jaxrs.ext.ContextClassProvider} was registered for the type.
 *
 * @param processAnnotatedType the annotated type being investigated
 * @param <X> the generic type of that processAnnotatedType
 */
public <X> void convertContextsToCdi(@Observes @WithAnnotations({Context.class})
                                         ProcessAnnotatedType<X> processAnnotatedType) {
    AnnotatedType<X> annotatedType = processAnnotatedType.getAnnotatedType();
    DelegateContextAnnotatedType<X> type = new DelegateContextAnnotatedType<>(annotatedType);
    contextTypes.addAll(type.getContextFieldTypes());
    processAnnotatedType.setAnnotatedType(type);
}