org.snapscript.core.ContextClassLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.core;
public class ContextClassLoader extends ClassLoader {
private final Class type;
public ContextClassLoader(Class type) {
this.type = type;
}
@Override
public Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
ClassLoader loader = type.getClassLoader();
try{
return loader.loadClass(name);
} catch(ClassNotFoundException cause) {
Thread thread = Thread.currentThread();
ClassLoader context = thread.getContextClassLoader();
if(context != loader) {
return context.loadClass(name);
}
throw cause;
}
}
}