Refine search
/** * 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; } } } }
@SuppressWarnings("unused") private void processAnnotatedType(@Observes final AnnotatedType<?> annotatedType = processAnnotatedType.getAnnotatedType();
private boolean isBeanWithManagedBeanAnnotation(ProcessAnnotatedType processAnnotatedType) { Class<?> beanClass = processAnnotatedType.getAnnotatedType().getJavaClass(); return beanClass.isAnnotationPresent(ManagedBean.class); }
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)); }); }
/** * 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 ); } }
private boolean isBeanWithManagedBeanAnnotation(ProcessAnnotatedType processAnnotatedType) { Class<?> beanClass = processAnnotatedType.getAnnotatedType().getJavaClass(); return beanClass.isAnnotationPresent(ManagedBean.class); }
private void registerMetrics(@Observes @WithAnnotations({Counted.class, Metered.class, Timed.class}) ProcessAnnotatedType<?> pat) { AnnotatedType<?> type = pat.getAnnotatedType(); Interceptor annot = type.getAnnotation(Interceptor.class); if (annot != null) { LOGGER.log(Level.FINE, () -> "### Processing annotations for " + pat.getAnnotatedType().getJavaClass().getName()); Class<?> clazz = configurator.getAnnotated().getJavaClass();
public void observeEagleType(@Observes ProcessAnnotatedType<Eagle> event) { final AnnotatedType<Eagle> annotatedType = event.getAnnotatedType(); event.setAnnotatedType(new ForwardingAnnotatedType<Eagle>() { @Override public AnnotatedType<Eagle> delegate() { return annotatedType; } }); } }
private Class<? extends Annotation> getJsf2ScopeAnnotation(ProcessAnnotatedType processAnnotatedType) { for (Class<? extends Annotation> currentJsfScope : this.mappedJsfScopes.keySet()) { if (processAnnotatedType.getAnnotatedType().getJavaClass().isAnnotationPresent(currentJsfScope)) { return currentJsfScope; } } return null; }
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)); } }
void detectInterfaces(@Observes ProcessAnnotatedType<?> event, BeanManager beanManager) { AnnotatedType<?> type = event.getAnnotatedType(); if (type.isAnnotationPresent(MessageBundle.class)) { messageBundleTypes.add(type); } }
private Class<? extends Annotation> getJsf2ScopeAnnotation(ProcessAnnotatedType processAnnotatedType) { for (Class<? extends Annotation> currentJsfScope : this.mappedJsfScopes.keySet()) { if (processAnnotatedType.getAnnotatedType().getJavaClass().isAnnotationPresent(currentJsfScope)) { return currentJsfScope; } } return null; }
/** * 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()); } }
<T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> event, BeanManager beanManager) { FacesConfig facesConfig = event.getAnnotatedType().getAnnotation(FacesConfig.class); if (facesConfig != null && facesConfig.version() == FacesConfig.Version.JSF_2_3) { registerCdiProducers = true; } }
private void vetoBean(ProcessAnnotatedType processAnnotatedType) { if(this.logger.isLoggable(Level.FINER)) { this.logger.finer(processAnnotatedType.getAnnotatedType().getJavaClass().getName() + " won't be used as CDI bean"); } processAnnotatedType.veto(); }
/** * 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()); } }
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 void checkExpressionActivated(ProcessAnnotatedType<?> processAnnotatedType) { Class<?> annotatedClass = processAnnotatedType.getAnnotatedType().getJavaClass(); if(!ActivationUtils.isActivated(annotatedClass, PropertyExpressionInterpreter.class)) { processAnnotatedType.veto(); LOG.finer("Expression Veto for bean with type: " + processAnnotatedType.getAnnotatedType().getJavaClass() ); } }
/** * Set a default scope for each CDI bean which is a JAX-RS Application subclass. * * @param <T> type * @param event event * @param beanManager bean manager */ public <T extends Application> void observeApplications(@Observes ProcessAnnotatedType<T> event, BeanManager beanManager) { setBeanManager(beanManager); AnnotatedType<T> annotatedType = event.getAnnotatedType(); if(!isSessionBean(annotatedType)) { LogMessages.LOGGER.debug(Messages.MESSAGES.discoveredCDIBeanApplication(annotatedType.getJavaClass().getCanonicalName())); event.setAnnotatedType(wrapAnnotatedType(annotatedType, applicationScopedLiteral)); } }
public <T> void replaceAnnotations(@Observes ProcessAnnotatedType<T> pat) { LOG.log(FINE, "processing type {0}", pat); pat.setAnnotatedType(new AnnotationReplacementBuilder<>(pat.getAnnotatedType()).invoke()); updateDecoratedTypes(pat); }