PageRenderTime 47ms CodeModel.GetById 33ms app.highlight 12ms RepoModel.GetById 1ms 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
 23package org.jboss.as.ee.structure;
 24
 25import java.util.List;
 26import java.util.Map;
 27
 28import org.jboss.as.ee.component.ComponentDescription;
 29import org.jboss.as.ee.component.EEApplicationDescription;
 30import org.jboss.as.ee.component.EEModuleDescription;
 31import org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor;
 32import org.jboss.as.server.deployment.DeploymentPhaseContext;
 33import org.jboss.as.server.deployment.DeploymentUnit;
 34import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
 35import org.jboss.as.server.deployment.DeploymentUnitProcessor;
 36import org.jboss.as.server.deployment.module.ResourceRoot;
 37import org.jboss.logging.Logger;
 38
 39import static org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION;
 40import static org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION;
 41import static org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS;
 42
 43/**
 44 * @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
 45 * @author Stuart Douglas
 46 */
 47public final class ComponentAggregationProcessor implements DeploymentUnitProcessor {
 48
 49    private static final Logger logger = Logger.getLogger(EEModuleConfigurationProcessor.class);
 50
 51    public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
 52        DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
 53
 54        if (deploymentUnit.getAttachment(Attachments.DEPLOYMENT_TYPE) == DeploymentType.EAR) {
 55
 56            final EEApplicationDescription applicationDescription = new EEApplicationDescription();
 57            deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION, applicationDescription);
 58
 59            final EEModuleDescription earDesc = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
 60            if (earDesc != null) {
 61                for (final Map.Entry<String, String> messageDestination : earDesc.getMessageDestinations().entrySet()) {
 62                    applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT).getRoot());
 63                }
 64            }
 65
 66            /*
 67            * We are an EAR, so we must inspect all of our subdeployments and aggregate all their component views
 68            * into a single index, so that inter-module resolution will work.
 69            */
 70            // Add the application description
 71            final List<DeploymentUnit> subdeployments = deploymentUnit.getAttachmentList(SUB_DEPLOYMENTS);
 72            for (final DeploymentUnit subdeployment : subdeployments) {
 73                final EEModuleDescription moduleDescription = subdeployment.getAttachment(EE_MODULE_DESCRIPTION);
 74                final ResourceRoot deploymentRoot = subdeployment.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
 75                if (moduleDescription == null) {
 76                    // Not an EE deployment.
 77                    continue;
 78                }
 79                for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
 80                    applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
 81                }
 82                for (final Map.Entry<String, String> messageDestination : moduleDescription.getMessageDestinations().entrySet()) {
 83                    applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentRoot.getRoot());
 84                }
 85                for (final ComponentDescription componentDescription : subdeployment.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
 86                    applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
 87                }
 88
 89                subdeployment.putAttachment(EE_APPLICATION_DESCRIPTION, applicationDescription);
 90            }
 91        } else if (deploymentUnit.getParent() == null) {
 92
 93            final EEApplicationDescription applicationDescription = new EEApplicationDescription();
 94            deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION, applicationDescription);
 95            /*
 96             * We are a top-level EE deployment, or a non-EE deployment.  Our "aggregate" index is just a copy of
 97             * our local EE module index.
 98             */
 99            final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
100            final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
101            if (moduleDescription == null) {
102                // Not an EE deployment.
103                return;
104            }
105            for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
106                applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
107            }
108            for (final Map.Entry<String, String> messageDestination : moduleDescription.getMessageDestinations().entrySet()) {
109                applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentRoot.getRoot());
110            }
111            for (final ComponentDescription componentDescription : deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
112                applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
113            }
114        }
115    }
116
117    public void undeploy(final DeploymentUnit context) {
118    }
119}