use of org.jboss.as.ee.naming.ContextInjectionSource in project wildfly by wildfly.
the class ModuleJndiBindingProcessor method deploy.
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final EEModuleConfiguration moduleConfiguration = deploymentUnit.getAttachment(Attachments.EE_MODULE_CONFIGURATION);
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (moduleConfiguration == null) {
return;
}
final List<ServiceName> dependencies = deploymentUnit.getAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES);
final Map<ServiceName, BindingConfiguration> deploymentDescriptorBindings = new HashMap<ServiceName, BindingConfiguration>();
final List<BindingConfiguration> bindingConfigurations = eeModuleDescription.getBindingConfigurations();
// we need to make sure that java:module/env and java:comp/env are always available
if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
bindingConfigurations.add(new BindingConfiguration("java:module/env", new ContextInjectionSource("env", "java:module/env")));
}
if (deploymentUnit.getParent() == null) {
bindingConfigurations.add(new BindingConfiguration("java:app/env", new ContextInjectionSource("env", "java:app/env")));
}
for (BindingConfiguration binding : bindingConfigurations) {
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(moduleConfiguration.getApplicationName(), moduleConfiguration.getModuleName(), null, false, binding.getName());
deploymentDescriptorBindings.put(bindInfo.getBinderServiceName(), binding);
addJndiBinding(moduleConfiguration, binding, phaseContext, dependencies);
}
// these are bindings that have been added via a deployment descriptor
for (final ComponentConfiguration componentConfiguration : moduleConfiguration.getComponentConfigurations()) {
// handle these duplicates?
for (BindingConfiguration binding : componentConfiguration.getComponentDescription().getBindingConfigurations()) {
final String bindingName = binding.getName();
final boolean compBinding = bindingName.startsWith("java:comp") || !bindingName.startsWith("java:");
if (componentConfiguration.getComponentDescription().getNamingMode() == ComponentNamingMode.CREATE && compBinding) {
// components with there own comp context do their own binding
continue;
}
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(moduleConfiguration.getApplicationName(), moduleConfiguration.getModuleName(), null, false, binding.getName());
deploymentDescriptorBindings.put(bindInfo.getBinderServiceName(), binding);
addJndiBinding(moduleConfiguration, binding, phaseContext, dependencies);
}
}
// now add all class level bindings
final Set<String> handledClasses = new HashSet<String>();
for (final ComponentConfiguration componentConfiguration : moduleConfiguration.getComponentConfigurations()) {
final Set<Class<?>> classConfigurations = new HashSet<Class<?>>();
classConfigurations.add(componentConfiguration.getComponentClass());
for (final InterceptorDescription interceptor : componentConfiguration.getComponentDescription().getAllInterceptors()) {
try {
classConfigurations.add(ClassLoadingUtils.loadClass(interceptor.getInterceptorClassName(), module));
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, interceptor.getInterceptorClassName(), componentConfiguration.getComponentClass());
}
}
processClassConfigurations(phaseContext, applicationClasses, moduleConfiguration, deploymentDescriptorBindings, handledClasses, componentConfiguration.getComponentDescription().getNamingMode(), classConfigurations, componentConfiguration.getComponentName(), dependencies);
}
// now we need to process resource bindings that are not part of a component
// we don't process app client modules, as it just causes problems by installing bindings that
// were only intended to be installed when running as an app client
boolean appClient = DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, deploymentUnit) || this.appclient;
if (!ignoreUnusedResourceBinding && !MetadataCompleteMarker.isMetadataComplete(phaseContext.getDeploymentUnit()) && !appClient) {
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
for (EEModuleClassDescription config : eeModuleDescription.getClassDescriptions()) {
if (handledClasses.contains(config.getClassName())) {
continue;
}
if (config.isInvalid()) {
continue;
}
final Set<BindingConfiguration> classLevelBindings = new HashSet<>(config.getBindingConfigurations());
// between classes and not miss out on any.)
if (!classLevelBindings.isEmpty()) {
ClassInfo classInfo = index.getClassByName(DotName.createSimple(config.getClassName()));
if (!isConcreteClass(classInfo) && !hasConcreteSubclass(index, classInfo)) {
continue;
}
}
for (BindingConfiguration binding : classLevelBindings) {
final String bindingName = binding.getName();
final boolean compBinding = bindingName.startsWith("java:comp") || !bindingName.startsWith("java:");
if (compBinding && !DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// we don't have a comp namespace
continue;
}
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(moduleConfiguration.getApplicationName(), moduleConfiguration.getModuleName(), null, false, binding.getName());
if (deploymentDescriptorBindings.containsKey(bindInfo.getBinderServiceName())) {
// this has been overridden by a DD binding
continue;
}
ROOT_LOGGER.tracef("Binding %s using service %s", binding.getName(), bindInfo.getBinderServiceName());
addJndiBinding(moduleConfiguration, binding, phaseContext, dependencies);
}
}
}
}
Aggregations