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; } } } }
void registerHasAllRoles(@Observes @WithAnnotations(HasAllRoles.class) ProcessAnnotatedType<?> pat) { if (pat.getAnnotatedType().isAnnotationPresent(HasAllRoles.class)) { HasAllRoles hasAllRoles = pat.getAnnotatedType().getAnnotation(HasAllRoles.class); pat.configureAnnotatedType().methods().forEach(amc -> { amc.add(hasAllRoles); amc.add(Secured.INSTANCE); }); } else { pat.configureAnnotatedType() .filterMethods(m -> m.isAnnotationPresent(HasAllRoles.class)) .forEach(amc -> { amc.add(Secured.INSTANCE); }); } }
private void camelAnnotatedTypes(@Observes @WithAnnotations(PropertyInject.class) ProcessAnnotatedType<?> pat) { camelBeans.add(pat.getAnnotatedType()); }
public void observeAnything(@WithAnnotations(RequestScoped.class) @Observes String event) { }
@SuppressWarnings({ "unchecked" }) void processHandlerAnnotatedType(@Observes @WithAnnotations({ WebRoute.class, WebRoutes.class }) ProcessAnnotatedType<?> event, BeanManager beanManager) { AnnotatedType<?> annotatedType = event.getAnnotatedType(); if (isWebRoute(annotatedType) && isRouteHandler(annotatedType)) { LOGGER.debug("Route handler found: {0}", annotatedType); for (AnnotatedMethod<?> method : annotatedType.getMethods()) { WebRoute[] webRoutes = getWebRoutes(method); if (webRoutes.length > 0) { event.configureAnnotatedType().methods().forEach(m -> { Id id = routes.get(m.getAnnotated().getJavaMember().toGenericString()); if (id != null) {
<T> void processAnnotatedType(@Observes @WithAnnotations(Veto.class) ProcessAnnotatedType<T> pat) { pat.veto(); }
protected Set<Class<? extends Annotation>> initRequiredTypeAnnotations(EnhancedAnnotatedMethod<T, ? super X> observer) { EnhancedAnnotatedParameter<?, ? super X> eventParameter = observer.getEnhancedParameters(Observes.class).get(0); WithAnnotations annotation = eventParameter.getAnnotation(WithAnnotations.class); if (annotation != null) { return ImmutableSet.of(annotation.value()); } return Collections.emptySet(); }
void registerRolesAllowed(@Observes @WithAnnotations(RolesAllowed.class) ProcessAnnotatedType<?> pat) { if (pat.getAnnotatedType().isAnnotationPresent(RolesAllowed.class)) { RolesAllowed roles = pat.getAnnotatedType().getAnnotation(RolesAllowed.class); pat.configureAnnotatedType().methods().forEach(amc -> { amc.add(roles); amc.add(Secured.INSTANCE); }); } else { pat.configureAnnotatedType() .filterMethods(m -> m.isAnnotationPresent(RolesAllowed.class)) .forEach(amc -> { amc.add(Secured.INSTANCE); }); } } }
private void camelAnnotatedTypes(@Observes @WithAnnotations(PropertyInject.class) ProcessAnnotatedType<?> pat) { camelBeans.add(pat.getAnnotatedType()); }
public void observeAfterBeanDiscovery(@WithAnnotations(Model.class) @Observes AfterBeanDiscovery event) { }
protected Set<Class<? extends Annotation>> initRequiredTypeAnnotations(EnhancedAnnotatedMethod<T, ? super X> observer) { EnhancedAnnotatedParameter<?, ? super X> eventParameter = getEventParameter(observer); WithAnnotations annotation = eventParameter.getAnnotation(WithAnnotations.class); if (annotation != null) { return ImmutableSet.<Class<? extends Annotation>>of(annotation.value()); } return Collections.emptySet(); }
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)); }); }
void registerLoggedIn(@Observes @WithAnnotations(LoggedIn.class) ProcessAnnotatedType<?> pat) { if (pat.getAnnotatedType().isAnnotationPresent(LoggedIn.class)) { pat.configureAnnotatedType().methods().forEach(amc -> { amc.add(LoggedIn.INSTANCE); amc.add(Secured.INSTANCE); }); } else { pat.configureAnnotatedType() .filterMethods(m -> m.isAnnotationPresent(LoggedIn.class)) .forEach(amc -> { amc.add(Secured.INSTANCE); }); } }
public void processAnnotatedType( @Observes @WithAnnotations({ Context.class, ApplicationPath.class, HeaderParam.class, QueryParam.class, FormParam.class, MatrixParam.class, BeanParam.class, PathParam.class}) ProcessAnnotatedType<?> processAnnotatedType, BeanManager beanManager) { beanManager.getExtension(CdiComponentProvider.class) .processAnnotatedType(processAnnotatedType); }
protected Set<Class<? extends Annotation>> initRequiredTypeAnnotations(EnhancedAnnotatedMethod<T, ? super X> observer) { EnhancedAnnotatedParameter<?, ? super X> eventParameter = getEventParameter(observer); WithAnnotations annotation = eventParameter.getAnnotation(WithAnnotations.class); if (annotation != null) { return ImmutableSet.<Class<? extends Annotation>>of(annotation.value()); } return Collections.emptySet(); }
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) { return; LOGGER.log(Level.FINE, () -> "### Processing annotations for " + pat.getAnnotatedType().getJavaClass().getName()); AnnotatedTypeConfigurator<?> configurator = pat.configureAnnotatedType(); Class<?> clazz = configurator.getAnnotated().getJavaClass();
protected Set<Class<? extends Annotation>> initRequiredTypeAnnotations(EnhancedAnnotatedMethod<T, ? super X> observer) { EnhancedAnnotatedParameter<?, ? super X> eventParameter = getEventParameter(observer); WithAnnotations annotation = eventParameter.getAnnotation(WithAnnotations.class); if (annotation != null) { return ImmutableSet.<Class<? extends Annotation>>of(annotation.value()); } return Collections.emptySet(); }
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)); } }
protected Set<Class<? extends Annotation>> initRequiredTypeAnnotations(EnhancedAnnotatedMethod<T, ? super X> observer) { EnhancedAnnotatedParameter<?, ? super X> eventParameter = getEventParameter(observer); WithAnnotations annotation = eventParameter.getAnnotation(WithAnnotations.class); if (annotation != null) { return ImmutableSet.<Class<? extends Annotation>>of(annotation.value()); } return Collections.emptySet(); }
/** * 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()); } }