{
// Find all the metadata types assoc w/ unit that specify a moduleName
List<NamedModule> metadatas = null;
for (Class<? extends NamedModule> type : inputTypes)
{
NamedModule nm = unit.getAttachment(type);
if (nm != null)
{
if (metadatas == null)
{
metadatas = new ArrayList<NamedModule>();
}
metadatas.add(nm);
}
}
if (metadatas == null)
{
return;
}
String moduleName = null;
// See if any of the existing metadata specifies a module name
for (NamedModule nm : metadatas)
{
moduleName = nm.getModuleName();
if (moduleName != null)
{
break;
}
}
// Enforce EAR rules from EE 6 EE.8.1.1
JBossAppMetaData appMetaData = null;
DeploymentUnit parent = unit.getParent();
if (parent != null)
{
appMetaData = parent.getAttachment(JBossAppMetaData.class);
}
if (appMetaData != null)
{
moduleName = establishUniqueModuleName(unit, moduleName, appMetaData);
}
else if (moduleName == null)
{
// Not in an EAR and no name was configured.
// Create a default module name as per EE 6 EE.8.1.2:
// "when a stand-alone module is deployed.... [t]he module name can be
// explicitly set in the module deployment descriptor. If not set, the
// name of the module is the base name of the module file with any
// extension (.war, .jar, .rar) removed and with any directory names removed."
moduleName = trimExtension(unit.getSimpleName());
}
// Apply the name to all metadata
for (NamedModule nm : metadatas)
{
nm.setModuleName(moduleName);
}
// Let other deployers get the module name w/o having to search
// for all the possible metadata types
unit.addAttachment(NamedModule.class, metadatas.get(0));