/** * 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]); } } } }