PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ee/src/main/java/org/jboss/as/ee/structure/ComponentAggregationProcessor.java

#
Java | 119 lines | 69 code | 14 blank | 36 comment | 19 complexity | 33a4a7343aae1cd88d276b98825ab6c7 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a 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.ee.structure;
  23. import java.util.List;
  24. import java.util.Map;
  25. import org.jboss.as.ee.component.ComponentDescription;
  26. import org.jboss.as.ee.component.EEApplicationDescription;
  27. import org.jboss.as.ee.component.EEModuleDescription;
  28. import org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor;
  29. import org.jboss.as.server.deployment.DeploymentPhaseContext;
  30. import org.jboss.as.server.deployment.DeploymentUnit;
  31. import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
  32. import org.jboss.as.server.deployment.DeploymentUnitProcessor;
  33. import org.jboss.as.server.deployment.module.ResourceRoot;
  34. import org.jboss.logging.Logger;
  35. import static org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION;
  36. import static org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION;
  37. import static org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS;
  38. /**
  39. * @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
  40. * @author Stuart Douglas
  41. */
  42. public final class ComponentAggregationProcessor implements DeploymentUnitProcessor {
  43. private static final Logger logger = Logger.getLogger(EEModuleConfigurationProcessor.class);
  44. public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
  45. DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
  46. if (deploymentUnit.getAttachment(Attachments.DEPLOYMENT_TYPE) == DeploymentType.EAR) {
  47. final EEApplicationDescription applicationDescription = new EEApplicationDescription();
  48. deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION, applicationDescription);
  49. final EEModuleDescription earDesc = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
  50. if (earDesc != null) {
  51. for (final Map.Entry<String, String> messageDestination : earDesc.getMessageDestinations().entrySet()) {
  52. applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT).getRoot());
  53. }
  54. }
  55. /*
  56. * We are an EAR, so we must inspect all of our subdeployments and aggregate all their component views
  57. * into a single index, so that inter-module resolution will work.
  58. */
  59. // Add the application description
  60. final List<DeploymentUnit> subdeployments = deploymentUnit.getAttachmentList(SUB_DEPLOYMENTS);
  61. for (final DeploymentUnit subdeployment : subdeployments) {
  62. final EEModuleDescription moduleDescription = subdeployment.getAttachment(EE_MODULE_DESCRIPTION);
  63. final ResourceRoot deploymentRoot = subdeployment.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
  64. if (moduleDescription == null) {
  65. // Not an EE deployment.
  66. continue;
  67. }
  68. for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
  69. applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
  70. }
  71. for (final Map.Entry<String, String> messageDestination : moduleDescription.getMessageDestinations().entrySet()) {
  72. applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentRoot.getRoot());
  73. }
  74. for (final ComponentDescription componentDescription : subdeployment.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
  75. applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
  76. }
  77. subdeployment.putAttachment(EE_APPLICATION_DESCRIPTION, applicationDescription);
  78. }
  79. } else if (deploymentUnit.getParent() == null) {
  80. final EEApplicationDescription applicationDescription = new EEApplicationDescription();
  81. deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION, applicationDescription);
  82. /*
  83. * We are a top-level EE deployment, or a non-EE deployment. Our "aggregate" index is just a copy of
  84. * our local EE module index.
  85. */
  86. final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
  87. final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
  88. if (moduleDescription == null) {
  89. // Not an EE deployment.
  90. return;
  91. }
  92. for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
  93. applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
  94. }
  95. for (final Map.Entry<String, String> messageDestination : moduleDescription.getMessageDestinations().entrySet()) {
  96. applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentRoot.getRoot());
  97. }
  98. for (final ComponentDescription componentDescription : deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
  99. applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
  100. }
  101. }
  102. }
  103. public void undeploy(final DeploymentUnit context) {
  104. }
  105. }