public GraphClassLoader newClassLoader(GraphClassLoaderRegistry classLoaderRegistry, DependencyManager dependencyManager, ModuleDefinition moduleDefinition) {
String moduleName = moduleDefinition.getName();
//use registered class loader if it already exists
GraphClassLoader classLoader = classLoaderRegistry.getClassLoader(moduleName);
if (classLoader != null) {
return classLoader;
}
//create new resource loader for current module definition
ClassRetriever moduleClassResourceRetriever = newModuleClassResourceRetriever(moduleDefinition);
List<ModuleDefinition> dependencies = dependencyManager.getOrderedModuleDependencies(moduleDefinition.getName());
//add list of dependent class loaders
List<GraphClassLoader> classLoaders = new ArrayList<GraphClassLoader>();
for (ModuleDefinition dependency : dependencies) {
if (dependency.getName().equals(moduleDefinition.getName())) continue;
classLoaders.add(newClassLoader(classLoaderRegistry, dependencyManager, dependency));
}
//set up parent class loader
ClassLoader parentClassLoader = classLoaderRegistry.getApplicationClassLoader();
ClassLoader parentClassLoaderToUse = parentClassLoader != null ? parentClassLoader : GraphClassLoaderFactory.class.getClassLoader();
//get third party package to resource mapping. Question: do we need to restrict to packages
ClassRetriever moduleLibraryResourceRetriever = newModuleLibraryResourceRetriever(moduleDefinition);
GraphClassLoader gcl = newGraphClassLoader(moduleDefinition, moduleClassResourceRetriever, moduleLibraryResourceRetriever, classLoaders, parentClassLoaderToUse);
classLoaderRegistry.addClassLoader(moduleDefinition.getName(), gcl);
return gcl;
}