Search in sources :

Example 1 with NamingStore

use of org.jboss.as.naming.NamingStore in project wildfly by wildfly.

the class EEJndiViewExtension method execute.

public void execute(final JndiViewExtensionContext context) throws OperationFailedException {
    final ModelNode applicationsNode = context.getResult().get("applications");
    final ServiceRegistry serviceRegistry = context.getOperationContext().getServiceRegistry(false);
    final Set<Resource.ResourceEntry> deploymentResource = context.getOperationContext().readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false).getChildren(DEPLOYMENT);
    for (final Resource.ResourceEntry entry : deploymentResource) {
        final ServiceController<?> deploymentUnitServiceController = serviceRegistry.getService(ServiceName.JBOSS.append("deployment", "unit", entry.getName()));
        if (deploymentUnitServiceController != null) {
            final ModelNode deploymentNode = applicationsNode.get(entry.getName());
            final DeploymentUnit deploymentUnit = DeploymentUnit.class.cast(deploymentUnitServiceController.getValue());
            final String appName = cleanName(deploymentUnit.getName());
            final ServiceName appContextName = ContextNames.contextServiceNameOfApplication(appName);
            final ServiceController<?> appContextController = serviceRegistry.getService(appContextName);
            if (appContextController != null) {
                final NamingStore appStore = NamingStore.class.cast(appContextController.getValue());
                try {
                    context.addEntries(deploymentNode.get("java:app"), new NamingContext(appStore, null));
                } catch (NamingException e) {
                    throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:app", appName)));
                }
            }
            if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
                final List<ResourceRoot> roots = deploymentUnit.getAttachmentList(org.jboss.as.server.deployment.Attachments.RESOURCE_ROOTS);
                if (roots != null)
                    for (ResourceRoot root : roots) {
                        if (SubDeploymentMarker.isSubDeployment(root)) {
                            final ResourceRoot parentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
                            final String relativePath = root.getRoot().getPathNameRelativeTo(parentRoot.getRoot());
                            final ServiceName subDeploymentServiceName = Services.deploymentUnitName(deploymentUnit.getName(), relativePath);
                            final ServiceController<?> subDeploymentController = serviceRegistry.getService(subDeploymentServiceName);
                            if (subDeploymentController != null) {
                                final DeploymentUnit subDeploymentUnit = DeploymentUnit.class.cast(subDeploymentController.getValue());
                                handleModule(context, subDeploymentUnit, deploymentNode.get("modules"), serviceRegistry);
                            }
                        }
                    }
            } else {
                handleModule(context, deploymentUnit, deploymentNode.get("modules"), serviceRegistry);
            }
        }
    }
}
Also used : NamingStore(org.jboss.as.naming.NamingStore) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) NamingContext(org.jboss.as.naming.NamingContext) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ServiceName(org.jboss.msc.service.ServiceName) NamingException(javax.naming.NamingException) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 2 with NamingStore

use of org.jboss.as.naming.NamingStore in project wildfly by wildfly.

the class NamespaceConfigurator method configure.

/** {@inheritDoc} */
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
    final ComponentNamingMode namingMode = description.getNamingMode();
    final InjectedEENamespaceContextSelector selector = new InjectedEENamespaceContextSelector();
    final String applicationName = configuration.getApplicationName();
    final String moduleName = configuration.getModuleName();
    final String compName = configuration.getComponentName();
    final ServiceName appContextServiceName = ContextNames.contextServiceNameOfApplication(applicationName);
    final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(applicationName, moduleName);
    final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(applicationName, moduleName, compName);
    final Injector<NamingStore> appInjector = selector.getAppContextInjector();
    final Injector<NamingStore> moduleInjector = selector.getModuleContextInjector();
    final Injector<NamingStore> compInjector = selector.getCompContextInjector();
    final Injector<NamingStore> jbossInjector = selector.getJbossContextInjector();
    final Injector<NamingStore> globalInjector = selector.getGlobalContextInjector();
    final Injector<NamingStore> exportedInjector = selector.getExportedContextInjector();
    configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

        public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) {
            serviceBuilder.addDependency(appContextServiceName, NamingStore.class, appInjector);
            serviceBuilder.addDependency(moduleContextServiceName, NamingStore.class, moduleInjector);
            if (namingMode == ComponentNamingMode.CREATE) {
                serviceBuilder.addDependency(compContextServiceName, NamingStore.class, compInjector);
            } else if (namingMode == ComponentNamingMode.USE_MODULE) {
                serviceBuilder.addDependency(moduleContextServiceName, NamingStore.class, compInjector);
            }
            serviceBuilder.addDependency(ContextNames.GLOBAL_CONTEXT_SERVICE_NAME, NamingStore.class, globalInjector);
            serviceBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, NamingStore.class, jbossInjector);
            serviceBuilder.addDependency(ContextNames.EXPORTED_CONTEXT_SERVICE_NAME, NamingStore.class, exportedInjector);
        }
    });
    final InterceptorFactory interceptorFactory = new ImmediateInterceptorFactory(new NamespaceContextInterceptor(selector, context.getDeploymentUnit().getServiceName()));
    configuration.addPostConstructInterceptor(interceptorFactory, InterceptorOrder.ComponentPostConstruct.JNDI_NAMESPACE_INTERCEPTOR);
    configuration.addPreDestroyInterceptor(interceptorFactory, InterceptorOrder.ComponentPreDestroy.JNDI_NAMESPACE_INTERCEPTOR);
    if (description.isPassivationApplicable()) {
        configuration.addPrePassivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.JNDI_NAMESPACE_INTERCEPTOR);
        configuration.addPostActivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.JNDI_NAMESPACE_INTERCEPTOR);
    }
    configuration.setNamespaceContextInterceptorFactory(interceptorFactory);
    configuration.setNamespaceContextSelector(selector);
}
Also used : NamingStore(org.jboss.as.naming.NamingStore) InterceptorFactory(org.jboss.invocation.InterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) ServiceName(org.jboss.msc.service.ServiceName) InjectedEENamespaceContextSelector(org.jboss.as.ee.naming.InjectedEENamespaceContextSelector) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory)

Example 3 with NamingStore

use of org.jboss.as.naming.NamingStore in project wildfly by wildfly.

the class EEJndiViewExtension method handleModule.

private void handleModule(final JndiViewExtensionContext context, final DeploymentUnit deploymentUnit, final ModelNode modulesNode, final ServiceRegistry serviceRegistry) throws OperationFailedException {
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    // If it isn't an EE module, just return
    if (moduleDescription == null) {
        return;
    }
    final String appName = moduleDescription.getApplicationName();
    final String moduleName = moduleDescription.getModuleName();
    final ModelNode moduleNode = modulesNode.get(moduleDescription.getModuleName());
    final ServiceName moduleContextName = ContextNames.contextServiceNameOfModule(appName, moduleName);
    final ServiceController<?> moduleContextController = serviceRegistry.getService(moduleContextName);
    if (moduleContextController != null) {
        final NamingStore moduleStore = NamingStore.class.cast(moduleContextController.getValue());
        try {
            context.addEntries(moduleNode.get("java:module"), new NamingContext(moduleStore, null));
        } catch (NamingException e) {
            throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:module", appName, moduleName)));
        }
        final Collection<ComponentDescription> componentDescriptions = moduleDescription.getComponentDescriptions();
        for (ComponentDescription componentDescription : componentDescriptions) {
            final String componentName = componentDescription.getComponentName();
            final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(appName, moduleName, componentName);
            final ServiceController<?> compContextController = serviceRegistry.getService(compContextServiceName);
            if (compContextController != null) {
                final ModelNode componentNode = moduleNode.get("components").get(componentName);
                final NamingStore compStore = NamingStore.class.cast(compContextController.getValue());
                try {
                    context.addEntries(componentNode.get("java:comp"), new NamingContext(compStore, null));
                } catch (NamingException e) {
                    throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:comp", appName, moduleName, componentName)));
                }
            }
        }
    }
}
Also used : NamingStore(org.jboss.as.naming.NamingStore) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) OperationFailedException(org.jboss.as.controller.OperationFailedException) NamingException(javax.naming.NamingException) ModelNode(org.jboss.dmr.ModelNode) NamingContext(org.jboss.as.naming.NamingContext)

Aggregations

NamingStore (org.jboss.as.naming.NamingStore)3 ServiceName (org.jboss.msc.service.ServiceName)3 NamingException (javax.naming.NamingException)2 OperationFailedException (org.jboss.as.controller.OperationFailedException)2 NamingContext (org.jboss.as.naming.NamingContext)2 ModelNode (org.jboss.dmr.ModelNode)2 Resource (org.jboss.as.controller.registry.Resource)1 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 InjectedEENamespaceContextSelector (org.jboss.as.ee.naming.InjectedEENamespaceContextSelector)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)1 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)1 InterceptorFactory (org.jboss.invocation.InterceptorFactory)1 ServiceController (org.jboss.msc.service.ServiceController)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1