Search in sources :

Example 6 with WeldBootstrapService

use of org.jboss.as.weld.WeldBootstrapService in project wildfly by wildfly.

the class WeldBeanManagerServiceProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final DeploymentUnit topLevelDeployment = Utils.getRootDeploymentUnit(deploymentUnit);
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(topLevelDeployment)) {
        return;
    }
    BeanDeploymentArchiveImpl rootBda = deploymentUnit.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE);
    if (rootBda == null) {
        // this archive is not actually a bean archive.
        // then use the top level root bda
        rootBda = topLevelDeployment.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE);
    }
    if (rootBda == null) {
        WeldLogger.DEPLOYMENT_LOGGER.couldNotFindBeanManagerForDeployment(deploymentUnit.getName());
        return;
    }
    final ServiceName weldServiceName = topLevelDeployment.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
    // add the BeanManager service
    final ServiceName beanManagerServiceName = BeanManagerService.serviceName(deploymentUnit);
    final ServiceBuilder<?> builder = serviceTarget.addService(beanManagerServiceName);
    final Consumer<BeanManager> beanManagerConsumer = builder.provides(beanManagerServiceName);
    final Supplier<WeldBootstrapService> weldContainerSupplier = builder.requires(weldServiceName);
    builder.setInstance(new BeanManagerService(rootBda.getId(), beanManagerConsumer, weldContainerSupplier));
    builder.install();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
        return;
    }
    // hack to set up a java:comp binding for jar deployments as well as wars
    if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit) || deploymentUnit.getName().endsWith(".jar")) {
        // bind the bean manager to JNDI
        final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(moduleDescription.getApplicationName(), moduleDescription.getModuleName());
        bindBeanManager(deploymentUnit, serviceTarget, beanManagerServiceName, moduleContextServiceName);
    }
    // bind the bm into java:comp for all components that require it
    for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
        if (component.getNamingMode() == ComponentNamingMode.CREATE) {
            final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(moduleDescription.getApplicationName(), moduleDescription.getModuleName(), component.getComponentName());
            bindBeanManager(deploymentUnit, serviceTarget, beanManagerServiceName, compContextServiceName);
        }
    }
    SetupAction action = new WeldContextSetup();
    deploymentUnit.putAttachment(ATTACHMENT_KEY, action);
    deploymentUnit.addToAttachmentList(Attachments.SETUP_ACTIONS, action);
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) BeanDeploymentArchiveImpl(org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl) WeldContextSetup(org.jboss.as.weld.arquillian.WeldContextSetup) ServiceTarget(org.jboss.msc.service.ServiceTarget) SetupAction(org.jboss.as.server.deployment.SetupAction) BeanManagerService(org.jboss.as.weld.services.BeanManagerService) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) BeanManager(javax.enterprise.inject.spi.BeanManager)

Aggregations

WeldBootstrapService (org.jboss.as.weld.WeldBootstrapService)6 ServiceName (org.jboss.msc.service.ServiceName)5 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)4 ServiceTarget (org.jboss.msc.service.ServiceTarget)4 Module (org.jboss.modules.Module)3 InterceptorBindings (org.jboss.weld.ejb.spi.InterceptorBindings)3 HashSet (java.util.HashSet)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 SetupAction (org.jboss.as.server.deployment.SetupAction)2 WeldStartService (org.jboss.as.weld.WeldStartService)2 WeldInterceptorBindingsService (org.jboss.as.weld.ejb.WeldInterceptorBindingsService)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ServiceLoader (java.util.ServiceLoader)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Consumer (java.util.function.Consumer)1 Supplier (java.util.function.Supplier)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1