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);
}
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;
}
Aggregations