*/
public final class ComponentAggregationProcessor implements DeploymentUnitProcessor {
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEApplicationDescription applicationDescription = new EEApplicationDescription();
if (deploymentUnit.getAttachment(Attachments.DEPLOYMENT_TYPE) == DeploymentType.EAR) {
/*
* 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 (DeploymentUnit subdeployment : subdeployments) {
final EEModuleDescription moduleDescription = subdeployment.getAttachment(EE_MODULE_DESCRIPTION);
if (moduleDescription == null) {
// Not an EE deployment.
continue;
}
for (AbstractComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
applicationDescription.addComponent(componentDescription);
}
subdeployment.putAttachment(EE_APPLICATION_DESCRIPTION, applicationDescription);
}
} else if (deploymentUnit.getParent() == null) {
/*
* 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 EEModuleDescription moduleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
if (moduleDescription == null) {
// Not an EE deployment.
return;
}
for (AbstractComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
applicationDescription.addComponent(componentDescription);
}
deploymentUnit.putAttachment(EE_APPLICATION_DESCRIPTION, applicationDescription);
}
}