/*
 * Java core library component.
 *
 * Copyright (c) 1997, 1998
 *      Transvirtual Technologies, Inc.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file.
 */

package java.lang;

import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;

public abstract class ClassLoader {

/**
 * To prevent any classes from being gc'd before we are gc'd, we keep them
 * in this hashtable.  The contents of this table correspond to entries
 * in the VM-internal class entry pool.
 */
private Hashtable loadedClasses = new Hashtable();
private ClassLoader parent;

protected ClassLoader() {
	this(getBaseClassLoader());
}

protected ClassLoader(ClassLoader parent) {
	System.getSecurityManager().checkCreateClassLoader();
	this.parent = parent;
}

final protected Class defineClass(String name, byte data[], int offset, int length) throws ClassFormatError {
	Class clazz = defineClass0(name, data, offset, length);
	if (name != null) {
		loadedClasses.put(name, clazz);
	}
	else {
		loadedClasses.put(clazz.getName(), clazz);
	}
	return (clazz);
}

/**
 * @deprecated
 */
final protected Class defineClass(byte data[], int offset, int length) throws ClassFormatError {
	return (defineClass(null, data, offset, length));
}

final protected Class findLoadedClass(String name) {
	return (findLoadedClass0(name));
}

final protected Class findSystemClass(String name) throws ClassNotFoundException {
	return (findSystemClass0(name));
}

public URL getResource(String name) {
	return (null);	// Default implementation just returns null
}

public InputStream getResourceAsStream(String name) {
	return (null); // Default implementation just returns null
}

public static URL getSystemResource(String name) {
	try {
		return (new URL("system", "", 0, name));
	}
	catch (MalformedURLException _) {
		return (null);
	}
}

public static InputStream getSystemResourceAsStream(String name) {
	byte[] data = getSystemResourceAsBytes0(name);
	if (data == null) {
		return (null);
	}
	else {
		return (new ByteArrayInputStream(data));
	}
}

public Class loadClass(String name) throws ClassNotFoundException {
	return (loadClass(name, true));
}

protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
	Class cls = findLoadedClass(name);
	if (cls == null) {
		try {
			if (parent != null) {
				cls = parent.loadClass(name, resolve);
			}
			else {
				cls = findSystemClass(name);
			}
		}
		catch (ClassNotFoundException _) {
			cls = findLocalClass(name);
		}
	}
	if (resolve) {
		resolveClass(cls);
	}
	return (cls);
}

protected void checkPackageAccess(String name) throws SecurityException {
}

protected Class findLocalClass(String name) throws ClassNotFoundException {
	throw new ClassNotFoundException(name);
}

final protected void resolveClass(Class c) {
	resolveClass0(c);
}

final protected void setSigners(Class cl, Object signers[]) {
	// Signer's are not currently supported.
}

public ClassLoader getParent() {
	return (parent);
}

public final Enumeration getResources(String name) throws IOException {
	throw new kaffe.util.NotImplemented(ClassLoader.class.getName() + ".getResources(String)");
}


public Enumeration getLocalResources(String name) throws IOException {
	return (null);
}

public URL getLocalResource(String name) {
	return (null);
}

public static Enumeration getSystemResources(String name) throws IOException {
	throw new kaffe.util.NotImplemented(ClassLoader.class.getName() + ".getSystemResources(String)");
}

public static ClassLoader getBaseClassLoader() {
	return (null);
}

protected Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException {
	throw new kaffe.util.NotImplemented(ClassLoader.class.getName() + ".definePackage(String,String,String,String,String,String,String,URL");
}

protected Package getPackage(String name) {
	throw new kaffe.util.NotImplemented(ClassLoader.class.getName() + ".getPackage(String)");
}

protected Package[] getPackages() {
	throw new kaffe.util.NotImplemented(ClassLoader.class.getName() + ".getPackages()");
}

native private Class defineClass0(String name, byte data[], int offset, int length);
native private Class findSystemClass0(String name);
native private Class findLoadedClass0(String name);
native private void resolveClass0(Class cls);
/**
 *  This is not part of the public interface.
 */
native public static byte[] getSystemResourceAsBytes0(String name);

}

@@ -801,20 +801,22 @@
 this(get
-Base
+System
 ClassLoa
@@ -947,30 +947,24 @@
  parent;%0A%7D%0A%0A
-final 
 protected Cl
@@ -953,32 +953,38 @@
 t;%0A%7D%0A%0Aprotected 
+final 
 Class defineClas
@@ -1275,22 +1275,16 @@
 ted%0A */%0A
-final 
 protecte
@@ -1281,24 +1281,30 @@
 /%0Aprotected 
+final 
 Class define
@@ -1422,30 +1422,24 @@
 ength));%0A%7D%0A%0A
-final 
 protected Cl
@@ -1428,32 +1428,38 @@
 );%0A%7D%0A%0Aprotected 
+final 
 Class findLoaded
@@ -1512,30 +1512,24 @@
 (name));%0A%7D%0A%0A
-final 
 protected Cl
@@ -1518,32 +1518,38 @@
 );%0A%7D%0A%0Aprotected 
+final 
 Class findSystem
@@ -2936,30 +2936,24 @@
 n(name);%0A%7D%0A%0A
-final 
 protected vo
@@ -2946,24 +2946,30 @@
 %0A%0Aprotected 
+final 
 void resolve
@@ -3007,22 +3007,16 @@
 (c);%0A%7D%0A%0A
-final 
 protecte
@@ -3013,24 +3013,30 @@
 %0A%0Aprotected 
+final 
 void setSign
@@ -3117,24 +3117,30 @@
 .%0A%7D%0A%0Apublic 
+final 
 ClassLoader 
@@ -3347,160 +3347,8 @@
 %7D%0A%0A%0A
-public Enumeration getLocalResources(String name) throws IOException %7B%0A%09return (null);%0A%7D%0A%0Apublic URL getLocalResource(String name) %7B%0A%09return (null);%0A%7D%0A%0A
 publ
@@ -3553,20 +3553,22 @@
 ader get
-Base
+System
 ClassLoa

Update with respect to final JDK 1.2 API.