38 |
|
|
39 |
package java.lang; |
package java.lang; |
40 |
|
|
41 |
import java.lang.reflect.*; |
import java.io.InputStream; |
42 |
import gnu.java.lang.*; |
import java.io.IOException; |
43 |
import java.io.*; |
import java.net.URL; |
44 |
import java.net.*; |
import java.security.CodeSource; |
45 |
import java.security.*; |
import java.security.PermissionCollection; |
46 |
import java.util.*; |
import java.security.Policy; |
47 |
|
import java.security.ProtectionDomain; |
48 |
|
import java.util.Enumeration; |
49 |
|
import java.util.HashMap; |
50 |
|
import java.util.Map; |
51 |
import gnu.java.util.DoubleEnumeration; |
import gnu.java.util.DoubleEnumeration; |
52 |
import gnu.java.util.EmptyEnumeration; |
import gnu.java.util.EmptyEnumeration; |
53 |
|
|
80 |
* <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 |
81 |
* static (native) methods on the package private class |
* static (native) methods on the package private class |
82 |
* <code>java.lang.VMClassLoader</code>, the system classloader is an |
* <code>java.lang.VMClassLoader</code>, the system classloader is an |
83 |
* instance of <code>gnu.java.lang.SystemClassloader</code> |
* instance of <code>gnu.java.lang.SystemClassLoader</code> |
84 |
* (which is a subclass of <code>java.net.URLClassLoader</code>). |
* (which is a subclass of <code>java.net.URLClassLoader</code>). |
85 |
* |
* |
86 |
* <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 |
117 |
*/ |
*/ |
118 |
public abstract class ClassLoader |
public abstract class ClassLoader |
119 |
{ |
{ |
120 |
/** All classes loaded by this classloader. */ |
/** |
121 |
private final Map loadedClasses = new HashMap(); |
* All classes loaded by this classloader. VM's may choose to implement |
122 |
|
* this cache natively; but it is here available for use if necessary. It |
123 |
|
* is not private in order to allow native code (and trusted subclasses) |
124 |
|
* access to this field. |
125 |
|
*/ |
126 |
|
final Map loadedClasses = new HashMap(); |
127 |
|
|
128 |
/** All packages defined by this classloader. */ |
/** |
129 |
private final Map definedPackages = new HashMap(); |
* All packages defined by this classloader. It is not private in order to |
130 |
|
* allow native code (and trusted subclasses) access to this field. |
131 |
|
*/ |
132 |
|
final Map definedPackages = new HashMap(); |
133 |
|
|
134 |
/** |
/** |
135 |
* The classloader that is consulted before this classloader. |
* The classloader that is consulted before this classloader. |
141 |
* System/Application classloader: defaults to an instance of |
* System/Application classloader: defaults to an instance of |
142 |
* gnu.java.lang.SystemClassLoader, unless the first invocation of |
* gnu.java.lang.SystemClassLoader, unless the first invocation of |
143 |
* getSystemClassLoader loads another class loader because of the |
* getSystemClassLoader loads another class loader because of the |
144 |
* java.system.class.loader property. |
* java.system.class.loader property. The initialization of this field |
145 |
* |
* is somewhat circular - getSystemClassLoader() checks whether this |
146 |
* XXX - The VM may needs to modify this field or set it to something |
* field is null in order to bypass a security check. |
|
* else, until gnu.java.lang.SystemClassLoader is correctly implemented. |
|
147 |
*/ |
*/ |
148 |
static final ClassLoader systemClassLoader = getSystemClassLoader(); |
static final ClassLoader systemClassLoader = getSystemClassLoader(); |
149 |
|
|
496 |
*/ |
*/ |
497 |
protected final Class findLoadedClass(String name) |
protected final Class findLoadedClass(String name) |
498 |
{ |
{ |
499 |
|
// NOTE: If the VM is keeping its own cache, it may make sense to have |
500 |
|
// this method be native. |
501 |
return (Class) loadedClasses.get(name); |
return (Class) loadedClasses.get(name); |
502 |
} |
} |
503 |
|
|
609 |
*/ |
*/ |
610 |
public static final URL getSystemResource(String name) |
public static final URL getSystemResource(String name) |
611 |
{ |
{ |
612 |
//XXX This should be: |
return getSystemClassLoader().getResource(name); |
|
// return getSystemClassLoader().getResource(name); |
|
|
if (name.startsWith("/")) |
|
|
name = name.substring(1); |
|
|
String cp = System.getProperty("java.class.path"); |
|
|
if (cp == null) |
|
|
return null; |
|
|
|
|
|
StringTokenizer st = new StringTokenizer(cp, File.pathSeparator); |
|
|
while (st.hasMoreTokens()) |
|
|
{ |
|
|
String path = st.nextToken(); |
|
|
if (path.toLowerCase().endsWith(".zip") || |
|
|
path.toLowerCase().endsWith(".jar")) |
|
|
return null; // Not implemented yet |
|
|
File f; |
|
|
if (path.endsWith(File.separator)) |
|
|
f = new File(path + name); |
|
|
else |
|
|
f = new File(path + File.separator + name); |
|
|
|
|
|
if (f.exists()) |
|
|
try |
|
|
{ |
|
|
return new URL("file://" + f.getAbsolutePath()); |
|
|
} |
|
|
catch (MalformedURLException e) |
|
|
{ |
|
|
return null; |
|
|
} |
|
|
} |
|
|
return null; |
|
613 |
} |
} |
614 |
|
|
615 |
/** |
/** |
688 |
* name of the class to use as the system class loader, otherwise this |
* name of the class to use as the system class loader, otherwise this |
689 |
* uses gnu.java.lang.SystemClassLoader. |
* uses gnu.java.lang.SystemClassLoader. |
690 |
* |
* |
|
* XXX - overriding the class loader does not currently work |
|
|
* |
|
691 |
* <p>Note that this is different from the bootstrap classloader that |
* <p>Note that this is different from the bootstrap classloader that |
692 |
* actually loads all the real "system" classes (the bootstrap classloader |
* actually loads all the real "system" classes (the bootstrap classloader |
693 |
* is the parent of the returned system classloader). |
* is the parent of the returned system classloader). |
709 |
// for java.system.class.loader. |
// for java.system.class.loader. |
710 |
if (systemClassLoader == null) |
if (systemClassLoader == null) |
711 |
{ |
{ |
712 |
// XXX return SystemClassLoader.getInstance(); |
String loader = System.getProperty("java.system.class.loader", |
713 |
|
"gnu.java.lang.SystemClassLoader"); |
714 |
|
try |
715 |
|
{ |
716 |
|
return (ClassLoader) Class.forName(loader).newInstance(); |
717 |
|
} |
718 |
|
catch (Exception e) |
719 |
|
{ |
720 |
|
throw (Error) new InternalError |
721 |
|
("System class loader could not be found: " + e).initCause(e); |
722 |
|
} |
723 |
} |
} |
724 |
// Check if we may return the system classloader |
// Check if we may return the system classloader |
725 |
SecurityManager sm = System.getSecurityManager(); |
SecurityManager sm = System.getSecurityManager(); |