PageRenderTime 31ms CodeModel.GetById 15ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/web/src/main/java/org/jboss/as/web/deployment/WarClassloadingDependencyProcessor.java

#
Java | 120 lines | 67 code | 23 blank | 30 comment | 9 complexity | 82c2c5f57d622a7815f8a7f4b8935115 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1/*
  2 * JBoss, Home of Professional Open Source
  3 * Copyright 2010, Red Hat Inc., and individual contributors as indicated
  4 * by the @authors tag. See the copyright.txt in the distribution for a
  5 * full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22package org.jboss.as.web.deployment;
 23
 24import org.jboss.as.ee.structure.DeploymentType;
 25import org.jboss.as.ee.structure.DeploymentTypeMarker;
 26import org.jboss.as.server.deployment.Attachments;
 27import org.jboss.as.server.deployment.DeploymentPhaseContext;
 28import org.jboss.as.server.deployment.DeploymentUnit;
 29import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
 30import org.jboss.as.server.deployment.DeploymentUnitProcessor;
 31import org.jboss.as.server.deployment.module.ModuleDependency;
 32import org.jboss.as.server.deployment.module.ModuleSpecification;
 33import org.jboss.as.web.WebLogger;
 34import org.jboss.logging.Logger;
 35import org.jboss.modules.Module;
 36import org.jboss.modules.ModuleIdentifier;
 37import org.jboss.modules.ModuleLoader;
 38import org.jboss.modules.filter.PathFilters;
 39
 40/**
 41 * Module dependencies processor.
 42 *
 43 * @author Emanuel Muckenhuber
 44 * @author Stan Silvert
 45 */
 46public class WarClassloadingDependencyProcessor implements DeploymentUnitProcessor {
 47
 48    private static final ModuleIdentifier JAVAX_EE_API = ModuleIdentifier.create("javaee.api");
 49
 50    private static final ModuleIdentifier JSF_IMPL = ModuleIdentifier.create("com.sun.jsf-impl");
 51    private static final ModuleIdentifier JSF_API = ModuleIdentifier.create("javax.faces.api");
 52    private static final ModuleIdentifier JSF_1_2_IMPL = ModuleIdentifier.create("com.sun.jsf-impl", "1.2");
 53    private static final ModuleIdentifier JSF_1_2_API = ModuleIdentifier.create("javax.faces.api", "1.2");
 54    private static final ModuleIdentifier BEAN_VALIDATION = ModuleIdentifier.create("org.hibernate.validator");
 55    private static final ModuleIdentifier JSTL = ModuleIdentifier.create("javax.servlet.jstl.api");
 56
 57    private static final ModuleIdentifier JBOSS_WEB = ModuleIdentifier.create("org.jboss.as.web");
 58
 59    static {
 60        Module.registerURLStreamHandlerFactoryModule(Module.forClass(WarClassloadingDependencyProcessor.class));
 61    }
 62
 63    private static final Logger logger = Logger.getLogger(WarClassloadingDependencyProcessor.class);
 64
 65    public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
 66        final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
 67
 68        if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
 69            return; // Skip non web deployments
 70        }
 71
 72        final DeploymentUnit topLevelDeployment = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
 73        final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
 74        final ModuleLoader moduleLoader = Module.getBootModuleLoader();
 75
 76        final String jsfVersion = JsfVersionMarker.getVersion(topLevelDeployment);
 77
 78        addJSFAPI(jsfVersion, moduleSpecification, moduleLoader);
 79
 80        // Add module dependencies on Java EE apis
 81        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JAVAX_EE_API, false, false, false, false));
 82
 83        addJSFImpl(jsfVersion, moduleSpecification, moduleLoader);
 84
 85        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JSTL, false, false, false, false));
 86        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, BEAN_VALIDATION, false, false, true, false));
 87
 88        // FIXME we need to revise the exports of the web module, so that we
 89        // don't export our internals
 90        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JBOSS_WEB, false, false, true, false));
 91
 92    }
 93
 94    private void addJSFAPI(String jsfVersion, ModuleSpecification moduleSpecification, ModuleLoader moduleLoader) {
 95        if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL)) return;
 96
 97        ModuleIdentifier jsfModule = JSF_API;
 98        if (jsfVersion.equals(JsfVersionMarker.JSF_1_2)) jsfModule = JSF_1_2_API;
 99        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, jsfModule, false, false, false, false));
100    }
101
102    private void addJSFImpl(String jsfVersion, ModuleSpecification moduleSpecification, ModuleLoader moduleLoader) {
103        if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL)) return;
104
105        ModuleIdentifier jsfModule = null;
106        if (jsfVersion.equals(JsfVersionMarker.JSF_1_2)) jsfModule = JSF_1_2_IMPL;
107        if (jsfVersion.equals(JsfVersionMarker.JSF_2_0)) jsfModule = JSF_IMPL;
108        if (jsfModule == null) {
109            jsfModule = JSF_IMPL;
110            WebLogger.WEB_LOGGER.unknownJSFVersion(jsfVersion, JsfVersionMarker.JSF_2_0);
111        }
112
113        ModuleDependency jsf = new ModuleDependency(moduleLoader, jsfModule, false, false, false, false);
114        jsf.addImportFilter(PathFilters.getMetaInfFilter(), true);
115        moduleSpecification.addSystemDependency(jsf);
116    }
117
118    public void undeploy(final DeploymentUnit context) {
119    }
120}