Search in sources :

Example 1 with ContextInjectionSource

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);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) InterceptorDescription(org.jboss.as.ee.component.InterceptorDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ContextInjectionSource(org.jboss.as.ee.naming.ContextInjectionSource) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) ContextNames(org.jboss.as.naming.deployment.ContextNames) HashSet(java.util.HashSet) EEModuleConfiguration(org.jboss.as.ee.component.EEModuleConfiguration) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) ServiceName(org.jboss.msc.service.ServiceName) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)1 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)1 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)1 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)1 EEModuleConfiguration (org.jboss.as.ee.component.EEModuleConfiguration)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 InterceptorDescription (org.jboss.as.ee.component.InterceptorDescription)1 ContextInjectionSource (org.jboss.as.ee.naming.ContextInjectionSource)1 ContextNames (org.jboss.as.naming.deployment.ContextNames)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)1 ClassInfo (org.jboss.jandex.ClassInfo)1 Module (org.jboss.modules.Module)1 ServiceName (org.jboss.msc.service.ServiceName)1