in hugegraph-common/src/main/java/org/apache/hugegraph/config/OptionSpace.java [45:94]
public static void register(String module, String holder) {
ClassLoader classLoader = OptionSpace.class.getClassLoader();
Class<?> clazz;
try {
clazz = classLoader.loadClass(holder);
} catch (ClassNotFoundException e) {
throw new ConfigException(
"Failed to load class of option holder '%s'", e, holder);
}
// Check subclass
if (!OptionHolder.class.isAssignableFrom(clazz)) {
throw new ConfigException(
"Class '%s' is not a subclass of OptionHolder", holder);
}
OptionHolder instance = null;
Exception exception = null;
try {
Method method = clazz.getMethod(INSTANCE_METHOD);
if (!Modifier.isStatic(method.getModifiers())) {
throw new NoSuchMethodException(INSTANCE_METHOD);
}
instance = (OptionHolder) method.invoke(null);
if (instance == null) {
exception = new ConfigException(
"Returned null from %s() method",
INSTANCE_METHOD);
}
} catch (NoSuchMethodException e) {
LOG.warn("Class {} does not has static method {}.",
holder, INSTANCE_METHOD);
exception = e;
} catch (InvocationTargetException e) {
LOG.warn("Can't call static method {} from class {}.",
INSTANCE_METHOD, holder);
exception = e;
} catch (IllegalAccessException e) {
LOG.warn("Illegal access while calling method {} from class {}.",
INSTANCE_METHOD, holder);
exception = e;
}
if (exception != null) {
throw new ConfigException("Failed to instantiate option holder: %s",
exception, holder);
}
register(module, instance);
}