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

The following examples show how to use javax.enterprise.inject.spi.ProcessAnnotatedType#setAnnotatedType() . 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: MappedJsf2ScopeExtension.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
protected void convertJsf2Scopes(@Observes ProcessAnnotatedType processAnnotatedType)
{
    if (!isActivated)
    {
        return;
    }

    //TODO
    //CodiStartupBroadcaster.broadcastStartup();

    Class<? extends Annotation> jsf2ScopeAnnotation = getJsf2ScopeAnnotation(processAnnotatedType);

    if (jsf2ScopeAnnotation != null && !isBeanWithManagedBeanAnnotation(processAnnotatedType))
    {
        processAnnotatedType.setAnnotatedType(
                convertBean(processAnnotatedType.getAnnotatedType(), jsf2ScopeAnnotation));
    }
}
 
Example 2
Source File: NamingConventionAwareMetadataFilter.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
public void ensureNamingConvention(@Observes ProcessAnnotatedType processAnnotatedType)
{
    Class<?> beanClass = processAnnotatedType.getAnnotatedType().getJavaClass();

    Named namedAnnotation = beanClass.getAnnotation(Named.class);
    if (namedAnnotation != null &&
            namedAnnotation.value().length() > 0 &&
            Character.isUpperCase(namedAnnotation.value().charAt(0)))
    {
        AnnotatedTypeBuilder builder = new AnnotatedTypeBuilder();
        builder.readFromType(beanClass);

        String beanName = namedAnnotation.value();
        String newBeanName = beanName.substring(0, 1).toLowerCase() + beanName.substring(1);

        builder.removeFromClass(Named.class)
                .addToClass(new NamedLiteral(newBeanName));

        processAnnotatedType.setAnnotatedType(builder.create());
    }
}
 
Example 3
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 4
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 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: GlobalInterceptorExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
protected void promoteInterceptors(@Observes ProcessAnnotatedType pat)
{
    if (priorityAnnotationInstance == null) //not CDI 1.1 or the extension is deactivated
    {
        return;
    }

    String beanClassName = pat.getAnnotatedType().getJavaClass().getName();
    if (beanClassName.startsWith(DS_PACKAGE_NAME))
    {
        if (pat.getAnnotatedType().isAnnotationPresent(Interceptor.class))
        {
            //noinspection unchecked
            pat.setAnnotatedType(new GlobalInterceptorWrapper(pat.getAnnotatedType(), priorityAnnotationInstance));
        }
        //currently not needed, because we don't use our interceptors internally -> check for the future
        else if (!beanClassName.contains(".test."))
        {
            for (Annotation annotation : pat.getAnnotatedType().getAnnotations())
            {
                if (beanManager.isInterceptorBinding(annotation.annotationType()))
                {
                    //once we see this warning we need to introduce double-call prevention logic due to WELD-1780
                    LOG.warning(beanClassName + " is an bean from DeltaSpike which is intercepted.");
                }
            }
        }
    }
}
 
Example 8
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 9
Source File: JpaExtension.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
<T> void addJpaToEmConsumers(@Observes @WithAnnotations(Unit.class) final ProcessAnnotatedType<T> pat) {
    if (pat.getAnnotatedType().isAnnotationPresent(Jpa.class)) {
        return;
    }
    pat.setAnnotatedType(new AutoJpaAnnotationType<T>(pat.getAnnotatedType()));
}
 
Example 10
Source File: MetricsExtension.java    From metrics-cdi with Apache License 2.0 4 votes vote down vote up
private <X> void metricsAnnotations(@Observes @WithAnnotations({CachedGauge.class, Counted.class, ExceptionMetered.class, Gauge.class, Metered.class, Timed.class}) ProcessAnnotatedType<X> pat) {
    pat.setAnnotatedType(new AnnotatedTypeDecorator<>(pat.getAnnotatedType(), METRICS_BINDING));
}
 
Example 11
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 12
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);
}
 
Example 13
Source File: BeanTestExtension.java    From BeanTest with Apache License 2.0 2 votes vote down vote up
/**
 * Adds {@link Inject} annotation to all the dependencies of the interceptor.
 * 
 * @param <X>
 *            the type of the annotated type
 * @param pat
 *            the process annotated type.
 */
private <X> void processInterceptorDependencies(ProcessAnnotatedType<X> pat) {
    AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<X>().readFromType(pat.getAnnotatedType());
    InjectionHelper.addInjectAnnotation(pat.getAnnotatedType(), builder);
    pat.setAnnotatedType(builder.create());
}