boolean hasCp = (cpFiles != null && cpFiles.isEmpty() == false);
WebBeanDiscoveryEnvironment environment = null;
if (hasWB || hasCp)
{
VFSDeploymentUnit topUnit = unit.getTopLevel();
environment = topUnit.getAttachment(WebBeanDiscoveryEnvironment.class);
if (environment == null)
{
environment = new WebBeanDiscoveryEnvironment();
topUnit.addAttachment(WebBeanDiscoveryEnvironment.class, environment);
}
}
try
{
if (hasWB)
{
for (VirtualFile file : wbFiles)
environment.addWebBeansXmlURL(file.toURL());
}
if (hasCp)
{
Module module = unit.getAttachment(Module.class);
if (module == null)
{
VFSDeploymentUnit parent = unit.getParent();
while (parent != null && module == null)
{
module = parent.getAttachment(Module.class);
parent = parent.getParent();
}
if (module == null)
throw new DeploymentException("No module in deployment unit's hierarchy: " + unit.getName());
}