Search in sources :

Example 11 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class PersistenceUnitServiceHandler method deployPersistenceUnitPhaseOne.

/**
 * first phase of starting the persistence unit
 *
 * @param deploymentUnit
 * @param eeModuleDescription
 * @param serviceTarget
 * @param classLoader
 * @param pu
 * @param adaptor
 * @throws DeploymentUnitProcessingException
 */
private static void deployPersistenceUnitPhaseOne(final DeploymentUnit deploymentUnit, final EEModuleDescription eeModuleDescription, final ServiceTarget serviceTarget, final ModuleClassLoader classLoader, final PersistenceUnitMetadata pu, final PersistenceProviderAdaptor adaptor) throws DeploymentUnitProcessingException {
    CapabilityServiceSupport capabilitySupport = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    pu.setClassLoader(classLoader);
    try {
        final HashMap<String, ValidatorFactory> properties = new HashMap<>();
        ProxyBeanManager proxyBeanManager = null;
        // JPA 2.1 sections 3.5.1 + 9.1 require the Jakarta Contexts and Dependency Injection bean manager to be passed to the peristence provider
        // if the persistence unit is contained in a deployment that is a Jakarta Contexts and Dependency Injection bean archive (has beans.xml).
        final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        boolean partOfWeldDeployment = false;
        if (support.hasCapability(WELD_CAPABILITY_NAME)) {
            partOfWeldDeployment = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get().isPartOfWeldDeployment(deploymentUnit);
        }
        if (partOfWeldDeployment) {
            proxyBeanManager = new ProxyBeanManager();
            // register Jakarta Contexts and Dependency Injection extension before WeldDeploymentProcessor, which is important for
            registerJPAEntityListenerRegister(deploymentUnit, support);
        // EAR deployments that contain a WAR that has persistence units defined.
        }
        deploymentUnit.addToAttachmentList(REMOVAL_KEY, new PersistenceAdaptorRemoval(pu, adaptor));
        // add persistence provider specific properties
        adaptor.addProviderProperties(properties, pu);
        final ServiceName puServiceName = PersistenceUnitServiceImpl.getPUServiceName(pu).append(FIRST_PHASE);
        deploymentUnit.putAttachment(JpaAttachments.PERSISTENCE_UNIT_SERVICE_KEY, puServiceName);
        deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_COMPLETE_SERVICES, puServiceName);
        deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, puServiceName);
        final PhaseOnePersistenceUnitServiceImpl service = new PhaseOnePersistenceUnitServiceImpl(classLoader, pu, adaptor, deploymentUnit.getServiceName(), proxyBeanManager);
        service.getPropertiesInjector().inject(properties);
        ServiceBuilder<PhaseOnePersistenceUnitServiceImpl> builder = serviceTarget.addService(puServiceName, service);
        boolean useDefaultDataSource = Configuration.allowDefaultDataSourceUse(pu);
        final String jtaDataSource = adjustJndi(pu.getJtaDataSourceName());
        final String nonJtaDataSource = adjustJndi(pu.getNonJtaDataSourceName());
        if (jtaDataSource != null && jtaDataSource.length() > 0) {
            if (jtaDataSource.equals(EE_DEFAULT_DATASOURCE)) {
                // explicit use of default datasource
                useDefaultDataSource = true;
            } else {
                builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getJtaDataSourceInjector()));
                useDefaultDataSource = false;
            }
        }
        if (nonJtaDataSource != null && nonJtaDataSource.length() > 0) {
            builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, nonJtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getNonJtaDataSourceInjector()));
            useDefaultDataSource = false;
        }
        // JPA 2.0 8.2.1.5, container provides default Jakarta Transactions datasource
        if (useDefaultDataSource) {
            // try the one defined in the Jakarta Persistence subsystem
            String defaultJtaDataSource = null;
            if (eeModuleDescription != null) {
                defaultJtaDataSource = eeModuleDescription.getDefaultResourceJndiNames().getDataSource();
            }
            if (defaultJtaDataSource == null || defaultJtaDataSource.isEmpty()) {
                // try the datasource defined in the JPA subsystem
                defaultJtaDataSource = adjustJndi(JPAService.getDefaultDataSourceName());
            }
            if (defaultJtaDataSource != null && !defaultJtaDataSource.isEmpty()) {
                builder.addDependency(ContextNames.bindInfoFor(defaultJtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getJtaDataSourceInjector()));
                ROOT_LOGGER.tracef("%s is using the default data source '%s'", puServiceName, defaultJtaDataSource);
            }
        }
        try {
            // save a thread local reference to the builder for setting up the second level cache dependencies
            CacheDeploymentListener.setInternalDeploymentSupport(builder, capabilitySupport);
            adaptor.addProviderDependencies(pu);
        } finally {
            CacheDeploymentListener.clearInternalDeploymentSupport();
        }
        // get async executor from Services.addServerExecutorDependency
        addServerExecutorDependency(builder, service.getExecutorInjector());
        builder.install();
        ROOT_LOGGER.tracef("added PersistenceUnitService (phase 1 of 2) for '%s'.  PU is ready for injector action.", puServiceName);
    } catch (ServiceRegistryException e) {
        throw JpaLogger.ROOT_LOGGER.failedToAddPersistenceUnit(e, pu.getPersistenceUnitName());
    }
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) WeldCapability(org.jboss.as.weld.WeldCapability) PhaseOnePersistenceUnitServiceImpl(org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl) ServiceRegistryException(org.jboss.msc.service.ServiceRegistryException) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ServiceName(org.jboss.msc.service.ServiceName) ProxyBeanManager(org.jboss.as.jpa.beanmanager.ProxyBeanManager)

Example 12 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class PersistenceUnitServiceHandler method deployPersistenceUnitPhaseTwo.

/**
 * Second phase of starting the persistence unit
 *
 * @param deploymentUnit
 * @param eeModuleDescription
 * @param serviceTarget
 * @param classLoader
 * @param pu
 * @param provider
 * @param adaptor
 * @throws DeploymentUnitProcessingException
 */
private static void deployPersistenceUnitPhaseTwo(final DeploymentUnit deploymentUnit, final EEModuleDescription eeModuleDescription, final ServiceTarget serviceTarget, final ModuleClassLoader classLoader, final PersistenceUnitMetadata pu, final PersistenceProvider provider, final PersistenceProviderAdaptor adaptor) throws DeploymentUnitProcessingException {
    TransactionManager transactionManager = ContextTransactionManager.getInstance();
    TransactionSynchronizationRegistry transactionSynchronizationRegistry = deploymentUnit.getAttachment(JpaAttachments.TRANSACTION_SYNCHRONIZATION_REGISTRY);
    CapabilityServiceSupport capabilitySupport = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    pu.setClassLoader(classLoader);
    try {
        ValidatorFactory validatorFactory = null;
        final HashMap<String, ValidatorFactory> properties = new HashMap<>();
        if (!ValidationMode.NONE.equals(pu.getValidationMode()) && capabilitySupport.hasCapability("org.wildfly.bean-validation")) {
            // Get the Jakarta Contexts and Dependency Injection enabled ValidatorFactory
            validatorFactory = deploymentUnit.getAttachment(BeanValidationAttachments.VALIDATOR_FACTORY);
        }
        BeanManagerAfterDeploymentValidation beanManagerAfterDeploymentValidation = registerJPAEntityListenerRegister(deploymentUnit, capabilitySupport);
        final PersistenceAdaptorRemoval persistenceAdaptorRemoval = new PersistenceAdaptorRemoval(pu, adaptor);
        deploymentUnit.addToAttachmentList(REMOVAL_KEY, persistenceAdaptorRemoval);
        // add persistence provider specific properties
        adaptor.addProviderProperties(properties, pu);
        final ServiceName puServiceName = PersistenceUnitServiceImpl.getPUServiceName(pu);
        deploymentUnit.putAttachment(JpaAttachments.PERSISTENCE_UNIT_SERVICE_KEY, puServiceName);
        deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_COMPLETE_SERVICES, puServiceName);
        deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, puServiceName);
        final PersistenceUnitServiceImpl service = new PersistenceUnitServiceImpl(properties, classLoader, pu, adaptor, provider, PersistenceUnitRegistryImpl.INSTANCE, deploymentUnit.getServiceName(), validatorFactory, deploymentUnit.getAttachment(org.jboss.as.ee.naming.Attachments.JAVA_NAMESPACE_SETUP_ACTION), beanManagerAfterDeploymentValidation);
        ServiceBuilder<PersistenceUnitService> builder = serviceTarget.addService(puServiceName, service);
        // the PU service has to depend on the JPAService which is responsible for setting up the necessary JPA infrastructure (like registering the cache EventListener(s))
        // @see https://issues.jboss.org/browse/WFLY-1531 for details
        builder.requires(JPAServiceNames.getJPAServiceName());
        // add dependency on first phase
        builder.addDependency(puServiceName.append(FIRST_PHASE), Object.class, new CastingInjector<>(service.getPhaseOnePersistenceUnitServiceImplInjector(), PhaseOnePersistenceUnitServiceImpl.class));
        boolean useDefaultDataSource = Configuration.allowDefaultDataSourceUse(pu);
        final String jtaDataSource = adjustJndi(pu.getJtaDataSourceName());
        final String nonJtaDataSource = adjustJndi(pu.getNonJtaDataSourceName());
        if (jtaDataSource != null && jtaDataSource.length() > 0) {
            if (jtaDataSource.equals(EE_DEFAULT_DATASOURCE)) {
                // explicit use of default datasource
                useDefaultDataSource = true;
            } else {
                builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getJtaDataSourceInjector()));
                useDefaultDataSource = false;
            }
        }
        if (nonJtaDataSource != null && nonJtaDataSource.length() > 0) {
            builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, nonJtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getNonJtaDataSourceInjector()));
            useDefaultDataSource = false;
        }
        // JPA 2.0 8.2.1.5, container provides default Jakarta Transactions datasource
        if (useDefaultDataSource) {
            // try the default datasource defined in the ee subsystem
            String defaultJtaDataSource = null;
            if (eeModuleDescription != null) {
                defaultJtaDataSource = eeModuleDescription.getDefaultResourceJndiNames().getDataSource();
            }
            if (defaultJtaDataSource == null || defaultJtaDataSource.isEmpty()) {
                // try the datasource defined in the Jakarta Persistence subsystem
                defaultJtaDataSource = adjustJndi(JPAService.getDefaultDataSourceName());
            }
            if (defaultJtaDataSource != null && !defaultJtaDataSource.isEmpty()) {
                builder.addDependency(ContextNames.bindInfoFor(defaultJtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getJtaDataSourceInjector()));
                ROOT_LOGGER.tracef("%s is using the default data source '%s'", puServiceName, defaultJtaDataSource);
            }
        }
        // JPA 2.1 sections 3.5.1 + 9.1 require the Jakarta Contexts and Dependency Injection bean manager to be passed to the persistence provider
        // if the persistence unit is contained in a deployment that is a Jakarta Contexts and Dependency Injection bean archive (has beans.xml).
        final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        if (support.hasCapability(WELD_CAPABILITY_NAME)) {
            support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get().addBeanManagerService(deploymentUnit, builder, service.getBeanManagerInjector());
        }
        try {
            // save a thread local reference to the builder for setting up the second level cache dependencies
            CacheDeploymentListener.setInternalDeploymentSupport(builder, capabilitySupport);
            adaptor.addProviderDependencies(pu);
        } finally {
            CacheDeploymentListener.clearInternalDeploymentSupport();
        }
        /**
         * handle extension that binds a transaction scoped entity manager to specified JNDI location
         */
        entityManagerBind(eeModuleDescription, serviceTarget, pu, puServiceName, transactionManager, transactionSynchronizationRegistry);
        /**
         * handle extension that binds an entity manager factory to specified JNDI location
         */
        entityManagerFactoryBind(eeModuleDescription, serviceTarget, pu, puServiceName);
        // get async executor from Services.addServerExecutorDependency
        addServerExecutorDependency(builder, service.getExecutorInjector());
        builder.install();
        ROOT_LOGGER.tracef("added PersistenceUnitService (phase 2 of 2) for '%s'.  PU is ready for injector action.", puServiceName);
        addManagementConsole(deploymentUnit, pu, adaptor, persistenceAdaptorRemoval);
    } catch (ServiceRegistryException e) {
        throw JpaLogger.ROOT_LOGGER.failedToAddPersistenceUnit(e, pu.getPersistenceUnitName());
    }
}
Also used : PhaseOnePersistenceUnitServiceImpl(org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl) PersistenceUnitServiceImpl(org.jboss.as.jpa.service.PersistenceUnitServiceImpl) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) PhaseOnePersistenceUnitServiceImpl(org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl) ServiceRegistryException(org.jboss.msc.service.ServiceRegistryException) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) BeanManagerAfterDeploymentValidation(org.jboss.as.jpa.beanmanager.BeanManagerAfterDeploymentValidation) ServiceName(org.jboss.msc.service.ServiceName) ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) PersistenceUnitService(org.jboss.as.jpa.spi.PersistenceUnitService)

Example 13 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class JaccEjbDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentContainsEjbs(deploymentUnit) == false) {
        return;
    }
    AbstractSecurityDeployer<?> deployer = null;
    deployer = new EjbSecurityDeployer();
    JaccService<?> service = deployer.deploy(deploymentUnit);
    if (service != null) {
        final DeploymentUnit parentDU = deploymentUnit.getParent();
        // Jakarta Enterprise Beans maybe included directly in war deployment
        ServiceName jaccServiceName = getJaccServiceName(deploymentUnit);
        final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
        ServiceBuilder<?> builder = serviceTarget.addService(jaccServiceName, service);
        if (parentDU != null) {
            // add dependency to parent policy
            builder.addDependency(parentDU.getServiceName().append(JaccService.SERVICE_NAME), PolicyConfiguration.class, service.getParentPolicyInjector());
        }
        CapabilityServiceSupport capabilitySupport = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        builder.addDependencies(capabilitySupport.getCapabilityServiceName(jaccCapabilityName));
        builder.setInitialMode(Mode.ACTIVE).install();
    }
}
Also used : EjbSecurityDeployer(org.jboss.as.ejb3.deployment.EjbSecurityDeployer) ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport)

Example 14 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class JPASubSystemAdd method performBoottime.

protected void performBoottime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
    context.addStep(new AbstractDeploymentChainStep() {

        protected void execute(DeploymentProcessorTarget processorTarget) {
            // set Hibernate persistence provider as the default provider
            javax.persistence.spi.PersistenceProviderResolverHolder.setPersistenceProviderResolver(PersistenceProviderResolverImpl.getInstance());
            final boolean appclient = context.getProcessType() == ProcessType.APPLICATION_CLIENT;
            PlatformImpl platform;
            if (appclient) {
                // we do not yet support a second level cache in the client container
                platform = new PlatformImpl(Classification.NONE);
            } else {
                // Infinispan can be used in server container
                platform = new PlatformImpl(Classification.INFINISPAN, Classification.INFINISPAN);
            }
            processorTarget.addDeploymentProcessor(JPAExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_REGISTER_JBOSS_ALL_JPA, new JBossAllXmlParserRegisteringProcessor<>(JPAJarJBossAllParser.ROOT_ELEMENT, JpaAttachments.DEPLOYMENT_SETTINGS_KEY, new JPAJarJBossAllParser()));
            // handles parsing of persistence.xml
            processorTarget.addDeploymentProcessor(JPAExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_PERSISTENCE_UNIT, new PersistenceUnitParseProcessor(appclient));
            // handles persistence unit / context annotations in components
            processorTarget.addDeploymentProcessor(JPAExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_PERSISTENCE_ANNOTATION, new JPAAnnotationProcessor());
            // injects Jakarta Persistence dependencies into an application
            processorTarget.addDeploymentProcessor(JPAExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_JPA, new JPADependencyProcessor());
            // Inject Hibernate Search dependencies into an application
            processorTarget.addDeploymentProcessor(JPAExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_HIBERNATE_SEARCH, new HibernateSearchProcessor());
            // handle ClassFileTransformer
            processorTarget.addDeploymentProcessor(JPAExtension.SUBSYSTEM_NAME, Phase.FIRST_MODULE_USE, Phase.FIRST_MODULE_USE_PERSISTENCE_CLASS_FILE_TRANSFORMER, new JPAClassFileTransformerProcessor());
            final CapabilityServiceSupport capabilities = context.getCapabilityServiceSupport();
            if (capabilities.hasCapability("org.wildfly.ejb3")) {
                // registers listeners/interceptors on session beans
                processorTarget.addDeploymentProcessor(JPAExtension.SUBSYSTEM_NAME, Phase.FIRST_MODULE_USE, Phase.FIRST_MODULE_USE_INTERCEPTORS, new JPAInterceptorProcessor());
            }
            // begin pu service install and deploying a persistence provider
            processorTarget.addDeploymentProcessor(JPAExtension.SUBSYSTEM_NAME, Phase.FIRST_MODULE_USE, Phase.FIRST_MODULE_USE_PERSISTENCE_PREPARE, new PersistenceBeginInstallProcessor(platform));
            // handles persistence unit / context references from deployment descriptors
            processorTarget.addDeploymentProcessor(JPAExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_PERSISTENCE_REF, new PersistenceRefProcessor());
            // handles pu deployment (completes pu service installation)
            processorTarget.addDeploymentProcessor(JPAExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_PERSISTENTUNIT, new PersistenceCompleteInstallProcessor(platform));
        }
    }, OperationContext.Stage.RUNTIME);
    final String dataSourceName = DEFAULT_DATASOURCE.resolveModelAttribute(context, model).asStringOrNull();
    final ExtendedPersistenceInheritance defaultExtendedPersistenceInheritance = ExtendedPersistenceInheritance.valueOf(DEFAULT_EXTENDEDPERSISTENCE_INHERITANCE.resolveModelAttribute(context, model).asString());
    final ServiceTarget target = context.getServiceTarget();
    JPAService.addService(target, dataSourceName, defaultExtendedPersistenceInheritance);
    JPAUserTransactionListenerService.addService(target);
}
Also used : JBossAllXmlParserRegisteringProcessor(org.jboss.as.server.deployment.jbossallxml.JBossAllXmlParserRegisteringProcessor) ServiceTarget(org.jboss.msc.service.ServiceTarget) PersistenceRefProcessor(org.jboss.as.jpa.processor.PersistenceRefProcessor) JPAInterceptorProcessor(org.jboss.as.jpa.processor.JPAInterceptorProcessor) PersistenceCompleteInstallProcessor(org.jboss.as.jpa.processor.PersistenceCompleteInstallProcessor) JPADependencyProcessor(org.jboss.as.jpa.processor.JPADependencyProcessor) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ExtendedPersistenceInheritance(org.jboss.as.jpa.config.ExtendedPersistenceInheritance) JPAJarJBossAllParser(org.jboss.as.jpa.processor.JPAJarJBossAllParser) DeploymentProcessorTarget(org.jboss.as.server.DeploymentProcessorTarget) PersistenceUnitParseProcessor(org.jboss.as.jpa.processor.PersistenceUnitParseProcessor) JPAClassFileTransformerProcessor(org.jboss.as.jpa.processor.JPAClassFileTransformerProcessor) AbstractDeploymentChainStep(org.jboss.as.server.AbstractDeploymentChainStep) HibernateSearchProcessor(org.jboss.as.jpa.processor.HibernateSearchProcessor) JPAAnnotationProcessor(org.jboss.as.jpa.processor.JPAAnnotationProcessor) PersistenceBeginInstallProcessor(org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor) PlatformImpl(org.jboss.as.jpa.platform.PlatformImpl)

Example 15 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class JSFComponentProcessor method processJSFArtifactsForInjection.

/**
 * According to Jakarta Server Faces specification there is a table of eligible components
 * for Jakarta Contexts and Dependency Injection (TABLE 5-3 Jakarta Server Faces Artifacts Eligible for Injection in chapter
 * 5.4.1 Jakarta Server Faces Managed Classes and Jakarta EE Annotations). This method parses
 * the faces-config configuration files and registers the classes.
 * The parser is quite simplistic. The tags are saved into a queue and
 * using the facesConfigElement tree it is known when a tag is one of the
 * classes to use for injection.
 */
private void processJSFArtifactsForInjection(final DeploymentUnit deploymentUnit, final Set<String> managedBeanClasses) {
    final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    boolean isCDI = support.hasCapability(WELD_CAPABILITY_NAME) && support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get().isPartOfWeldDeployment(deploymentUnit);
    final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    JsfElement current = null;
    Deque<JsfElement> queue = new LinkedList<>();
    for (final VirtualFile facesConfig : getConfigurationFiles(deploymentUnit)) {
        try (InputStream is = facesConfig.openStream()) {
            final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            inputFactory.setXMLResolver(NoopXMLResolver.create());
            XMLStreamReader parser = inputFactory.createXMLStreamReader(is);
            boolean finished = false;
            while (!finished) {
                int event = parser.next();
                switch(event) {
                    case XMLStreamConstants.END_DOCUMENT:
                        finished = true;
                        parser.close();
                        break;
                    case XMLStreamConstants.START_ELEMENT:
                        String tagName = parser.getLocalName();
                        if (current == null) {
                            // first element => should be faces-context
                            if (tagName.equals(JsfTag.FACES_CONFIG.getTagName())) {
                                current = new JsfElement(facesConfigElement);
                            } else {
                                current = new JsfElement(tagName);
                            }
                        } else {
                            JsfTree child = current.isTree() ? current.getTree().getChild(tagName) : null;
                            if (child != null && child.isLeaf()) {
                                // leaf component => read the class and register the component
                                String className = parser.getElementText().trim();
                                if (!managedBeanClasses.contains(className)) {
                                    managedBeanClasses.add(className);
                                    if (child.getTag() == JsfTag.MANAGED_BEAN_CLASS) {
                                        installManagedBeanComponent(className, moduleDescription, module, deploymentUnit, applicationClassesDescription);
                                    } else {
                                        installJsfArtifactComponent(child.getTag().getTagName(), className, isCDI, moduleDescription, module, deploymentUnit, applicationClassesDescription);
                                    }
                                }
                            } else if (child != null) {
                                // non-leaf known element => advance into it
                                queue.push(current);
                                current = new JsfElement(child);
                            } else {
                                // unknown element => just put it in the queue
                                queue.push(current);
                                current = new JsfElement(tagName);
                            }
                        }
                        break;
                    case XMLStreamConstants.END_ELEMENT:
                        // end of current element, just get the previous element from the queue
                        current = queue.isEmpty() ? null : queue.pop();
                        break;
                }
            }
        } catch (Exception e) {
            JSFLogger.ROOT_LOGGER.managedBeansConfigParseFailed(facesConfig);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) WeldCapability(org.jboss.as.weld.WeldCapability) LinkedList(java.util.LinkedList) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) Module(org.jboss.modules.Module) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)76 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)39 ServiceName (org.jboss.msc.service.ServiceName)38 ServiceTarget (org.jboss.msc.service.ServiceTarget)25 WeldCapability (org.jboss.as.weld.WeldCapability)19 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)18 Module (org.jboss.modules.Module)16 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)14 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)10 HashMap (java.util.HashMap)9 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)9 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)8 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)8 ValidatorFactory (javax.validation.ValidatorFactory)7 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)7 HashSet (java.util.HashSet)6 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)6 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)6 ModelNode (org.jboss.dmr.ModelNode)6 ModuleLoader (org.jboss.modules.ModuleLoader)6