throw new IllegalStateException("Item not resolved: " + item);
// Dynamic requirement, create it lazily
if (requirement.isDynamic())
{
DelegateLoader delegate = createLazyDelegateLoader(checkDomain(), item);
delegate.setImportType(getImportType(requirement));
dynamic.add(delegate);
continue;
}
Module iDependOnModule = item.getResolvedModule();
if (iDependOnModule == null)
{
// Do it the hard way - probably optional or a self dependency?
String name = (String) item.getIDependOn();
if (name != null)
iDependOnModule = checkDomain().getModule(name);
if (iDependOnModule == null)
{
if (requirement.isOptional())
continue;
throw new IllegalStateException("Module not found for requirement: " + item);
}
}
// Check for re-export by the module
if (requirement.wantReExports())
addDelegates(iDependOnModule, delegates, dynamic, visited, true);
// Only add a the delegate if this is not a self-dependency
if (iDependOnModule != module)
{
// If we are connecting to another module we collect the imported package names per delegate
if (requirement instanceof PackageRequirement)
{
List<String> packageNames = delegateToRequiredPackages.get(iDependOnModule);
if (packageNames == null)
{
packageNames = new ArrayList<String>();
delegateToRequiredPackages.put(iDependOnModule, packageNames);
}
PackageRequirement packageRequirement = (PackageRequirement)requirement;
packageNames.add(packageRequirement.getName());
}
else
{
// Determine the delegate loader for the module
DelegateLoader delegate = iDependOnModule.getDelegateLoader(module, requirement);
if (delegate == null)
throw new IllegalStateException("Cannot obtain delegate for: " + requirement);
delegate.setImportType(getImportType(requirement));
delegates.add(delegate);
}
}
}
}
// Add FilteredDelegateLoaders for all collected package requirements
for (Entry<Module, List<String>> entry : delegateToRequiredPackages.entrySet())
{
Module iDependOnModule = entry.getKey();
DelegateLoader delegate = iDependOnModule.getDelegateLoader(module, entry.getValue());
delegates.add(delegate);
}
}