Debian Codegraph @

rhino/src/org/mozilla/javascript/DefiningClassLoader.java

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package org.mozilla.javascript;
6
7 /**
8 * Load generated classes.
9 *
10 * @author Norris Boyd
11 */
12 public class DefiningClassLoader extends ClassLoader
13 implements GeneratedClassLoader
14 {
15 public DefiningClassLoader() {
16 this.parentLoader = getClass().getClassLoader();
17 }
18
19 public DefiningClassLoader(ClassLoader parentLoader) {
20 this.parentLoader = parentLoader;
21 }
22
23 public Class<?> defineClass(String name, byte[] data) {
24 // Use our own protection domain for the generated classes.
25 // TODO: we might want to use a separate protection domain for classes
26 // compiled from scripts, based on where the script was loaded from.
27 return super.defineClass(name, data, 0, data.length,
28 SecurityUtilities.getProtectionDomain(getClass()));
29 }
30
31 public void linkClass(Class<?> cl) {
32 resolveClass(cl);
33 }
34
35 @Override
36 public Class<?> loadClass(String name, boolean resolve)
37 throws ClassNotFoundException
38 {
39 Class<?> cl = findLoadedClass(name);
40 if (cl == null) {
41 if (parentLoader != null) {
42 cl = parentLoader.loadClass(name);
43 } else {
44 cl = findSystemClass(name);
45 }
46 }
47 if (resolve) {
48 resolveClass(cl);
49 }
50 return cl;
51 }
52
53 private final ClassLoader parentLoader;
54 }