public void setupPackages(ClassLoader cl) throws Exception {
final String JAVA_PACKAGE = "JavaPackage";
if (classLoader != cl) {
classLoader = cl;
Scriptable newPackages = new NativeJavaPackage("", cl);
newPackages.setParentScope(this);
newPackages.setPrototype(ScriptableObject.getClassPrototype(this, JAVA_PACKAGE));
super.put("Packages", this, newPackages);
for (int i = 0; i < BUILTIN_PACKAGES.length; i++) {
String pkgName = BUILTIN_PACKAGES[i];
Scriptable pkg = new NativeJavaPackage(pkgName, cl);
pkg.setParentScope(this);
pkg.setPrototype(ScriptableObject.getClassPrototype(this, JAVA_PACKAGE));
super.put(pkgName, this, pkg);
}
}
}