/** * Process a bean. Checks the bean for @Service annotation and if it is found, verifies * the bean scope and marks it for export as service at a later stage. * * @param event The process bean event. See CDI specification * @param <T> The type of the bean */ public <T> void processBean(@Observes ProcessBean<T> event) { Bean<T> bean = event.getBean(); Service service = BeanExporter.getServiceDefinition(bean); if (service == null) { return; } // Check the scope. Must be global. Class<? extends Annotation> scope = bean.getScope(); if (!scope.equals(ComponentScoped.class) && !scope.equals(ApplicationScoped.class)) { // Set an error. event.addDefinitionError(new Exception("beans annotated with @Service must have a global scope")); return; } // Mark the bean as exportable. exportedBeans.put(bean, null); }
protected <X> void findHessianWebServices(final @Observes ProcessBean<X> processBean) { if (ProcessSessionBean.class.isInstance(processBean)) { return; } final Bean<X> bean = processBean.getBean(); final Class<?> beanClass = bean.getBeanClass(); for (final Class<?> itf : beanClass.getInterfaces()) { final Hessian hessian = itf.getAnnotation(Hessian.class); final String key = "openejb.hessian." + beanClass.getName() + "_" + itf.getName() + ".path"; final String path = appInfo.properties.getProperty(key, SystemInstance.get().getProperty(key)); if (hessian != null || path != null) { toDeploy.add(new Deployment(itf, path, bean)); } } }
private void beans(@Observes ProcessBean<?> pb, BeanManager manager) { cdiBeans.add(pb.getBean()); // Lookup for CDI event endpoint injection points pb.getBean().getInjectionPoints().stream() .filter(ip -> CdiEventEndpoint.class.equals(getRawType(ip.getType()))) .forEach(ip -> { Type type = ip.getType() instanceof ParameterizedType ? ((ParameterizedType) ip.getType()).getActualTypeArguments()[0] : Object.class; String uri = eventEndpointUri(type, ip.getQualifiers()); cdiEventEndpoints.put(uri, new CdiEventEndpoint<>(uri, type, ip.getQualifiers(), manager)); }); }
public <A> void processBean(final @Observes ProcessBean<A> processBeanEvent) { if (!ACTIVATED) { return; } if (cacheManagerFound && cacheProviderFound) { return; } final Bean<A> bean = processBeanEvent.getBean(); if (CacheManagerBean.class.isInstance(bean) || CacheProviderBean.class.isInstance(bean)) { return; } if (!cacheManagerFound) { cacheManagerFound = bean.getTypes().contains(CacheManager.class); } if (!cacheProviderFound) { cacheProviderFound = bean.getTypes().contains(CachingProvider.class); } }
public <T> void collect(@Observes ProcessBean<T> event) { if (event.getAnnotated().isAnnotationPresent(Autoload.class) && event.getAnnotated().isAnnotationPresent(ApplicationScoped.class)) { autoloadBeanList.add(event.getBean()); log.info(String.format("Adding %s to the list of beans to autostart.", event.getBean().getBeanClass().toString())); } }
public <T> void collect(@Observes ProcessBean<T> event) { if (event.getAnnotated().isAnnotationPresent(Eager.class) && event.getAnnotated().isAnnotationPresent(ApplicationScoped.class)) { eagerBeansList.add(event.getBean()); } }
<X> void processBean(@Observes ProcessBean<X> event) { if (event.getAnnotated().isAnnotationPresent(Startup.class) && event.getAnnotated().isAnnotationPresent(SingletonService.class)) { System.out.println("CDI: Found @Startup in "+event.getBean().getName()); startupBeans.add(event.getBean()); } }
/** * The container fires an event for each enabled bean, interceptor or * decorator deployed in a bean archive, before registering the * javax.enterprise.inject.spi.Bean object. * * Scan beans for {@link Startup} annotation. * * @param beanEvent * event */ <T> void processBean(@Observes ProcessBean<T> beanEvent) { this.log.info("{} is processing Bean before registering the Bean object", beanEvent .getAnnotated().getClass().getName()); if (beanEvent.getAnnotated().isAnnotationPresent(Startup.class) && beanEvent.getAnnotated().isAnnotationPresent(ApplicationScoped.class)) { this.startupBeans.add(beanEvent.getBean()); } }
/** * Listener to ProcessBean event to locate handlers. * * @param processBean current {@link AnnotatedType} * @param beanManager Activated Bean Manager * @throws TypeNotPresentException if any of the actual type arguments refers to a non-existent type declaration * when trying to obtain the actual type arguments from a * {@link java.lang.reflect.ParameterizedType} * @throws java.lang.reflect.MalformedParameterizedTypeException * if any of the actual type parameters refer to a parameterized type that cannot * be instantiated for any reason when trying to obtain the actual type arguments * from a {@link java.lang.reflect.ParameterizedType} */ @SuppressWarnings("UnusedDeclaration") public <T> void findHandlers(@Observes final ProcessBean<?> processBean, final BeanManager beanManager) { if (!isActivated) { return; } if (processBean.getBean() instanceof Interceptor || processBean.getBean() instanceof Decorator || !(processBean.getAnnotated() instanceof AnnotatedType)) { return; } AnnotatedType annotatedType = (AnnotatedType)processBean.getAnnotated(); if (annotatedType.getJavaClass().isAnnotationPresent(ExceptionHandler.class)) { final Set<AnnotatedMethod<? super T>> methods = annotatedType.getMethods(); for (AnnotatedMethod<? super T> method : methods) { if (HandlerMethodImpl.isHandler(method)) { if (method.getJavaMember().getExceptionTypes().length != 0) { processBean.addDefinitionError(new IllegalArgumentException( String.format("Handler method %s must not throw exceptions", method.getJavaMember()))); } //beanManager won't be stored in the instance -> no issue with wls12c registerHandlerMethod(new HandlerMethodImpl(processBean.getBean(), method, beanManager)); } } } }
public void findSources(@Observes ProcessBean<? extends ConfigSource> source) { if (!source.getAnnotated().isAnnotationPresent(Source.class)) { return; } cdiSources.add(source.getBean()); }
public void findFilters(@Observes ProcessBean<? extends ConfigFilter> filter) { if (!filter.getAnnotated().isAnnotationPresent(Filter.class)) { return; } cdiFilters.add(filter.getBean()); }
public void collectDynamicTypes(@Observes ProcessBean<?> processBean) { for (final InjectionPoint ip : processBean.getBean().getInjectionPoints()) { final ConfigProperty annotation = ip.getAnnotated().getAnnotation(ConfigProperty.class); if (annotation == null || annotation.converter() == ConfigResolver.Converter.class) { continue; } dynamicConfigTypes.add(ip.getType()); } }
<T> void processBean(@Observes ProcessBean<T> pb) { logger.info("finished the scanning process"); processBean++; }
void foundClientConfig(@Observes ProcessBean<?> processBean) { if (processBean.getBean().getTypes().contains(ArtemisClientConfiguration.class)) { ActiveMQCDILogger.LOGGER.discoveredConfiguration(processBean); foundConfiguration = true; } }
void foundEmbeddedConfig(@Observes ProcessBean<?> processBean) { if (processBean.getBean().getTypes().contains(Configuration.class)) { ActiveMQCDILogger.LOGGER.discoveredClientConfiguration(processBean); foundEmbeddedConfig = true; } }
@LogMessage @Message(id = 571000, value = "Discovered configuration class {0}", format = Message.Format.MESSAGE_FORMAT) void discoveredConfiguration(ProcessBean<?> pb);
@LogMessage @Message(id = 571001, value = "Discovered client configuration class {0}", format = Message.Format.MESSAGE_FORMAT) void discoveredClientConfiguration(ProcessBean<?> pb);
public <T> void processBean(@Observes ProcessBean<T> event) { if (event.getAnnotated().isAnnotationPresent(ComponentScoped.class)) { // Add this one. theseBeans.add(event.getBean()); } }
<X> void processBean(@Observes ProcessBean<X> event) { if (event.getAnnotated().isAnnotationPresent(Startup.class) && event.getAnnotated().isAnnotationPresent(ApplicationScoped.class)) { startupBeans.add(event.getBean()); } }
<X> void logLifecycleEvent(@Observes ProcessBean<X> event) { LOGGER.info("ProcessBean: bean=" + event.getBean()); }
public void findFlywayBean(@Observes ProcessBean<Flyway> flywayProcessBean) { this.foundFlywayBean = true; }
/** * <p>Collect all beans that have the {@link com.acme.trains.Eager @Eager} and {@link javax.enterprise.context.ApplicationScoped @ApplicationScoped} * annotation and save them for startup.</p> * * @param event Event represents and contains the found CDI bean during initial scanning. * @param <T> Class of the found bean. * * @see com.acme.trains.Eager * @see javax.enterprise.context.ApplicationScoped */ public <T> void collect(@Observes ProcessBean<T> event) { if (event.getAnnotated().isAnnotationPresent(Eager.class) && event.getAnnotated().isAnnotationPresent(ApplicationScoped.class)) { eagerBeansList.add(event.getBean()); } }