84 |
* <p>The bootstrap classloader in GNU Classpath is implemented as a couple of |
* <p>The bootstrap classloader in GNU Classpath is implemented as a couple of |
85 |
* static (native) methods on the package private class |
* static (native) methods on the package private class |
86 |
* <code>java.lang.VMClassLoader</code>, the system classloader is an |
* <code>java.lang.VMClassLoader</code>, the system classloader is an |
87 |
* instance of <code>gnu.java.lang.SystemClassLoader</code> |
* anonymous inner class of ClassLoader and a subclass of |
88 |
* (which is a subclass of <code>java.net.URLClassLoader</code>). |
* <code>java.net.URLClassLoader</code>. |
89 |
* |
* |
90 |
* <p>Users of a <code>ClassLoader</code> will normally just use the methods |
* <p>Users of a <code>ClassLoader</code> will normally just use the methods |
91 |
* <ul> |
* <ul> |
151 |
private final boolean initialized; |
private final boolean initialized; |
152 |
|
|
153 |
/** |
/** |
|
* System/Application classloader: defaults to an instance of |
|
|
* gnu.java.lang.SystemClassLoader, unless the first invocation of |
|
|
* getSystemClassLoader loads another class loader because of the |
|
|
* java.system.class.loader property. The initialization of this field |
|
|
* is somewhat circular - getSystemClassLoader() checks whether this |
|
|
* field is null in order to bypass a security check. |
|
|
*/ |
|
|
static final ClassLoader systemClassLoader = |
|
|
VMClassLoader.getSystemClassLoader(); |
|
|
|
|
|
/** |
|
154 |
* The default protection domain, used when defining a class with a null |
* The default protection domain, used when defining a class with a null |
155 |
* paramter for the domain. |
* paramter for the domain. |
156 |
*/ |
*/ |
211 |
*/ |
*/ |
212 |
protected ClassLoader() throws SecurityException |
protected ClassLoader() throws SecurityException |
213 |
{ |
{ |
214 |
this(systemClassLoader); |
this(System.systemClassLoader); |
215 |
} |
} |
216 |
|
|
217 |
/** |
/** |
460 |
protected final Class findSystemClass(String name) |
protected final Class findSystemClass(String name) |
461 |
throws ClassNotFoundException |
throws ClassNotFoundException |
462 |
{ |
{ |
463 |
return Class.forName(name, false, systemClassLoader); |
return Class.forName(name, false, System.systemClassLoader); |
464 |
} |
} |
465 |
|
|
466 |
/** |
/** |
622 |
*/ |
*/ |
623 |
public static final URL getSystemResource(String name) |
public static final URL getSystemResource(String name) |
624 |
{ |
{ |
625 |
return systemClassLoader.getResource(name); |
return System.systemClassLoader.getResource(name); |
626 |
} |
} |
627 |
|
|
628 |
/** |
/** |
638 |
*/ |
*/ |
639 |
public static Enumeration getSystemResources(String name) throws IOException |
public static Enumeration getSystemResources(String name) throws IOException |
640 |
{ |
{ |
641 |
return systemClassLoader.getResources(name); |
return System.systemClassLoader.getResources(name); |
642 |
} |
} |
643 |
|
|
644 |
/** |
/** |
693 |
|
|
694 |
/** |
/** |
695 |
* Returns the system classloader. The system classloader (also called |
* Returns the system classloader. The system classloader (also called |
696 |
* the application classloader) is the classloader that was used to |
* the application classloader) is the classloader that is used to |
697 |
* load the application classes on the classpath (given by the system |
* load the application classes on the classpath (given by the system |
698 |
* property <code>java.class.path</code>. This is set as the context |
* property <code>java.class.path</code>. This is set as the context |
699 |
* class loader for a thread. The system property |
* class loader for a thread. The system property |
700 |
* <code>java.system.class.loader</code>, if defined, is taken to be the |
* <code>java.system.class.loader</code>, if defined, is taken to be the |
701 |
* name of the class to use as the system class loader, which must have |
* name of the class to use as the system class loader, which must have |
702 |
* a public constructor which takes a ClassLoader as a parent; otherwise this |
* a public constructor which takes a ClassLoader as a parent. The parent |
703 |
* uses gnu.java.lang.SystemClassLoader. |
* class loader passed in the constructor is the default system class |
704 |
|
* loader. |
705 |
* |
* |
706 |
* <p>Note that this is different from the bootstrap classloader that |
* <p>Note that this is different from the bootstrap classloader that |
707 |
* actually loads all the real "system" classes (the bootstrap classloader |
* actually loads all the real "system" classes. |
|
* is the parent of the returned system classloader). |
|
708 |
* |
* |
709 |
* <p>A security check will be performed for |
* <p>A security check will be performed for |
710 |
* <code>RuntimePermission("getClassLoader")</code> if the calling class |
* <code>RuntimePermission("getClassLoader")</code> if the calling class |
724 |
{ |
{ |
725 |
Class c = VMSecurityManager.getClassContext()[1]; |
Class c = VMSecurityManager.getClassContext()[1]; |
726 |
ClassLoader cl = c.getClassLoader(); |
ClassLoader cl = c.getClassLoader(); |
727 |
if (cl != null && cl != systemClassLoader) |
if (cl != null && cl != System.systemClassLoader) |
728 |
sm.checkPermission(new RuntimePermission("getClassLoader")); |
sm.checkPermission(new RuntimePermission("getClassLoader")); |
729 |
} |
} |
730 |
|
|
731 |
return systemClassLoader; |
return System.systemClassLoader; |
732 |
} |
} |
733 |
|
|
734 |
/** |
/** |