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