You could use the same idea for lazy loading. In your fallback loader, attempt to load the corresponding module. If it succeeds, add it as a dependency to the Module, and then relink the module; then retry the load.
OK, this would work.
protected LocalLoader doUpdate(String[] tokens)
{
Node<Import> current = root;
StringBuilder path = new StringBuilder();
for (String token : tokens)
{
current = current.getChild(token);
if (current == null)
return null;
if (path.length() > 0)
path.append(".");
path.append(token);
Import i = current.getValue();
if (i != null)
{
ModuleIdentifier mi = ModuleIdentifier.create(path.toString(), i.getVersion().toString());
ModuleDependencySpec.Builder mdsb = ModuleDependencySpec.build(mi).setOptional(i.isOptional());
if (i.isExport()) // TODO -- relink depending modules ...
mdsb.setExportFilter(PathFilters.acceptAll());
ModuleDependencySpec mds = mdsb.create();
DependencySpec dependencySpec = dependencyBuilder.addModuleDependency(mds).create();
try
{
Module module = Module.getModule(target);
loader.updateModule(module, dependencySpec);
return module.getModuleLocalLoader(); // <--------- HERE
}
catch (ModuleLoadException ignored)
{
return null;
}
}
}
return null;
}
but in order not to hack around too much, I would need somthing like "HERE".
Exposing too much if we expose ModuleClassLoader's LocalLoader?
btw: any tip on how to relink dependeing modules from TODO?