if(children != null && modules != null)
{
for(DeploymentUnit child : children)
{
String moduleName = child.getSimpleName();
ModuleMetaData module = modules.get(moduleName);
if(module != null && module.getAlternativeDD() != null)
{
VirtualFile altDDFile = unit.getRoot().getChild(module.getAlternativeDD());
if(altDDFile == null)
throw new IllegalStateException("Failed to locate alternative DD '" + module.getAlternativeDD() + "' in " + unit.getRoot().getPathName());
String attachmentName;
if(module.getType() == ModuleMetaData.ModuleType.Ejb)
attachmentName = EjbJarMetaData.class.getName();
else if(module.getType() == ModuleMetaData.ModuleType.Web)
attachmentName = WebMetaData.class.getName();
else if(module.getType() == ModuleMetaData.ModuleType.Client)
attachmentName = ApplicationClientMetaData.class.getName();
else if(module.getType() == ModuleMetaData.ModuleType.Connector)
attachmentName = "org.jboss.resource.metadata.ConnectorMetaData";
else
throw new IllegalStateException("Expected module types in an EAR are ejb, web, java and connector but got " + module.getType() + " for " + child.getName() + " in " + unit.getName());
child.addAttachment(attachmentName + ".altDD", altDDFile);
if(log.isTraceEnabled())
log.trace("attached alt-dd " + altDDFile + " for module " + child.getSimpleName());
}