/** * Ignores the classes which are manually added using bindings (through {@link Application} class) and scanned by CDI. * The manual adding is privileged and the beans scanned using CDI are ignored. * <p> * TODO: The method counts with the condition that the all bindings are known before the CDI scanning has been started, * can be changed during the migration from CDI SE to JAVA EE environment. * * @param pat processed type. * @param <T> type of the scanned bean. */ public <T> void ignoreManuallyRegisteredComponents( @Observes @WithAnnotations({ Path.class, Provider.class }) ProcessAnnotatedType<T> pat) { for (Binding binding : bindings.getBindings()) { if (ClassBinding.class.isAssignableFrom(binding.getClass())) { ClassBinding<?> classBinding = (ClassBinding<?>) binding; if (pat.getAnnotatedType().getJavaClass() == classBinding.getService()) { pat.veto(); return; } } else if (InstanceBinding.class.isAssignableFrom(binding.getClass())) { InstanceBinding<?> instanceBinding = (InstanceBinding<?>) binding; if (pat.getAnnotatedType().getJavaClass() == instanceBinding.getService().getClass()) { pat.veto(); return; } } } }
private void recordAnnotatedGaugeSite(@Observes @WithAnnotations(Gauge.class) ProcessAnnotatedType<?> pat) { LOGGER.log(Level.FINE, () -> "### recordAnnoatedGaugeSite for class " + pat.getAnnotatedType().getJavaClass()); AnnotatedType<?> type = pat.getAnnotatedType(); LOGGER.log(Level.FINE, () -> "### Processing annotations for " + type.getJavaClass().getName()); // Register metrics based on annotations AnnotatedTypeConfigurator<?> configurator = pat.configureAnnotatedType(); Class<?> clazz = configurator.getAnnotated().getJavaClass(); // If abstract class, then handled by concrete subclasses if (Modifier.isAbstract(clazz.getModifiers())) { return; } // Process @Gauge methods keeping non-private declared on this class configurator.filterMethods(method -> method.getJavaMember().getDeclaringClass().equals(clazz) && !Modifier.isPrivate(method.getJavaMember().getModifiers()) && method.isAnnotationPresent(Gauge.class)) .forEach(method -> { Method javaMethod = method.getAnnotated().getJavaMember(); String explicitGaugeName = method.getAnnotated().getAnnotation(Gauge.class).name(); String gaugeName = String.format("%s.%s", clazz.getName(), explicitGaugeName != null && explicitGaugeName.length() > 0 ? explicitGaugeName : javaMethod.getName()); annotatedGaugeSites.put(gaugeName, method); LOGGER.log(Level.FINE, () -> String.format("### Recorded annotated gauge with name %s", gaugeName)); }); }
private void registerMetrics(@Observes @WithAnnotations({Counted.class, Metered.class, Timed.class}) ProcessAnnotatedType<?> pat) {
public void registerClient(@Observes @WithAnnotations({RegisterRestClient.class}) ProcessAnnotatedType<?> pat) { Class<?> typeDef = pat.getAnnotatedType().getJavaClass(); if(typeDef.isInterface()) { proxyTypes.add(typeDef); pat.veto(); } else { errors.add(new IllegalArgumentException("Rest client needs to be interface: " + typeDef)); } }
/** * Set a default scope for each CDI bean which is a JAX-RS Provider. * * @param <T> type * @param event event * @param beanManager bean manager */ public <T> void observeProviders(@WithAnnotations({Provider.class}) @Observes ProcessAnnotatedType<T> event, BeanManager beanManager) { setBeanManager(beanManager); AnnotatedType<T> annotatedType = event.getAnnotatedType(); if(!annotatedType.getJavaClass().isInterface() && !isSessionBean(annotatedType) // This check is redundant for CDI 1.1 containers but required for CDI 1.0 && annotatedType.isAnnotationPresent(Provider.class)) { LogMessages.LOGGER.debug(Messages.MESSAGES.discoveredCDIBeanJaxRsProvider(annotatedType.getJavaClass().getCanonicalName())); event.setAnnotatedType(wrapAnnotatedType(annotatedType, applicationScopedLiteral)); this.providers.add(annotatedType.getJavaClass()); } }
/** * Set a default scope for each CDI bean which is a JAX-RS Resource. * * @param <T> type * @param event event * @param beanManager bean manager */ public <T> void observeResources(@WithAnnotations({Path.class}) @Observes ProcessAnnotatedType<T> event, BeanManager beanManager) { setBeanManager(beanManager); AnnotatedType<T> annotatedType = event.getAnnotatedType(); if(!annotatedType.getJavaClass().isInterface() && !isSessionBean(annotatedType) // This check is redundant for CDI 1.1 containers but required for CDI 1.0 && GetRestful.isRootResource(annotatedType.getJavaClass()) && !annotatedType.isAnnotationPresent(Decorator.class)) { LogMessages.LOGGER.debug(Messages.MESSAGES.discoveredCDIBeanJaxRsResource(annotatedType.getJavaClass().getCanonicalName())); event.setAnnotatedType(wrapAnnotatedType(annotatedType, requestScopedLiteral)); this.resources.add(annotatedType.getJavaClass()); } }
/** * Used to register the method validation interceptor bindings. * * @param processAnnotatedTypeEvent event fired for each annotated type * @param <T> the annotated type */ public <T> void processAnnotatedType(@Observes @WithAnnotations({ Constraint.class, Valid.class, ValidateOnExecution.class }) ProcessAnnotatedType<T> processAnnotatedTypeEvent) { Contracts.assertNotNull( processAnnotatedTypeEvent, "The ProcessAnnotatedType event cannot be null" ); // validation globally disabled if ( !isExecutableValidationEnabled ) { return; } AnnotatedType<T> type = processAnnotatedTypeEvent.getAnnotatedType(); Set<AnnotatedCallable<? super T>> constrainedCallables = determineConstrainedCallables( type ); if ( !constrainedCallables.isEmpty() ) { ValidationEnabledAnnotatedType<T> wrappedType = new ValidationEnabledAnnotatedType<>( type, constrainedCallables ); processAnnotatedTypeEvent.setAnnotatedType( wrappedType ); } }
public void findListeners(@Observes @WithAnnotations({WebListener.class}) ProcessAnnotatedType<? extends ServletContextListener> pat) { listeners.add(pat.getAnnotatedType().getJavaClass()); } public void findServlets(@Observes @WithAnnotations({WebServlet.class})
public void findServlets(@Observes @WithAnnotations({WebServlet.class}) ProcessAnnotatedType<? extends HttpServlet> pat) { servlets.add(pat.getAnnotatedType().getJavaClass()); } public void findFilters(@Observes @WithAnnotations({WebFilter.class})
public void findServlets(@Observes @WithAnnotations({WebServlet.class}) ProcessAnnotatedType<? extends HttpServlet> pat) { servlets.add(pat.getAnnotatedType().getJavaClass()); } public void findFilters(@Observes @WithAnnotations({WebFilter.class})
public void findClients(@Observes @WithAnnotations({RegisterRestClient.class}) ProcessAnnotatedType<?> pat) { Class<?> restClient = pat.getAnnotatedType().getJavaClass(); if (restClient.isInterface()) { restClientClasses.add(restClient); pat.veto(); } else { errors.add(new IllegalArgumentException("The class " + restClient + " is not an interface")); } }
public void registerRestClient(@Observes @WithAnnotations(RegisterRestClient.class) ProcessAnnotatedType<?> type) { Class<?> javaClass = type.getAnnotatedType().getJavaClass(); if (javaClass.isInterface()) { proxyTypes.add(javaClass); type.veto(); } else { errors.add(new IllegalArgumentException("Rest client needs to be an interface " + javaClass)); } }
public void findClients(@Observes @WithAnnotations({RegisterRestClient.class}) ProcessAnnotatedType<?> pat) { Class<?> restClient = pat.getAnnotatedType().getJavaClass(); if (restClient.isInterface()) { restClientClasses.add(restClient); pat.veto(); } else { errors.add(new IllegalArgumentException("The class " + restClient + " is not an interface")); } }
public void registerClient(@Observes @WithAnnotations({RegisterRestClient.class}) ProcessAnnotatedType<?> pat) { Class<?> typeDef = pat.getAnnotatedType().getJavaClass(); if(typeDef.isInterface()) { proxyTypes.add(typeDef); pat.veto(); } else { errors.add(new IllegalArgumentException("Rest client needs to be interface: " + typeDef)); } }
public <T> void observeProviders( @WithAnnotations({Provider.class}) @Observes ProcessAnnotatedType<T> event, BeanManager beanManager) { AnnotatedType<T> annotatedType = event.getAnnotatedType(); addProvider(annotatedType.getJavaClass()); }
public <T> void observeResources( @WithAnnotations({Path.class}) @Observes ProcessAnnotatedType<T> event, BeanManager beanManager) { AnnotatedType<T> annotatedType = event.getAnnotatedType(); addResource(annotatedType.getJavaClass()); }
private <X> void registerMetrics(@Observes @WithAnnotations({Counted.class, Metered.class, Timed.class}) ProcessAnnotatedType<X> pat) { AnnotatedTypeDecorator<X> decoratedType = new AnnotatedTypeDecorator<>(pat.getAnnotatedType(), REGISTER_METRICS_BINDING); pat.setAnnotatedType(decoratedType); }
private <X> void registerGauges(@Observes @WithAnnotations({Gauge.class}) ProcessAnnotatedType<X> pat) { AnnotatedTypeDecorator<X> decoratedType = new AnnotatedTypeDecorator<>(pat.getAnnotatedType(), GAUGE_BEAN_BINDING); pat.setAnnotatedType(decoratedType); }
@SuppressWarnings("serial") public <T> void processAnnotatedType( @Observes @WithAnnotations(Path.class) ProcessAnnotatedType<T> processAnnotatedType) { AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>() .readFromType(processAnnotatedType.getAnnotatedType()) .addToClass(new AnnotationLiteral<Exceptionable>() {}); processAnnotatedType.setAnnotatedType(builder.create()); }
public <T> void onAnnotatedType(@Observes @WithAnnotations(Transactional.class) ProcessAnnotatedType<T> annotatedType) { AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>() .readFromType(annotatedType.getAnnotatedType()) .addToClass(AnnotationInstanceProvider.of(org.apache.deltaspike.jpa.api.transaction.Transactional.class)); annotatedType.setAnnotatedType(builder.create()); }