public abstract class ClassLoader extends Object
Modifier and Type | Field and Description |
---|---|
protected Hashtable |
packages
The packages which have been defined by this ClassLoader.
|
Modifier | Constructor and Description |
---|---|
protected |
ClassLoader()
Any ClassLoader created using the default constructor will
have as its parent the system ClassLoader.
|
protected |
ClassLoader(ClassLoader parent)
This new-to-Java-1.2 constructor allows the parent to be
specified by the caller.
|
Modifier and Type | Method and Description |
---|---|
void |
clearAssertionStatus()
Clear the assertion status settings for all classes and packages,
and the default.
|
protected Class |
defineClass(byte[] data,
int offset,
int length)
Deprecated.
Replaced by defineClass(String, byte[], int, int)
|
protected Class |
defineClass(String classname,
byte[] data,
int offset,
int length)
If no ProtectionDomain is specified, the default domain is used.
|
protected Class |
defineClass(String classname,
byte[] data,
int offset,
int length,
ProtectionDomain pd)
Turns a bag of bytecodes into a Class and register it in the namespace of this ClassLoader.
|
protected Package |
definePackage(String pkgname,
String spectitle,
String specversion,
String specvendor,
String impltitle,
String implversion,
String implvendor,
URL sealbase)
Define a package by name.
|
void |
enableResourceMonitoring(boolean enable) |
protected Class |
findClass(String classname)
The default implementation of findClass() is just a mugtrap: any
real ClassLoader must override it.
|
protected String |
findLibrary(String libname)
default behaviour is to return null.
|
protected Class |
findLoadedClass(String classname)
findLoadedClass looks for a class in the cache of classes for which
this ClassLoader was the defining ClassLoader.
|
protected URL |
findResource(String resname)
findResource returns null: real resource-aware ClassLoaders
override this method.
|
protected Enumeration |
findResources(String resname)
findResources returns an empty Enumeration: real resource-aware
ClassLoaders override this method.
|
protected Class |
findSystemClass(String classname)
findSystemClass tries to load the named class using the system ClassLoader
|
protected Package |
getPackage(String pkgname)
Get the Package object associated with the given package name.
|
protected Package[] |
getPackages()
Get all Package objects known to this ClassLoader and its ancestors,
as an array of all things.
|
ClassLoader |
getParent()
Get the identity of the parent ClassLoader.
|
URL |
getResource(String resname)
getResource retrieves the named resource using "responsible
delegation", rather like loadClass (except that there is no
equivalent to "findLoadedClass").
|
InputStream |
getResourceAsStream(String resname)
Get a resource in the form of an InputStream.
|
Enumeration |
getResources(String resname)
getResources retrieves all the resource matching "name" in a
responsibly delegating manner.
|
static ClassLoader |
getSystemClassLoader()
Get the identity of the system ClassLoader.
|
static URL |
getSystemResource(String resname)
Get a resource using the system class loader.
|
static InputStream |
getSystemResourceAsStream(String resname)
Get a system resource in the form of an InputStream.
|
static Enumeration |
getSystemResources(String resname)
Get all resources using the system class loader.
|
Class |
loadClass(String classname)
If no 'resolve' parameter is supplied then the default is 'false'
(N.B.
|
protected Class |
loadClass(String classname,
boolean resolve)
As of Java 1.2 this method is no longer abstract.
|
protected void |
resolveClass(Class c)
resolveClass forces all constants in the constant pool of c to be resolved.
|
void |
setClassAssertionStatus(String className,
boolean enabled)
Sets the desired assertion status for the named top-level class in this
class loader and any nested classes contained therein.
|
void |
setDefaultAssertionStatus(boolean enabled)
Sets the default assertion status for this class loader.
|
void |
setPackageAssertionStatus(String packageName,
boolean enabled)
Sets the package-default assertion status for the named
package in this class loader.
|
protected void |
setSigners(Class cl,
Object[] signers)
Set the signers of a class.
|
protected final Hashtable packages
protected ClassLoader() throws SecurityException
SecurityException
protected ClassLoader(ClassLoader parent) throws SecurityException
SecurityException
protected Class loadClass(String classname, boolean resolve) throws ClassNotFoundException
ClassNotFoundException
public Class loadClass(String classname) throws ClassNotFoundException
ClassNotFoundException
protected Class findClass(String classname) throws ClassNotFoundException
ClassNotFoundException
protected final Class defineClass(byte[] data, int offset, int length) throws ClassFormatError
ClassFormatError
protected final Class defineClass(String classname, byte[] data, int offset, int length, ProtectionDomain pd) throws ClassFormatError
ClassFormatError
protected final Class defineClass(String classname, byte[] data, int offset, int length) throws ClassFormatError
ClassFormatError
protected final void resolveClass(Class c) throws NullPointerException
NullPointerException
protected final Class findSystemClass(String classname) throws ClassNotFoundException
ClassNotFoundException
protected final Class findLoadedClass(String classname)
protected URL findResource(String resname)
protected Enumeration findResources(String resname) throws IOException
IOException
public URL getResource(String resname)
public final Enumeration getResources(String resname) throws IOException
IOException
public static Enumeration getSystemResources(String resname) throws IOException
IOException
public static ClassLoader getSystemClassLoader()
public final ClassLoader getParent()
public static InputStream getSystemResourceAsStream(String resname)
public InputStream getResourceAsStream(String resname)
public static URL getSystemResource(String resname)
protected Package definePackage(String pkgname, String spectitle, String specversion, String specvendor, String impltitle, String implversion, String implvendor, URL sealbase) throws IllegalArgumentException
IllegalArgumentException
protected Package getPackage(String pkgname)
protected Package[] getPackages()
public void clearAssertionStatus()
public void setDefaultAssertionStatus(boolean enabled)
public void setPackageAssertionStatus(String packageName, boolean enabled)
A subpackage of a package named p is any package whose name begins with "p.". For example, javax.swing.text is a subpackage of javax.swing, and both java.util and java.lang.reflect are subpackages of java.
In the event that multiple package defaults apply to a given class, the package default pertaining to the most specific package takes precedence over the others. For example, if javax.lang and javax.lang.reflect both have package defaults associated with them, the latter package default applies to classes in javax.lang.reflect.
Package defaults take precedence over the class loader's default assertion status, and may be overridden on a per-class basis by invoking the setClassAssertionStatus method.
packageName
- the name of the package whose default assertion
status is to be set.enabled
- true if classes loaded by this class loader
and belonging to the named package and its subpackages will
henceforth have assertions enabled by default, false if they will
have assertions disabled by default.public void setClassAssertionStatus(String className, boolean enabled)
If the named class is not a top-level class, this invocation will have no effect on the actual assertion status of any class.
className
- the fully qualified class name of the top-level class
whose default assertion status is to be set.enabled
- true if the named class will have assertions enabled
when (and if) it is initialized, false if it will
have assertions disabled by default.public void enableResourceMonitoring(boolean enable)