public final class ComponentAggregationProcessor implements DeploymentUnitProcessor {
private static final Logger logger = Logger.getLogger(EEModuleConfigurationProcessor.class);
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (deploymentUnit.getAttachment(Attachments.DEPLOYMENT_TYPE) == DeploymentType.EAR) {
final EEApplicationDescription applicationDescription = new EEApplicationDescription();
deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION, applicationDescription);
final EEModuleDescription earDesc = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
if (earDesc != null) {
for (final Map.Entry<String, String> messageDestination : earDesc.getMessageDestinations().entrySet()) {
applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT).getRoot());
}
}
/*
* We are an EAR, so we must inspect all of our subdeployments and aggregate all their component views
* into a single index, so that inter-module resolution will work.
*/
// Add the application description
final List<DeploymentUnit> subdeployments = deploymentUnit.getAttachmentList(SUB_DEPLOYMENTS);
for (final DeploymentUnit subdeployment : subdeployments) {
final EEModuleDescription moduleDescription = subdeployment.getAttachment(EE_MODULE_DESCRIPTION);
final ResourceRoot deploymentRoot = subdeployment.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
if (moduleDescription == null) {
// Not an EE deployment.
continue;
}
for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
}
for (final Map.Entry<String, String> messageDestination : moduleDescription.getMessageDestinations().entrySet()) {
applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentRoot.getRoot());
}
for (final ComponentDescription componentDescription : subdeployment.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
}
subdeployment.putAttachment(EE_APPLICATION_DESCRIPTION, applicationDescription);
}
} else if (deploymentUnit.getParent() == null) {
final EEApplicationDescription applicationDescription = new EEApplicationDescription();
deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION, applicationDescription);
/*
* We are a top-level EE deployment, or a non-EE deployment. Our "aggregate" index is just a copy of
* our local EE module index.
*/
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
if (moduleDescription == null) {
// Not an EE deployment.
return;
}
for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
}
for (final Map.Entry<String, String> messageDestination : moduleDescription.getMessageDestinations().entrySet()) {
applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentRoot.getRoot());
}
for (final ComponentDescription componentDescription : deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
}
}
}