if (classLoader == null) {
classLoader = Objects.firstNonNull(Thread.currentThread().getContextClassLoader(), getClass().getClassLoader());
}
DatasetDefinitionRegistry registry = registryFactory.create();
List<DatasetModuleMeta> modulesToLoad = implementationInfo.getModules();
for (DatasetModuleMeta moduleMeta : modulesToLoad) {
// adding dataset module jar to classloader
try {
classLoader = typeLoader.create(moduleMeta, classLoader);
} catch (IOException e) {
LOG.error("Was not able to init classloader for module {} while trying to load type {}",
moduleMeta, implementationInfo, e);
throw Throwables.propagate(e);
}
Class<?> moduleClass;
// try program class loader then cdap class loader
try {
moduleClass = ClassLoaders.loadClass(moduleMeta.getClassName(), classLoader, this);
} catch (ClassNotFoundException e) {
try {
moduleClass = ClassLoaders.loadClass(moduleMeta.getClassName(), null, this);
} catch (ClassNotFoundException e2) {
LOG.error("Was not able to load dataset module class {} while trying to load type {}",
moduleMeta.getClassName(), implementationInfo, e);
throw Throwables.propagate(e);
}
}
try {
DatasetModule module = DatasetModules.getDatasetModule(moduleClass);
module.register(registry);
} catch (Exception e) {
LOG.error("Was not able to load dataset module class {} while trying to load type {}",
moduleMeta.getClassName(), implementationInfo, e);
throw Throwables.propagate(e);
}
}
return (T) new DatasetType(registry.get(implementationInfo.getName()), classLoader);
}