/** Global bindings associated with script engines created by this manager. */
private Bindings globalScope;
private boolean canCallerAccessLoader(ClassLoader loader) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
ClassLoader callerLoader = getCallerClassLoader();
if (callerLoader != null) {
if (loader != callerLoader || !isAncestor(loader, callerLoader)) {
try {
sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
} catch (SecurityException exp) {
if (DEBUG) exp.printStackTrace();
return false;
}
} // else fallthru..
} // else fallthru..
} // else fallthru..
return true;
}
// Note that this code is same as ClassLoader.getCallerClassLoader().
// But, that method is package private and hence we can't call here.
private ClassLoader getCallerClassLoader() {
Class caller = Reflection.getCallerClass(3);
if (caller == null) {
return null;
}
return caller.getClassLoader();
}
// is cl1 ancestor of cl2?
private boolean isAncestor(ClassLoader cl1, ClassLoader cl2) {
do {
cl2 = cl2.getParent();
if (cl1 == cl2) return true;
} while (cl2 != null);
return false;
}
}
=5=
THE END |