javax.enterprise.inject.spi.ProcessBean Java Examples

The following examples show how to use javax.enterprise.inject.spi.ProcessBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Cxfs.java    From openwebbeans-meecrowave with Apache License 2.0 6 votes vote down vote up
@Override
public <T> void collect(@Observes final ProcessBean<T> event) {
    if (!event.getAnnotated().isAnnotationPresent(Path.class) && AnnotatedType.class.isInstance(event.getAnnotated())) {
        final AnnotatedType<?> type = AnnotatedType.class.cast(event.getAnnotated());
        // note: should we use Annotated for interfaces as well?
        if (type.getTypeClosure().stream()
                .filter(it -> Class.class.isInstance(it) && Class.class.cast(it).isInterface())
                .map(Class.class::cast)
                .anyMatch(c -> c.isAnnotationPresent(Path.class))) {
            try {
                List.class.cast(serviceBeans.get(this)).add(event.getBean());
                return;
            } catch (final IllegalAccessException e) {
                new org.apache.meecrowave.logging.tomcat.LogFacade(Cxfs.class.getName())
                        .error(e.getMessage(), e);
            }
        }
    }
    super.collect(event);
}
 
Example #2
Source File: HessianExtension.java    From tomee with Apache License 2.0 6 votes vote down vote up
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));
        }
    }
}
 
Example #3
Source File: JAXRSCdiResourceExtension.java    From cxf with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> void collect(@Observes final ProcessBean< T > event) {
    if (event.getAnnotated().isAnnotationPresent(ApplicationPath.class)) {
        applicationBeans.add(event.getBean());
    } else if (event.getAnnotated().isAnnotationPresent(Path.class)) {
        serviceBeans.add(event.getBean());
    } else if (event.getAnnotated().isAnnotationPresent(Provider.class)) {
        providerBeans.add(event.getBean());
    } else if (event.getBean().getTypes().contains(javax.ws.rs.core.Feature.class)) {
        providerBeans.add(event.getBean());
    } else if (event.getBean().getTypes().contains(Feature.class)) {
        featureBeans.add((Bean< ? extends Feature >)event.getBean());
    } else if (CdiBusBean.CXF.equals(event.getBean().getName())
            && Bus.class.isAssignableFrom(event.getBean().getBeanClass())) {
        hasBus = true;
    } else if (event.getBean().getQualifiers().contains(DEFAULT)) {
        event.getBean().getTypes().stream()
            .filter(e -> Object.class != e && InjectionUtils.STANDARD_CONTEXT_CLASSES.contains(e.getTypeName()))
            .findFirst()
            .ifPresent(type -> existingStandardClasses.add(type.getTypeName()));
    }
}
 
Example #4
Source File: ExtraJCacheExtension.java    From jcache-cdi with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #5
Source File: ConfigurationExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
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());
    }
}
 
Example #6
Source File: ConfigurationExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public void findFilters(@Observes ProcessBean<? extends ConfigFilter> filter)
{
    if (!filter.getAnnotated().isAnnotationPresent(Filter.class))
    {
        return;
    }
    cdiFilters.add(filter.getBean());
}
 
Example #7
Source File: ConfigurationExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public void findSources(@Observes ProcessBean<? extends ConfigSource> source)
{
    if (!source.getAnnotated().isAnnotationPresent(Source.class))
    {
        return;
    }
    cdiSources.add(source.getBean());
}
 
Example #8
Source File: ExceptionControlExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
            }
        }
    }
}
 
Example #9
Source File: ExtraJCacheExtension.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #10
Source File: TomEEOpenAPIExtension.java    From tomee with Apache License 2.0 5 votes vote down vote up
<T> void findEndpointsAndApplication(@Observes final ProcessBean<T> event) {
    final String typeName = event.getAnnotated().getBaseType().getTypeName();
    if (classes == null && !skipScan && event.getAnnotated().isAnnotationPresent(Path.class) &&
            !event.getAnnotated().isAnnotationPresent(RegisterRestClient.class) &&
            !typeName.startsWith("org.apache.geronimo.microprofile.openapi.") &&
            (packages == null || packages.stream().anyMatch(typeName::startsWith))) {
        endpoints.add(event.getBean());
    }
}
 
Example #11
Source File: JAXRSCdiResourceExtension.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts relevant beans from producers.
 * @param event process bean event
 * @param baseType base type of the producer
 */
private <T> void processProducer(final ProcessBean<T> event, final Type baseType) {
    if (baseType instanceof Class<?>) {
        final Class<?> clazz = (Class<?>)baseType;
        if (clazz.isAnnotationPresent(Path.class)) {
            serviceBeans.add(event.getBean());
        } else if (clazz.isAnnotationPresent(Provider.class)) {
            providerBeans.add(event.getBean());
        } else if (clazz.isAnnotationPresent(ApplicationPath.class)) {
            applicationBeans.add(event.getBean());
        } 
    }
}
 
Example #12
Source File: MPConfigExtension.java    From microprofile-jwt-auth with Apache License 2.0 5 votes vote down vote up
void doProcessBean(@Observes ProcessBean pb) {
    System.out.printf("pb: %s, class:%s, types:%s\n", pb.getAnnotated(), pb.getBean().getBeanClass(), pb.getBean().getTypes());
    if (pb.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
        System.out.printf("\t+++ has ConfigProperty annotation\n");
        //pba.setBeanAttributes(new ConverterBeanAttribute(pba.getBeanAttributes(), types));
    }
}
 
Example #13
Source File: JtaExtension.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
void findJtaComponents(@Observes final ProcessBean<?> bean) {
    if (!hasManager && bean.getBean().getTypes().contains(TransactionManager.class)) {
        hasManager = true;
    }
    if (!hasRegistry && bean.getBean().getTypes().contains(TransactionSynchronizationRegistry.class)) {
        hasRegistry = true;
    }
}
 
Example #14
Source File: JpaExtension.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
void collectEntityManagerInjections(@Observes final ProcessBean<?> bean) {
    final Map<UnitKey, EntityManagerBean> beans = bean.getBean().getInjectionPoints().stream()
            .filter(i -> i.getAnnotated().isAnnotationPresent(Unit.class))
            .map(i -> i.getAnnotated().getAnnotation(Unit.class))
            .collect(toMap(u -> new UnitKey(u.name(), u.synchronization()), unit -> new EntityManagerBean(entityManagerContext, unit.name(), unit.synchronization())));
    entityManagerBeans.putAll(beans);
}
 
Example #15
Source File: ActiveMQCDILogger.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@LogMessage
@Message(id = 571001, value = "Discovered client configuration class {0}", format = Message.Format.MESSAGE_FORMAT)
void discoveredClientConfiguration(ProcessBean<?> pb);
 
Example #16
Source File: EagerExtension.java    From hawkular-metrics with Apache License 2.0 4 votes vote down vote up
public <T> void collect(@Observes ProcessBean<T> event) {
    if (event.getAnnotated().isAnnotationPresent(Eager.class) &&
        event.getAnnotated().isAnnotationPresent(ApplicationScoped.class)) {
        eagerBeansList.add(event.getBean());
    }
}
 
Example #17
Source File: ActiveMQCDILogger.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@LogMessage
@Message(id = 571000, value = "Discovered configuration class {0}", format = Message.Format.MESSAGE_FORMAT)
void discoveredConfiguration(ProcessBean<?> pb);
 
Example #18
Source File: ArtemisExtension.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
void foundEmbeddedConfig(@Observes ProcessBean<?> processBean) {
   if (processBean.getBean().getTypes().contains(Configuration.class)) {
      ActiveMQCDILogger.LOGGER.discoveredClientConfiguration(processBean);
      foundEmbeddedConfig = true;
   }
}
 
Example #19
Source File: FlywayExtension.java    From hammock with Apache License 2.0 4 votes vote down vote up
public void findFlywayBean(@Observes ProcessBean<Flyway> flywayProcessBean) {
   this.foundFlywayBean = true;
}
 
Example #20
Source File: ArtemisExtension.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
void foundClientConfig(@Observes ProcessBean<?> processBean) {
   if (processBean.getBean().getTypes().contains(ArtemisClientConfiguration.class)) {
      ActiveMQCDILogger.LOGGER.discoveredConfiguration(processBean);
      foundConfiguration = true;
   }
}
 
Example #21
Source File: EagerExtension.java    From hawkular-apm with Apache License 2.0 4 votes vote down vote up
public <T> void collect(@Observes ProcessBean<T> event) {
    if (event.getAnnotated().isAnnotationPresent(Eager.class) &&
            event.getAnnotated().isAnnotationPresent(ApplicationScoped.class)) {
        eagerBeansList.add(event.getBean());
    }
}
 
Example #22
Source File: JAXWSCdiExtension.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
public <T> void collect(@Observes final ProcessBean<T> processBean) {
    if (active && processBean.getAnnotated().isAnnotationPresent(marker)) {
        serviceBeans.add(processBean.getBean());
    }
}
 
Example #23
Source File: JAXWSCdiExtension.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
public <T> void collect(@Observes final ProcessBean<T> processBean) {
    impl.collect(processBean);
}
 
Example #24
Source File: JpaExtension.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
void collectEntityManagers(@Observes final ProcessBean<?> bean) {
    if (bean.getBean().getTypes().contains(PersistenceUnitInfoBuilder.class)) {
        unitBuilders.add(bean.getBean());
    }
}