Java 类javax.enterprise.inject.spi.WithAnnotations 实例源码

项目:opendata-common    文件:SchedulerExtension.java   
<T> void findJobs( @Observes @WithAnnotations({Cron.class}) ProcessAnnotatedType<T> pat, BeanManager beanManager )
{
    // Ensure we are named otherwise job won't fire as we can't locate it
    AnnotatedType<?> type = pat.getAnnotatedType();
    Class<?> clazz = type.getJavaClass();
    CDIUtils.addTypeAnnotation( pat, Named.class, () -> new NamedImpl( "Schedule_" + (id++) ) );

    if( type.isAnnotationPresent( Cron.class ) ) {
        if( Job.class.isAssignableFrom( clazz ) ) {
            jobClasses.add( clazz );
        }
        else {
            throw new UnsupportedOperationException( "@Cron on type must implement Job" );
        }
    }
    else {
        for( AnnotatedMethod<?> meth: type.getMethods() ) {
            if( meth.isAnnotationPresent( Cron.class ) ) {
                jobClasses.add( clazz );
            }
        }
    }
}
项目:Camel    文件:CamelCdiTestExtension.java   
/**
 * Activates the alternatives declared with {@code @Beans} globally for the
 * application.
 * <p/>
 * For every types and every methods of every types declared with
 * {@link Beans#alternatives()}, the {@code Priority} annotation is added
 * so that the corresponding alternatives are selected globally for the
 * entire application.
 *
 * @see Beans
 */
private <T> void alternatives(@Observes @WithAnnotations(Alternative.class) ProcessAnnotatedType<T> pat) {
    AnnotatedType<T> type = pat.getAnnotatedType();

    if (!Arrays.asList(beans.alternatives()).contains(type.getJavaClass())) {
        // Only select globally the alternatives that are declared with @Beans
        return;
    }

    Set<AnnotatedMethod<? super T>> methods = new HashSet<>();
    for (AnnotatedMethod<? super T> method : type.getMethods()) {
        if (method.isAnnotationPresent(Alternative.class) && !method.isAnnotationPresent(Priority.class)) {
            methods.add(new AnnotatedMethodDecorator<>(method, PriorityLiteral.of(APPLICATION)));
        }
    }

    if (type.isAnnotationPresent(Alternative.class) && !type.isAnnotationPresent(Priority.class)) {
        pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, PriorityLiteral.of(APPLICATION), methods));
    } else if (!methods.isEmpty()) {
        pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, methods));
    }
}
项目:wildfly-microprofile-health    文件:CDIExtension.java   
/**
 * Discover all classes that implements HealthCheckProcedure
 */
public void observeResources(@Observes @WithAnnotations({Health.class})  ProcessAnnotatedType<? extends HealthCheck> event) {
   AnnotatedType<? extends HealthCheck> annotatedType = event.getAnnotatedType();
   Class<? extends HealthCheck> javaClass = annotatedType.getJavaClass();
   MicroProfileHealthLogger.ROOT_LOGGER.debugf("Discovered health check procedure %s", javaClass);
   delegates.add(annotatedType);
}
项目:snoopee    文件:SnoopEEScannerExtension.java   
<T> void processAnnotatedType(@Observes @WithAnnotations(EnableSnoopEEClient.class) ProcessAnnotatedType<T> pat) {

        // workaround for WELD bug revealed by JDK8u60
        final ProcessAnnotatedType<T> snoopAnnotated = pat;

        LOGGER.config(() -> "Found @EnableSnoopEEClient annotated class: " + snoopAnnotated.getAnnotatedType().getJavaClass().getName());
        snoopEnabled = true;
        serviceName = snoopAnnotated.getAnnotatedType().getAnnotation(EnableSnoopEEClient.class).serviceName();
        LOGGER.config(() -> "SnoopEE Service name is: " + serviceName);
    }
项目:snoopee    文件:SnoopEEScannerExtension.java   
<T> void processAnnotatedType(@Observes @WithAnnotations(EnableSnoopEEClient.class) ProcessAnnotatedType<T> pat) {

        // workaround for WELD bug revealed by JDK8u60
        final ProcessAnnotatedType<T> snoopAnnotated = pat;

        LOGGER.config(() -> "Found @EnableSnoopEEClient annotated class: " + snoopAnnotated.getAnnotatedType().getJavaClass().getName());
        snoopEnabled = true;
        serviceName = snoopAnnotated.getAnnotatedType().getAnnotation(EnableSnoopEEClient.class).serviceName();
        LOGGER.config(() -> "SnoopEE Service name is: " + serviceName);
    }
项目:weld-vertx    文件:ServiceProxyExtension.java   
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());
    }
}
项目:wildfly-swarm    文件:HealthExtension.java   
public <T> void observeResources(@Observes @WithAnnotations({Health.class}) ProcessAnnotatedType<T> event) {

        AnnotatedType<T> annotatedType = event.getAnnotatedType();
        Class<T> javaClass = annotatedType.getJavaClass();
        for (Class<?> intf : javaClass.getInterfaces()) {
            if (intf.getName().equals(HealthCheck.class.getName())) {
                log.info(">> Discovered health check procedure " + javaClass);
                delegates.add(annotatedType);
            }
        }
    }
项目:snoop    文件:SnoopScannerExtension.java   
<T> void processAnnotatedType(@Observes @WithAnnotations(EnableSnoopClient.class) ProcessAnnotatedType<T> pat) {

        // workaround for WELD bug revealed by JDK8u60
        final ProcessAnnotatedType<T> snoopAnnotated = pat;

        LOGGER.config(() -> "Found @EnableSnoopClient annotated class: " + snoopAnnotated.getAnnotatedType().getJavaClass().getName());
        snoopEnabled = true;
        serviceName = snoopAnnotated.getAnnotatedType().getAnnotation(EnableSnoopClient.class).serviceName();
        LOGGER.config(() -> "Snoop Service name is: " + serviceName);
    }
项目:snoop    文件:SnoopEurekaScannerExtension.java   
<T> void processAnnotatedType(@Observes @WithAnnotations({EnableEurekaClient.class}) ProcessAnnotatedType<T> pat) {

   LOGGER.config(() -> "Found @EnableEurekaClient annotated class: " + pat.getAnnotatedType().getJavaClass().getName());
   eurekaEnabled = true;
   applicationName = pat.getAnnotatedType().getAnnotation(EnableEurekaClient.class).name();
   LOGGER.config(() -> "Eureka application name is: " + applicationName);
}
项目:SimplePersistence    文件:HibernateFilterExtension.java   
public <T> void processAnnotatedType(
        @Observes @WithAnnotations({ FilterParameters.class, FilterParameter.class }) final ProcessAnnotatedType<T> event) {
    final AnnotatedType<T> annotatedType = event.getAnnotatedType();
    if (annotatedType.isAnnotationPresent(FilterParameters.class)) {
        final FilterParameters annotation = annotatedType.getAnnotation(FilterParameters.class);
        addFilterParameters(annotation);
    }
    if (annotatedType.isAnnotationPresent(FilterParameter.class)) {
        // TODO deal with single parameters
    }
}
项目:javaee-nosql    文件:MongoExtension.java   
/**
 * Looks for {@link MongoClientDefinition} annotation to capture it.
 * Also Checks if the application contains more than one of these definition
 */
void detectMongoClientDefinition(
        @Observes @WithAnnotations(MongoClientDefinition.class) ProcessAnnotatedType<?> pat) {
    AnnotatedType at = pat.getAnnotatedType();

    MongoClientDefinition md = at.getAnnotation(MongoClientDefinition.class);
    String name = md.name();

    if (mongoDef != null) {
        moreThanOne = true;
    } else {
        mongoDef = md;
    }
}
项目:hammock    文件:JerseyCdiExtension.java   
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());
    }
}
项目:hammock    文件:JerseyCdiExtension.java   
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());
    }
}
项目:kie-wb-common    文件:ControllerExtension.java   
public <T> void processStandaloneController(@WithAnnotations({StandaloneController.class}) @Observes ProcessAnnotatedType<T> event) {
    LOGGER.info("Processing standalone controller class: {}", event.getAnnotatedType().getJavaClass());
    StandaloneController a = event.getAnnotatedType().getJavaClass().getAnnotation(StandaloneController.class);
    if (a != null && ControllerUtils.useEmbeddedController()) {
        LOGGER.info("Removing standalone controller class {} from CDI context", event.getAnnotatedType().getJavaClass());
        event.veto();
    }
}
项目:kie-wb-common    文件:ControllerExtension.java   
public <T> void processEmbeddedController(@WithAnnotations({EmbeddedController.class}) @Observes ProcessAnnotatedType<T> event) {
    LOGGER.info("Processing embedded controller class: {}", event.getAnnotatedType().getJavaClass());
    EmbeddedController a = event.getAnnotatedType().getJavaClass().getAnnotation(EmbeddedController.class);
    if (a != null && ControllerUtils.useEmbeddedController() == false) {
        LOGGER.info("Removing embedded controller class {} from CDI context", event.getAnnotatedType().getJavaClass());
        event.veto();
    }
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:ObserverExtension.java   
<T> void processAnnotatedTypeWithAnnotations(
        @Observes @WithAnnotations({ Named.class }) ProcessAnnotatedType<T> pat) {
    logger.info("scanning type: " + pat.getAnnotatedType().getJavaClass().getName());
    processAnnotatedTypeWithAnnotations++;
}
项目:reactive-cdi-events    文件:ReactorExtension.java   
public void findObservers(@Observes @WithAnnotations(ObservesReactor.class)ProcessAnnotatedType<?> pat) {
    discoveredTypes.add(pat.getAnnotatedType());
}
项目:java-restify    文件:RestifyCdiExtension.java   
public void collect(@Observes @WithAnnotations(Restifyable.class) ProcessAnnotatedType<?> type) {
    types.add(type.getAnnotatedType().getJavaClass());
}
项目:wildfly-swarm    文件:MetricCdiInjectionExtension.java   
private <X> void metricsAnnotations(@Observes @WithAnnotations({ Counted.class, Gauge.class, Metered.class, Timed.class }) ProcessAnnotatedType<X> pat) {
    AnnotatedTypeDecorator newPAT = new AnnotatedTypeDecorator<>(pat.getAnnotatedType(), METRICS_BINDING);
    LOGGER.debugf("annotations: %s", newPAT.getAnnotations());
    LOGGER.debugf("methods: %s", newPAT.getMethods());
    pat.setAnnotatedType(newPAT);
}
项目:appformer    文件:SystemConfigProducer.java   
<T> void processAnnotatedType(@Observes @WithAnnotations(Veto.class) ProcessAnnotatedType<T> pat) {
    pat.veto();
}
项目:camel-cdi    文件:CdiCamelExtension.java   
private void importResources(@Observes @WithAnnotations(ImportResource.class) ProcessAnnotatedType<?> pat) {
    resources.add(pat.getAnnotatedType().getAnnotation(ImportResource.class));
}
项目:camel-cdi    文件:CdiCamelExtension.java   
private void typeConverters(@Observes @WithAnnotations(Converter.class) ProcessAnnotatedType<?> pat) {
    converters.add(pat.getAnnotatedType().getJavaClass());
}
项目:camel-cdi    文件:CdiCamelExtension.java   
private void camelAnnotations(@Observes @WithAnnotations({BeanInject.class, Consume.class,
    EndpointInject.class, Produce.class, PropertyInject.class}) ProcessAnnotatedType<?> pat) {
    camelBeans.add(pat.getAnnotatedType());
}
项目:camel-cdi    文件:CdiCamelExtension.java   
private void consumeBeans(@Observes @WithAnnotations(Consume.class) ProcessAnnotatedType<?> pat) {
    eagerBeans.add(pat.getAnnotatedType());
}
项目:hammock    文件:WebServerExtension.java   
public void findListeners(@Observes @WithAnnotations({WebListener.class})
                          ProcessAnnotatedType<? extends ServletContextListener> pat) {
    listeners.add(pat.getAnnotatedType().getJavaClass());
}
项目:hammock    文件:WebServerExtension.java   
public void findServlets(@Observes @WithAnnotations({WebServlet.class})
                                  ProcessAnnotatedType<? extends HttpServlet> pat) {
    servlets.add(pat.getAnnotatedType().getJavaClass());
}
项目:hammock    文件:WebServerExtension.java   
public void findFilters(@Observes @WithAnnotations({WebFilter.class})
                                  ProcessAnnotatedType<? extends Filter> pat) {
    filters.add(pat.getAnnotatedType().getJavaClass());
}
项目:hammock    文件:UndertowWebSocketExtension.java   
public void findWebSocketServers(@Observes @WithAnnotations(ServerEndpoint.class)ProcessAnnotatedType<?> pat) {
    endpointClasses.add(pat.getAnnotatedType().getJavaClass());
}
项目:microservices-tutorial    文件:RestMonitorExtension.java   
public void watchForRestEndpoints(@Observes @WithAnnotations(Path.class)
                                  ProcessAnnotatedType processAnnotatedType) {
    restEndpointClasses.add(processAnnotatedType.getAnnotatedType().getJavaClass());
}
项目:microservices-tutorial    文件:RestMonitorExtension.java   
public void watchForProviders(@Observes @WithAnnotations(Provider.class)
                              ProcessAnnotatedType processAnnotatedType) {
    providerClasses.add(processAnnotatedType.getAnnotatedType().getJavaClass());
}
项目:metrics-cdi    文件:MetricsExtension.java   
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));
}
项目:BeanTest    文件:BeanTestExtension.java   
/**
 * Replaces the meta data of the {@link ProcessAnnotatedType}.
 * 
 * <p>
 * The ProcessAnnotatedType's meta data will be replaced, if the annotated type has one of the following annotations:
 * <ul>
 * <li> {@link Stateless}
 * <li> {@link MessageDriven}
 * <li> {@link Interceptor}
 * <li> {@link Singleton}
 * </ul>
 *
 * @param <X> the type of the ProcessAnnotatedType
 * @param pat the annotated type representing the class being processed
 */
public <X> void processInjectionTarget(@Observes @WithAnnotations({Stateless.class, MessageDriven.class, Interceptor.class, Singleton.class}) ProcessAnnotatedType<X> pat) {
    if (pat.getAnnotatedType().isAnnotationPresent(Stateless.class) || pat.getAnnotatedType().isAnnotationPresent(MessageDriven.class)) {
        modifiyAnnotatedTypeMetadata(pat);
    } else if (pat.getAnnotatedType().isAnnotationPresent(Interceptor.class)) {
        processInterceptorDependencies(pat);
    } else if(pat.getAnnotatedType().isAnnotationPresent(Singleton.class)) {
        addApplicationScopedAndTransactionalToSingleton(pat);
    }
}