Move code to try to load a class from getPkgProperty to the separated findClass method and add catching of SecurityException there.

This commit is contained in:
igor%mir2.org 2002-12-30 00:49:11 +00:00
parent 6c08e83f5d
commit 25a4f559fd

View File

@ -210,27 +210,22 @@ public class NativeJavaPackage extends ScriptableObject {
: packageName + "." + name;
Context cx = Context.getContext();
ClassShutter shutter = cx.getClassShutter();
Scriptable newValue;
try {
if (shutter != null && !shutter.visibleToScripts(newPackage))
throw new ClassNotFoundException();
Class newClass = classLoader != null
? classLoader.loadClass(newPackage)
: ScriptRuntime.loadClassName(newPackage);
newValue = new NativeJavaClass(getTopLevelScope(this), newClass);
newValue.setParentScope(this);
newValue.setPrototype(this.prototype);
} catch (ClassNotFoundException ex) {
if (createPkg) {
NativeJavaPackage pkg = new NativeJavaPackage(newPackage,
classLoader);
pkg.setParentScope(this);
pkg.setPrototype(this.prototype);
newValue = pkg;
} else {
newValue = null;
Scriptable newValue = null;
if (shutter == null || shutter.visibleToScripts(newPackage)) {
Class cl = findClass(classLoader, newPackage);
if (cl != null) {
newValue = new NativeJavaClass(getTopLevelScope(this), cl);
newValue.setParentScope(this);
newValue.setPrototype(this.prototype);
}
}
if (newValue == null && createPkg) {
NativeJavaPackage pkg = new NativeJavaPackage(newPackage,
classLoader);
pkg.setParentScope(this);
pkg.setPrototype(this.prototype);
newValue = pkg;
}
if (newValue != null) {
// Make it available for fast lookup and sharing of
// lazily-reflected constructors and static members.
@ -277,6 +272,19 @@ public class NativeJavaPackage extends ScriptableObject {
Context.getMessage0("msg.not.java.obj"));
}
private static Class findClass(ClassLoader loader, String className) {
try {
if (loader != null) {
return loader.loadClass(className);
} else {
return ScriptRuntime.loadClassName(className);
}
} catch (ClassNotFoundException ex) {
} catch (SecurityException ex) {
}
return null;
}
private String packageName;
private ClassLoader classLoader;
}