From cb07068ba10b64b32548b7ccc1c2baa45f96d72c Mon Sep 17 00:00:00 2001 From: green Date: Sun, 26 Nov 2000 03:58:56 +0000 Subject: 2000-11-25 Anthony Green * prims.cc (_Jv_NewObjectArray): Undo placement change. (_Jv_NewPrimArray): Likewise. * gcj/array.h (__JArray): Undo const change. Removed constructor. (class JArray): Removed constructor. * java/lang/Thread.java (context_class_loader): New private data. (getContextClassLoader): New method. (setContextClassLoader): New method. (Thread): Initialize context_class_loader. * java/net/URLClassLoader.java: Import java.util.Enumeration. (getResource): Rename to findResource. (findResource): New method. Used to be getResource. (getResourceAsStream): Deleted. (jarFileize): Extracted logic from URLClassLoader constructor into this new private method. (addURL): New protected method. (URLClassLoader): Call jarFileize. Use addElement instead of insertElementAt. (findResources): New method. * java/lang/ClassLoader.java: Import java.util.Enumeration. (getResource): Implement correct logic. (findResource): New method. (getResources): New method. (findClass): Create a ClassNotFoundException with the name of the class rather than nothing at all. (defineClass) Only throw ClassFormatError. * java/lang/Class.java (forName): New method. * java/lang/Class.h (forName): New method. * java/lang/natClass.cc (forName): New method. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@37751 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/java/lang/ClassLoader.java | 76 ++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 12 deletions(-) (limited to 'libjava/java/lang/ClassLoader.java') diff --git a/libjava/java/lang/ClassLoader.java b/libjava/java/lang/ClassLoader.java index 90f852ef6c9..de9560317a2 100644 --- a/libjava/java/lang/ClassLoader.java +++ b/libjava/java/lang/ClassLoader.java @@ -11,8 +11,10 @@ details. */ package java.lang; import java.io.InputStream; +import java.io.IOException; import java.net.URL; import java.net.URLConnection; +import java.util.Enumeration; import java.util.Stack; /** @@ -132,7 +134,7 @@ public abstract class ClassLoader { protected Class findClass (String name) throws ClassNotFoundException { - throw new ClassNotFoundException (); + throw new ClassNotFoundException (name); } /** @@ -154,7 +156,7 @@ public abstract class ClassLoader { * @exception java.lang.LinkageError * @see ClassLoader#defineClass(String,byte[],int,int) */ protected final Class defineClass(byte[] data, int off, int len) - throws java.lang.ClassNotFoundException, java.lang.LinkageError + throws ClassFormatError { return defineClass (null, data, off, len); } @@ -188,7 +190,7 @@ public abstract class ClassLoader { byte[] data, int off, int len) - throws java.lang.ClassNotFoundException, java.lang.LinkageError + throws ClassFormatError { if (data==null || data.length < off+len || off<0 || len<0) throw new ClassFormatError ("arguments to defineClass " @@ -207,10 +209,7 @@ public abstract class ClassLoader { return defineClass0 (name, data, off, len); - } catch (java.lang.LinkageError x) { - throw x; // rethrow - - } catch (java.lang.ClassNotFoundException x) { + } catch (ClassFormatError x) { throw x; // rethrow } catch (java.lang.VirtualMachineError x) { @@ -223,7 +222,7 @@ public abstract class ClassLoader { + "while defining class " + name + ": " + x.toString ()); - } + } } /** This is the entry point of defineClass into the native code */ @@ -231,7 +230,7 @@ public abstract class ClassLoader { byte[] data, int off, int len) - throws java.lang.ClassNotFoundException, java.lang.LinkageError; + throws ClassFormatError; /** @@ -356,8 +355,8 @@ public abstract class ClassLoader { if (res == null) return null; return res.openStream (); } catch (java.io.IOException x) { - return null; - } + return null; + } } /** @@ -369,9 +368,62 @@ public abstract class ClassLoader { * @see java.lang.ClassLoader#getResourceAsStream(String) * @see java.io.URL */ - public URL getResource(String name) { + public URL getResource (String name) + { + // The rules say search the parent class if non-null, + // otherwise search the built-in class loader (assumed to be + // the system ClassLoader). If not found, call + // findResource(). + URL result = null; + + ClassLoader delegate = parent; + + if (delegate == null) + delegate = getSystemClassLoader (); + + // Protect ourselves from looping. + if (this != delegate) + result = delegate.getResource (name); + + if (result != null) + return result; + else + return findResource (name); + } + + protected URL findResource (String name) + { + // Default to returning null. Derived classes implement this. return null; } + public Enumeration getResources (String name) throws IOException + { + // The rules say search the parent class if non-null, + // otherwise search the built-in class loader (assumed to be + // the system ClassLoader). If not found, call + // findResource(). + Enumeration result = null; + + ClassLoader delegate = parent; + + if (delegate == null) + delegate = getSystemClassLoader (); + + // Protect ourselves from looping. + if (this != delegate) + result = delegate.getResources (name); + + if (result != null) + return result; + else + return findResources (name); + } + + protected Enumeration findResources (String name) throws IOException + { + // Default to returning null. Derived classes implement this. + return null; + } } -- cgit v1.2.1