Search in sources :

Example 1 with Prioritized

use of javax.enterprise.inject.spi.Prioritized in project core by weld.

the class AfterBeanDiscoveryImpl method processBeanRegistration.

private <T> void processBeanRegistration(BeanRegistration registration, GlobalEnablementBuilder globalEnablementBuilder) {
    Bean<?> bean = registration.initBean();
    BeanManagerImpl beanManager = registration.initBeanManager();
    if (beanManager == null) {
        // Get the bean manager for beans added via ABD#addBean()
        beanManager = getOrCreateBeanDeployment(bean.getBeanClass()).getBeanManager();
    } else {
        // Also validate the bean produced by a builder
        ExternalBeanAttributesFactory.validateBeanAttributes(bean, getBeanManager());
        validateBean(bean);
    }
    // Custom beans (alternatives, interceptors, decorators) may also implement javax.enterprise.inject.spi.Prioritized
    Integer priority = (bean instanceof Prioritized) ? ((Prioritized) bean).getPriority() : null;
    // if added via WeldBeanConfigurator, there might be a priority specified as well
    if (priority == null && bean instanceof WeldBean) {
        priority = ((WeldBean) bean).getPriority();
    }
    if (bean instanceof Interceptor<?>) {
        beanManager.addInterceptor((Interceptor<?>) bean);
        if (priority != null) {
            globalEnablementBuilder.addInterceptor(bean.getBeanClass(), priority);
        }
    } else if (bean instanceof Decorator<?>) {
        beanManager.addDecorator(CustomDecoratorWrapper.of((Decorator<?>) bean, beanManager));
        if (priority != null) {
            globalEnablementBuilder.addDecorator(bean.getBeanClass(), priority);
        }
    } else {
        beanManager.addBean(bean);
        if (priority != null && bean.isAlternative()) {
            globalEnablementBuilder.addAlternative(bean.getBeanClass(), priority);
        }
    }
    containerLifecycleEvents.fireProcessBean(beanManager, bean, registration.extension);
}
Also used : WeldBean(org.jboss.weld.bean.WeldBean) Prioritized(javax.enterprise.inject.spi.Prioritized) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) Interceptor(javax.enterprise.inject.spi.Interceptor)

Example 2 with Prioritized

use of javax.enterprise.inject.spi.Prioritized in project core by weld.

the class JsonObjects method createBasicObserverJson.

@SuppressFBWarnings(value = "BC_VACUOUS_INSTANCEOF", justification = "WELD-2452, with CDI 1.2 API, this doesn't need to be true.")
static JsonObjectBuilder createBasicObserverJson(ObserverMethod<?> observerMethod, Probe probe) {
    JsonObjectBuilder observerBuilder = createSimpleObserverJson(observerMethod, probe);
    observerBuilder.add(RECEPTION, observerMethod.getReception().toString());
    observerBuilder.add(TX_PHASE, observerMethod.getTransactionPhase().toString());
    if (!observerMethod.getObservedQualifiers().isEmpty()) {
        JsonArrayBuilder qualifiersBuilder = Json.arrayBuilder();
        for (Annotation qualifier : observerMethod.getObservedQualifiers()) {
            qualifiersBuilder.add(qualifier.toString());
        }
        observerBuilder.add(QUALIFIERS, qualifiersBuilder);
    }
    if (observerMethod instanceof ObserverMethodImpl) {
        ObserverMethodImpl<?, ?> observerMethodImpl = (ObserverMethodImpl<?, ?>) observerMethod;
        observerBuilder.add(DECLARING_BEAN, createSimpleBeanJson(observerMethodImpl.getDeclaringBean(), probe));
    }
    if (isUnrestrictedProcessAnnotatedTypeObserver(observerMethod)) {
        observerBuilder.add(DESCRIPTION, WARNING_UNRESTRICTED_PAT_OBSERVER);
    }
    // WELD-2452 to be removed once WFLY is EE 8 certified
    if (observerMethod instanceof Prioritized) {
        // Every OM is now instance of Prioritized
        final int priority = Prioritized.class.cast(observerMethod).getPriority();
        observerBuilder.add(PRIORITY, priority);
        observerBuilder.add(PRIORITY_RANGE, Components.PriorityRange.of(priority).toString());
    }
    return observerBuilder;
}
Also used : Prioritized(javax.enterprise.inject.spi.Prioritized) ObserverMethodImpl(org.jboss.weld.event.ObserverMethodImpl) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder) Annotation(java.lang.annotation.Annotation) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Prioritized (javax.enterprise.inject.spi.Prioritized)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Annotation (java.lang.annotation.Annotation)1 Interceptor (javax.enterprise.inject.spi.Interceptor)1 WeldBean (org.jboss.weld.bean.WeldBean)1 ObserverMethodImpl (org.jboss.weld.event.ObserverMethodImpl)1 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)1 JsonArrayBuilder (org.jboss.weld.probe.Json.JsonArrayBuilder)1 JsonObjectBuilder (org.jboss.weld.probe.Json.JsonObjectBuilder)1