use of lucee.commons.io.SystemUtil.Caller in project Lucee by lucee.
the class EnvClassLoader method load.
private synchronized Object load(String name, short type, boolean doLog) {
Object obj = null;
// first we check the callers classpath
Caller caller = SystemUtil.getCallerClass();
if (!caller.isEmpty()) {
// if the request comes from classpath
Class clazz = caller.fromClasspath();
if (clazz != null) {
if (clazz.getClassLoader() != null) {
obj = _load(clazz.getClassLoader(), name, type);
if (obj == null && clazz.getClassLoader() instanceof PhysicalClassLoader && clazz != caller.fromBootDelegation && caller.fromBootDelegation != null & caller.fromBootDelegation.getClassLoader() != null) {
obj = _load(caller.fromBootDelegation.getClassLoader(), name, type);
}
}
}
if (obj == null && caller.fromBundle != null) {
if (caller.fromBundle.getClassLoader() != null)
obj = _load(caller.fromBundle.getClassLoader(), name, type);
}
if (obj != null)
return obj;
}
// now we check in the core for the class (this includes all jars loaded by the core)
if ((caller.isEmpty() || caller.fromBundle != null) && caller.fromBundle.getClassLoader() != getParent()) {
obj = _load(getParent(), name, type);
if (obj != null) {
return obj;
}
}
// now we check extension bundles
if (caller.isEmpty() || /*PATCH LDEV-1312*/
(ThreadLocalPageContext.get() == null) || /* if we are in a child threads*/
caller.fromBundle != null) {
Bundle[] bundles = ConfigWebUtil.getEngine(config).getBundleContext().getBundles();
Bundle b = null;
for (int i = 0; i < bundles.length; i++) {
b = bundles[i];
if (b != null && !OSGiUtil.isFrameworkBundle(b)) {
try {
if (type == CLASS)
obj = b.loadClass(name);
else if (type == URL)
obj = b.getResource(name);
else {
java.net.URL url = b.getResource(name);
if (url != null)
obj = url.openStream();
}
if (obj != null)
break;
} catch (Exception e) {
obj = null;
}
}
}
if (obj != null) {
return obj;
}
}
if (caller.fromClasspath() != null) {
ClassLoader loader = CFMLEngineFactory.class.getClassLoader();
obj = _load(loader, name, type);
if (obj != null) {
// print.e("found in classpath:"+name+"->");
return obj;
}
}
return obj;
}
Aggregations