use of org.jboss.as.weld.injection.WeldInjectionContextInterceptor in project wildfly by wildfly.
the class WeldComponentIntegrationProcessor method addWeldIntegration.
/**
* As the weld based instantiator needs access to the bean manager it is installed as a service.
*/
private void addWeldIntegration(final Iterable<ComponentIntegrator> componentIntegrators, final ComponentInterceptorSupport componentInterceptorSupport, final ServiceTarget target, final ComponentConfiguration configuration, final ComponentDescription description, final Class<?> componentClass, final String beanName, final ServiceName weldServiceName, final ServiceName weldStartService, final ServiceName beanManagerService, final Set<Class<?>> interceptorClasses, final ClassLoader classLoader, final String beanDeploymentArchiveId) {
final ServiceName serviceName = configuration.getComponentDescription().getServiceName().append("WeldInstantiator");
final ServiceBuilder<?> builder = target.addService(serviceName);
builder.requires(weldStartService);
configuration.setInstanceFactory(WeldManagedReferenceFactory.INSTANCE);
configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) throws DeploymentUnitProcessingException {
serviceBuilder.requires(serviceName);
}
});
boolean isComponentIntegrationPerformed = false;
for (ComponentIntegrator componentIntegrator : componentIntegrators) {
Supplier<ServiceName> bindingServiceNameSupplier = () -> {
if (componentInterceptorSupport == null) {
throw WeldLogger.DEPLOYMENT_LOGGER.componentInterceptorSupportNotAvailable(componentClass);
}
return addWeldInterceptorBindingService(target, configuration, componentClass, beanName, weldServiceName, weldStartService, beanDeploymentArchiveId, componentInterceptorSupport);
};
DefaultInterceptorIntegrationAction integrationAction = (bindingServiceName) -> {
if (componentInterceptorSupport == null) {
throw WeldLogger.DEPLOYMENT_LOGGER.componentInterceptorSupportNotAvailable(componentClass);
}
addJsr299BindingsCreateInterceptor(configuration, description, beanName, weldServiceName, builder, bindingServiceName, componentInterceptorSupport);
addCommonLifecycleInterceptionSupport(configuration, builder, bindingServiceName, beanManagerService, componentInterceptorSupport);
configuration.addComponentInterceptor(new UserInterceptorFactory(factory(InterceptionType.AROUND_INVOKE, builder, bindingServiceName, componentInterceptorSupport), factory(InterceptionType.AROUND_TIMEOUT, builder, bindingServiceName, componentInterceptorSupport)), InterceptorOrder.Component.CDI_INTERCEPTORS, false);
};
if (componentIntegrator.integrate(beanManagerService, configuration, description, builder, bindingServiceNameSupplier, integrationAction, componentInterceptorSupport)) {
isComponentIntegrationPerformed = true;
break;
}
}
final Supplier<WeldBootstrapService> weldContainerSupplier = builder.requires(weldServiceName);
final WeldComponentService weldComponentService = new WeldComponentService(weldContainerSupplier, componentClass, beanName, interceptorClasses, classLoader, beanDeploymentArchiveId, description.isCDIInterceptorEnabled(), description, isComponentWithView(description, componentIntegrators));
builder.setInstance(weldComponentService);
if (!isComponentIntegrationPerformed) {
// otherwise they will be called twice
description.setIgnoreLifecycleInterceptors(true);
// for components with no view register interceptors that delegate to InjectionTarget lifecycle methods to trigger lifecycle interception
configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new AbstractInjectionTargetDelegatingInterceptor() {
@Override
protected void run(Object instance) {
weldComponentService.getInjectionTarget().postConstruct(instance);
}
}), InterceptorOrder.ComponentPostConstruct.CDI_INTERCEPTORS);
configuration.addPreDestroyInterceptor(new ImmediateInterceptorFactory(new AbstractInjectionTargetDelegatingInterceptor() {
@Override
protected void run(Object instance) {
weldComponentService.getInjectionTarget().preDestroy(instance);
}
}), InterceptorOrder.ComponentPreDestroy.CDI_INTERCEPTORS);
}
builder.install();
configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new WeldInjectionContextInterceptor(weldComponentService)), InterceptorOrder.ComponentPostConstruct.WELD_INJECTION_CONTEXT_INTERCEPTOR);
configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new WeldInterceptorInjectionInterceptor(interceptorClasses)), InterceptorOrder.ComponentPostConstruct.INTERCEPTOR_WELD_INJECTION);
configuration.addPostConstructInterceptor(WeldInjectionInterceptor.FACTORY, InterceptorOrder.ComponentPostConstruct.COMPONENT_WELD_INJECTION);
}
Aggregations