// This is a work around for CDI Uber Jar deployment. When Weld scans the classpath it pick up // RemoteCacheManager // (this is an implementation, not an interface, so it gets instantiated). As a result we get // duplicated classes // in CDI BeanManager. @SuppressWarnings("unused") <T extends RemoteCacheManager> void removeDuplicatedRemoteCacheManager( @Observes ProcessAnnotatedType<T> bean) { if (RemoteCacheManager.class .getCanonicalName() .equals(bean.getAnnotatedType().getJavaClass().getCanonicalName())) { LOGGER.info("removing duplicated RemoteCacheManager" + bean.getAnnotatedType()); bean.veto(); } }
public void vetoSpringBeans(@Observes ProcessAnnotatedType event) { if (!initialized) { init(); } if (!applicationContextFound) { return; } if (beanForClassExists(event.getAnnotatedType().getJavaClass())) { // Do not deploy this class to the CDI context. event.veto(); if (LOG.isDebugEnabled()) { LOG.debug("Vetoing " + event.getAnnotatedType().getJavaClass().getCanonicalName()); } } }
<T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) { AnnotatedType<T> annotatedType = pat.getAnnotatedType(); Class<T> type = annotatedType.getJavaClass(); // Determine if bean should be processed boolean veto = !context.filter.filter(type); if (!veto) { for (AbstractBean boundBean : context.injector.boundBeans) { Class<?> beanType = boundBean.getBeanClass(); if (beanType.isAssignableFrom(type)) { veto = true; break; } } } // if (veto) { pat.veto(); } }
private void processAnnotatedType(@Observes ProcessAnnotatedType<?> pat) { if (pat.getAnnotatedType().isAnnotationPresent(Vetoed.class)) { pat.veto(); } if (hasAnnotation(pat.getAnnotatedType(), Converter.class)) { converters.add(pat.getAnnotatedType().getJavaClass()); } if (hasAnnotation( pat.getAnnotatedType(), BeanInject.class, Consume.class, EndpointInject.class, Produce.class, PropertyInject.class)) { camelBeans.add(pat.getAnnotatedType()); } if (hasAnnotation(pat.getAnnotatedType(), Consume.class)) { eagerBeans.add(pat.getAnnotatedType()); } if (hasAnnotation(pat.getAnnotatedType(), ImportResource.class)) { resources.add(pat.getAnnotatedType().getAnnotation(ImportResource.class)); } }
/** * Register managed beans as Errai services * * @param event - * @param <T> - */ @SuppressWarnings("UnusedDeclaration") public <T> void observeResources(@Observes final ProcessAnnotatedType<T> event) { final AnnotatedType<T> type = event.getAnnotatedType(); for (final Annotation a : type.getJavaClass().getAnnotations()) { if (a.annotationType().isAnnotationPresent(Qualifier.class)) { beanQualifiers.put(a.annotationType().getName(), a); } } // services if (type.isAnnotationPresent(Service.class)) { log.debug("discovered Errai annotation on type: " + type); boolean isRpc = false; final Class<T> javaClass = type.getJavaClass(); for (final Class<?> intf : javaClass.getInterfaces()) { isRpc = intf.isAnnotationPresent(Remote.class); if (isRpc) { if (!managedTypes.getRemoteInterfaces().contains(intf)) { managedTypes.addRemoteInterface(intf); } } } if (!isRpc) { managedTypes.addServiceEndpoint(type); } } else { for (final AnnotatedMethod method : type.getMethods()) { if (method.isAnnotationPresent(Service.class)) { managedTypes.addServiceMethod(type, method); } } } // veto on client side implementations that contain CDI annotations // (i.e. @Observes) Otherwise Weld might try to invoke on them if (vetoClasses.contains(type.getJavaClass().getName()) || (type.getJavaClass().getPackage().getName().contains("client") && !type.getJavaClass().isInterface())) { event.veto(); } /** We must scan for Event consumer injection points to build the tables */ final Class clazz = type.getJavaClass(); for (final Field f : clazz.getDeclaredFields()) { if (f.isAnnotationPresent(Inject.class) && f.isAnnotationPresent(ObserverModel.class)) { processEventInjector(f.getType(), f.getGenericType(), f.getAnnotations()); } } for (final Method m : clazz.getDeclaredMethods()) { if (m.isAnnotationPresent(Inject.class) && m.isAnnotationPresent(ObserverModel.class)) { final Class<?>[] parameterTypes = m.getParameterTypes(); for (int i = 0, parameterTypesLength = parameterTypes.length; i < parameterTypesLength; i++) { final Class<?> parmType = parameterTypes[i]; processEventInjector( parmType, m.getGenericParameterTypes()[i], m.getParameterAnnotations()[i]); } } } for (final Constructor c : clazz.getDeclaredConstructors()) { if (c.isAnnotationPresent(Inject.class) && c.isAnnotationPresent(ObserverModel.class)) { final Class<?>[] parameterTypes = c.getParameterTypes(); for (int i = 0, parameterTypesLength = parameterTypes.length; i < parameterTypesLength; i++) { final Class<?> parmType = parameterTypes[i]; processEventInjector( parmType, c.getGenericParameterTypes()[i], c.getParameterAnnotations()[i]); } } } }
/** * Simply get rid of Solder {@link ELResolverProducer}. Cross-archive specialization is broken so * we cannot use that. */ public void vetoSolderElResolverProducer( @Observes ProcessAnnotatedType<ELResolverProducer> event) { if (event.getAnnotatedType().getJavaClass().equals(ELResolverProducer.class)) { event.veto(); } }