PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms 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. */
  22. package org.jboss.as.web.deployment;
  23. import org.jboss.as.ee.structure.DeploymentType;
  24. import org.jboss.as.ee.structure.DeploymentTypeMarker;
  25. import org.jboss.as.server.deployment.Attachments;
  26. import org.jboss.as.server.deployment.DeploymentPhaseContext;
  27. import org.jboss.as.server.deployment.DeploymentUnit;
  28. import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
  29. import org.jboss.as.server.deployment.DeploymentUnitProcessor;
  30. import org.jboss.as.server.deployment.module.ModuleDependency;
  31. import org.jboss.as.server.deployment.module.ModuleSpecification;
  32. import org.jboss.as.web.WebLogger;
  33. import org.jboss.logging.Logger;
  34. import org.jboss.modules.Module;
  35. import org.jboss.modules.ModuleIdentifier;
  36. import org.jboss.modules.ModuleLoader;
  37. import org.jboss.modules.filter.PathFilters;
  38. /**
  39. * Module dependencies processor.
  40. *
  41. * @author Emanuel Muckenhuber
  42. * @author Stan Silvert
  43. */
  44. public class WarClassloadingDependencyProcessor implements DeploymentUnitProcessor {
  45. private static final ModuleIdentifier JAVAX_EE_API = ModuleIdentifier.create("javaee.api");
  46. private static final ModuleIdentifier JSF_IMPL = ModuleIdentifier.create("com.sun.jsf-impl");
  47. private static final ModuleIdentifier JSF_API = ModuleIdentifier.create("javax.faces.api");
  48. private static final ModuleIdentifier JSF_1_2_IMPL = ModuleIdentifier.create("com.sun.jsf-impl", "1.2");
  49. private static final ModuleIdentifier JSF_1_2_API = ModuleIdentifier.create("javax.faces.api", "1.2");
  50. private static final ModuleIdentifier BEAN_VALIDATION = ModuleIdentifier.create("org.hibernate.validator");
  51. private static final ModuleIdentifier JSTL = ModuleIdentifier.create("javax.servlet.jstl.api");
  52. private static final ModuleIdentifier JBOSS_WEB = ModuleIdentifier.create("org.jboss.as.web");
  53. static {
  54. Module.registerURLStreamHandlerFactoryModule(Module.forClass(WarClassloadingDependencyProcessor.class));
  55. }
  56. private static final Logger logger = Logger.getLogger(WarClassloadingDependencyProcessor.class);
  57. public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
  58. final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
  59. if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
  60. return; // Skip non web deployments
  61. }
  62. final DeploymentUnit topLevelDeployment = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
  63. final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
  64. final ModuleLoader moduleLoader = Module.getBootModuleLoader();
  65. final String jsfVersion = JsfVersionMarker.getVersion(topLevelDeployment);
  66. addJSFAPI(jsfVersion, moduleSpecification, moduleLoader);
  67. // Add module dependencies on Java EE apis
  68. moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JAVAX_EE_API, false, false, false, false));
  69. addJSFImpl(jsfVersion, moduleSpecification, moduleLoader);
  70. moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JSTL, false, false, false, false));
  71. moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, BEAN_VALIDATION, false, false, true, false));
  72. // FIXME we need to revise the exports of the web module, so that we
  73. // don't export our internals
  74. moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JBOSS_WEB, false, false, true, false));
  75. }
  76. private void addJSFAPI(String jsfVersion, ModuleSpecification moduleSpecification, ModuleLoader moduleLoader) {
  77. if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL)) return;
  78. ModuleIdentifier jsfModule = JSF_API;
  79. if (jsfVersion.equals(JsfVersionMarker.JSF_1_2)) jsfModule = JSF_1_2_API;
  80. moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, jsfModule, false, false, false, false));
  81. }
  82. private void addJSFImpl(String jsfVersion, ModuleSpecification moduleSpecification, ModuleLoader moduleLoader) {
  83. if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL)) return;
  84. ModuleIdentifier jsfModule = null;
  85. if (jsfVersion.equals(JsfVersionMarker.JSF_1_2)) jsfModule = JSF_1_2_IMPL;
  86. if (jsfVersion.equals(JsfVersionMarker.JSF_2_0)) jsfModule = JSF_IMPL;
  87. if (jsfModule == null) {
  88. jsfModule = JSF_IMPL;
  89. WebLogger.WEB_LOGGER.unknownJSFVersion(jsfVersion, JsfVersionMarker.JSF_2_0);
  90. }
  91. ModuleDependency jsf = new ModuleDependency(moduleLoader, jsfModule, false, false, false, false);
  92. jsf.addImportFilter(PathFilters.getMetaInfFilter(), true);
  93. moduleSpecification.addSystemDependency(jsf);
  94. }
  95. public void undeploy(final DeploymentUnit context) {
  96. }
  97. }