Main Page | Class Hierarchy | Class List | Directories | Class Members | Related Pages

java.lang.ClassLoader Class Reference

List of all members.

Detailed Description

This class must be implemented by the vm vendor.

The documented methods and natives must be implemented to support other provided class implementations in this package. ClassLoaders are used to dynamically load, link and install classes into a running image.


Public Member Functions

final ClassLoader getParent ()
 Returns the specified ClassLoader's parent.
URL getResource (String resName)
 Answers an URL which can be used to access the resource described by resName, using the class loader's resource lookup algorithm.
final Enumeration getResources (String resName) throws IOException
 Answers an Enumeration of URL which can be used to access the resources described by resName, using the class loader's resource lookup algorithm.
InputStream getResourceAsStream (String resName)
 Answers a stream on a resource found by looking up resName using the class loader's resource lookup algorithm.
Class loadClass (String className) throws ClassNotFoundException
 Invoked by the Virtual Machine when resolving class references.
void setClassAssertionStatus (String cname, boolean enable)
 Sets the assertion status of a class.
void setPackageAssertionStatus (String pname, boolean enable)
 Sets the assertion status of a package.
void setDefaultAssertionStatus (boolean enable)
 Sets the default assertion status of a classloader.
void clearAssertionStatus ()
 Clears the default, package and class assertion status of a classloader.

Static Public Member Functions

static ClassLoader getSystemClassLoader ()
 Returns the system class loader.
static URL getSystemResource (String resName)
 Answers an URL specifing a resource which can be found by looking up resName using the system class loader's resource lookup algorithm.
static Enumeration getSystemResources (String resName) throws IOException
 Answers an Emuneration of URL containing all resources which can be found by looking up resName using the system class loader's resource lookup algorithm.
static InputStream getSystemResourceAsStream (String resName)
 Answers a stream on a resource found by looking up resName using the system class loader's resource lookup algorithm.

Protected Member Functions

 ClassLoader ()
 Constructs a new instance of this class with the system class loader as its parent.
 ClassLoader (ClassLoader parentLoader)
 Constructs a new instance of this class with the given class loader as its parent.
final Class defineClass (byte[] classRep, int offset, int length) throws ClassFormatError
 Constructs a new class from an array of bytes containing a class definition in class file format.
final Class defineClass (String className, byte[] classRep, int offset, int length) throws ClassFormatError
 Constructs a new class from an array of bytes containing a class definition in class file format.
final Class defineClass (String className, byte[] classRep, int offset, int length, ProtectionDomain protectionDomain) throws java.lang.ClassFormatError
 Constructs a new class from an array of bytes containing a class definition in class file format and assigns the new class to the specified protection domain.
Class findClass (String className) throws ClassNotFoundException
 Overridden by subclasses, by default throws ClassNotFoundException.
final Class findLoadedClass (String className)
 Attempts to find and return a class which has already been loaded by the virtual machine.
final Class findSystemClass (String className) throws ClassNotFoundException
 Attempts to load a class using the system class loader.
Class loadClass (String className, boolean resolveClass) throws ClassNotFoundException
 Loads the class with the specified name, optionally linking the class after load.
final void resolveClass (Class clazz)
 Forces a class to be linked (initialized).
URL findResource (String resName)
 Answers an URL which can be used to access the resource described by resName, using the class loader's resource lookup algorithm.
Enumeration findResources (String resName) throws IOException
 Answers an Enumeration of URL which can be used to access the resources described by resName, using the class loader's resource lookup algorithm.
String findLibrary (String libName)
 Answers the absolute path of the file containing the library associated with the given name, or null.
Package getPackage (String name)
 Attempt to locate the requested package.
Package[] getPackages ()
 Return all the packages known to this class loader.
Package definePackage (String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException
 Define a new Package using the specified information.
final void setSigners (Class c, Object[] signers)
 Sets the signers of a class.

Package Functions

final boolean isSystemClassLoader ()
 This method must be provided by the vm vendor, as it is used by other provided class implementations in this package.
final boolean isAncestorOf (ClassLoader child)
 Answers true if the receiver is ancestor of another class loader.
final Object[] getSigners (Class c)
 Gets the signers of a class.
boolean getClassAssertionStatus (String cname)
 Answers the assertion status of the named class Returns the assertion status of the class or nested class if it has been set.
boolean getPackageAssertionStatus (String pname)
 Answers the assertion status of the named package Returns the assertion status of the named package or superpackage if that has been set.
boolean getDefaultAssertionStatus ()
 Answers the default assertion status.

Static Package Functions

static final void initializeClassLoaders ()
static final ClassLoader getStackClassLoader (int depth)
 This must be provided by the vm vendor.
static ClassLoader callerClassLoader ()
 This method must be included, as it is used by System.load(), System.loadLibrary().
static void loadLibraryWithClassLoader (String libName, ClassLoader loader)
 This method must be provided by the vm vendor, as it is called by java.lang.System.loadLibrary().
static void loadLibraryWithPath (String libName, ClassLoader loader, String libraryPath)
 This method must be provided by the vm vendor, as it is called by java.lang.System.load().

Static Package Attributes

static ClassLoader systemClassLoader


Constructor & Destructor Documentation

java.lang.ClassLoader.ClassLoader  )  [protected]
 

Constructs a new instance of this class with the system class loader as its parent.

Exceptions:
SecurityException if a security manager exists and it does not allow the creation of new ClassLoaders.

java.lang.ClassLoader.ClassLoader ClassLoader  parentLoader  )  [protected]
 

Constructs a new instance of this class with the given class loader as its parent.

Parameters:
parentLoader ClassLoader the ClassLoader to use as the new class loaders parent.
Exceptions:
SecurityException if a security manager exists and it does not allow the creation of new ClassLoaders.
NullPointerException if the parent is null.


Member Function Documentation

final Class java.lang.ClassLoader.defineClass byte[]  classRep,
int  offset,
int  length
throws ClassFormatError [protected]
 

Constructs a new class from an array of bytes containing a class definition in class file format.

Parameters:
classRep byte[] a memory image of a class file.
offset int the offset into the classRep.
length int the length of the class file.
Deprecated:
Use defineClass(String, byte[], int, int)

final Class java.lang.ClassLoader.defineClass String  className,
byte[]  classRep,
int  offset,
int  length
throws ClassFormatError [protected]
 

Constructs a new class from an array of bytes containing a class definition in class file format.

Parameters:
className java.lang.String the name of the new class
classRep byte[] a memory image of a class file
offset int the offset into the classRep
length int the length of the class file

final Class java.lang.ClassLoader.defineClass String  className,
byte[]  classRep,
int  offset,
int  length,
ProtectionDomain  protectionDomain
throws java.lang.ClassFormatError [protected]
 

Constructs a new class from an array of bytes containing a class definition in class file format and assigns the new class to the specified protection domain.

Parameters:
className java.lang.String the name of the new class.
classRep byte[] a memory image of a class file.
offset int the offset into the classRep.
length int the length of the class file.
protectionDomain ProtectionDomain the protection domain this class should belongs to.

Class java.lang.ClassLoader.findClass String  className  )  throws ClassNotFoundException [protected]
 

Overridden by subclasses, by default throws ClassNotFoundException.

This method is called by loadClass() after the parent ClassLoader has failed to find a loaded class of the same name.

Returns:
java.lang.Class the class or null.
Parameters:
className String the name of the class to search for.
Exceptions:
ClassNotFoundException always, unless overridden.

final Class java.lang.ClassLoader.findLoadedClass String  className  )  [protected]
 

Attempts to find and return a class which has already been loaded by the virtual machine.

Note that the class may not have been linked and the caller should call resolveClass() on the result if necessary.

Returns:
java.lang.Class the class or null.
Parameters:
className String the name of the class to search for.

final Class java.lang.ClassLoader.findSystemClass String  className  )  throws ClassNotFoundException [protected]
 

Attempts to load a class using the system class loader.

Note that the class has already been been linked.

Returns:
java.lang.Class the class which was loaded.
Parameters:
className String the name of the class to search for.
Exceptions:
ClassNotFoundException if the class can not be found.

final ClassLoader java.lang.ClassLoader.getParent  ) 
 

Returns the specified ClassLoader's parent.

Returns:
java.lang.ClassLoader the class or null.
Exceptions:
SecurityException if a security manager exists and it does not allow the parent loader to be retrieved.

URL java.lang.ClassLoader.getResource String  resName  ) 
 

Answers an URL which can be used to access the resource described by resName, using the class loader's resource lookup algorithm.

The default behavior is just to return null.

Returns:
URL the location of the resource.
Parameters:
resName String the name of the resource to find.
See also:
Class.getResource

final Enumeration java.lang.ClassLoader.getResources String  resName  )  throws IOException
 

Answers an Enumeration of URL which can be used to access the resources described by resName, using the class loader's resource lookup algorithm.

The default behavior is just to return an empty Enumeration.

Returns:
Enumeration the locations of the resources.
Parameters:
resName String the name of the resource to find.

InputStream java.lang.ClassLoader.getResourceAsStream String  resName  ) 
 

Answers a stream on a resource found by looking up resName using the class loader's resource lookup algorithm.

The default behavior is just to return null.

Returns:
InputStream a stream on the resource or null.
Parameters:
resName String the name of the resource to find.
See also:
Class.getResourceAsStream

static ClassLoader java.lang.ClassLoader.getSystemClassLoader  )  [static]
 

Returns the system class loader.

This is the parent for new ClassLoader instances, and is typically the class loader used to start the application. If a security manager is present, and the caller's class loader is not null and the caller's class loader is not the same as or an ancestor of the system class loader, then this method calls the security manager's checkPermission method with a RuntimePermission("getClassLoader") permission to ensure it's ok to access the system class loader. If not, a SecurityException will be thrown.

Returns:
java.lang.ClassLoader the system classLoader.
Exceptions:
SecurityException if a security manager exists and it does not allow access to the system class loader.

static URL java.lang.ClassLoader.getSystemResource String  resName  )  [static]
 

Answers an URL specifing a resource which can be found by looking up resName using the system class loader's resource lookup algorithm.

Returns:
URL a URL specifying a system resource or null.
Parameters:
resName String the name of the resource to find.
See also:
Class.getResource

static Enumeration java.lang.ClassLoader.getSystemResources String  resName  )  throws IOException [static]
 

Answers an Emuneration of URL containing all resources which can be found by looking up resName using the system class loader's resource lookup algorithm.

Returns:
Enumeration an Enumeration of URL containing the system resources
Parameters:
resName String the name of the resource to find.

static InputStream java.lang.ClassLoader.getSystemResourceAsStream String  resName  )  [static]
 

Answers a stream on a resource found by looking up resName using the system class loader's resource lookup algorithm.

Basically, the contents of the java.class.path are searched in order, looking for a path which matches the specified resource.

Returns:
a stream on the resource or null.
Parameters:
resName the name of the resource to find.
See also:
Class.getResourceAsStream

Class java.lang.ClassLoader.loadClass String  className  )  throws ClassNotFoundException
 

Invoked by the Virtual Machine when resolving class references.

Equivalent to loadClass(className, false);

Returns:
java.lang.Class the Class object.
Parameters:
className String the name of the class to search for.
Exceptions:
ClassNotFoundException If the class could not be found.

Class java.lang.ClassLoader.loadClass String  className,
boolean  resolveClass
throws ClassNotFoundException [protected]
 

Loads the class with the specified name, optionally linking the class after load.

Steps are: 1) Call findLoadedClass(className) to determine if class is loaded 2) Call loadClass(className, resolveClass) on the parent loader. 3) Call findClass(className) to find the class

Returns:
java.lang.Class the Class object.
Parameters:
className String the name of the class to search for.
resolveClass boolean indicates if class should be resolved after loading.
Exceptions:
ClassNotFoundException If the class could not be found.

final void java.lang.ClassLoader.resolveClass Class  clazz  )  [protected]
 

Forces a class to be linked (initialized).

If the class has already been linked this operation has no effect.

Parameters:
clazz Class the Class to link.
Exceptions:
NullPointerException if clazz is null.
See also:
Class.getResource

final boolean java.lang.ClassLoader.isSystemClassLoader  )  [package]
 

This method must be provided by the vm vendor, as it is used by other provided class implementations in this package.

A sample implementation of this method is provided by the reference implementation. This method is used by SecurityManager.classLoaderDepth(), currentClassLoader() and currentLoadedClass(). Answers true if the receiver is a system class loader.

Note that this method has package visibility only. It is defined here to avoid the security manager check in getSystemClassLoader, which would be required to implement this method anywhere else.

Returns:
boolean true if the receiver is a system class loader
See also:
Class.getClassLoaderImpl()

final boolean java.lang.ClassLoader.isAncestorOf ClassLoader  child  )  [package]
 

Answers true if the receiver is ancestor of another class loader.

Note that this method has package visibility only. It is defined here to avoid the security manager check in getParent, which would be required to implement this method anywhere else.

Parameters:
child ClassLoader, a child candidate
Returns:
boolean true if the receiver is ancestor of the parameter

URL java.lang.ClassLoader.findResource String  resName  )  [protected]
 

Answers an URL which can be used to access the resource described by resName, using the class loader's resource lookup algorithm.

The default behavior is just to return null. This should be implemented by a ClassLoader.

Returns:
URL the location of the resource.
Parameters:
resName String the name of the resource to find.

Enumeration java.lang.ClassLoader.findResources String  resName  )  throws IOException [protected]
 

Answers an Enumeration of URL which can be used to access the resources described by resName, using the class loader's resource lookup algorithm.

The default behavior is just to return an empty Enumeration.

Parameters:
resName String the name of the resource to find.
Returns:
Enumeration the locations of the resources.
Exceptions:
IOException when an error occurs

String java.lang.ClassLoader.findLibrary String  libName  )  [protected]
 

Answers the absolute path of the file containing the library associated with the given name, or null.

If null is answered, the system searches the directories specified by the system property "java.library.path".

Returns:
String the library file name or null.
Parameters:
libName String the name of the library to find.

Package java.lang.ClassLoader.getPackage String  name  )  [protected]
 

Attempt to locate the requested package.

If no package information can be located, null is returned.

Parameters:
name The name of the package to find
Returns:
The package requested, or null

Package [] java.lang.ClassLoader.getPackages  )  [protected]
 

Return all the packages known to this class loader.

Returns:
All the packages known to this classloader

Package java.lang.ClassLoader.definePackage String  name,
String  specTitle,
String  specVersion,
String  specVendor,
String  implTitle,
String  implVersion,
String  implVendor,
URL  sealBase
throws IllegalArgumentException [protected]
 

Define a new Package using the specified information.

Parameters:
name The name of the package
specTitle The title of the specification for the Package
specVersion The version of the specification for the Package
specVendor The vendor of the specification for the Package
implTitle The implementation title of the Package
implVersion The implementation version of the Package
implVendor The specification vendor of the Package
Returns:
The Package created
Exceptions:
IllegalArgumentException if the Package already exists

final Object [] java.lang.ClassLoader.getSigners Class  c  )  [package]
 

Gets the signers of a class.

Parameters:
c The Class object
Returns:
signers The signers for the class

final void java.lang.ClassLoader.setSigners Class  c,
Object[]  signers
[protected]
 

Sets the signers of a class.

Parameters:
c The Class object
signers The signers for the class

static final ClassLoader java.lang.ClassLoader.getStackClassLoader int  depth  )  [static, package]
 

This must be provided by the vm vendor.

It is used by SecurityManager.checkMemberAccess() with depth = 3. Note that checkMemberAccess() assumes the following stack when called. <user code>=""> <- want this class
Class.getDeclared*();
Class.checkMemberAccess();
SecurityManager.checkMemberAccess(); <- current frame
Returns the ClassLoader of the method (including natives) at the specified depth on the stack of the calling thread. Frames representing the VM implementation of java.lang.reflect are not included in the list. Notes:

  • This method operates on the defining classes of methods on stack. NOT the classes of receivers.
  • The item at depth zero is the caller of this method

Parameters:
depth the stack depth of the requested ClassLoader
Returns:
the ClassLoader at the specified depth

static ClassLoader java.lang.ClassLoader.callerClassLoader  )  [static, package]
 

This method must be included, as it is used by System.load(), System.loadLibrary().

The reference implementation of this method uses the getStackClassLoader() method. Returns the ClassLoader of the method that called the caller. i.e. A.x() calls B.y() calls callerClassLoader(), A's ClassLoader will be returned. Returns null for the bootstrap ClassLoader.

Returns:
a ClassLoader or null for the bootstrap ClassLoader

static void java.lang.ClassLoader.loadLibraryWithClassLoader String  libName,
ClassLoader  loader
[static, package]
 

This method must be provided by the vm vendor, as it is called by java.lang.System.loadLibrary().

System.loadLibrary() cannot call Runtime.loadLibrary() because this method loads the library using the ClassLoader of the calling method. Loads and links the library specified by the argument.

Parameters:
libName the name of the library to load
loader the classloader in which to load the library
Exceptions:
UnsatisfiedLinkError if the library could not be loaded
SecurityException if the library was not allowed to be loaded

static void java.lang.ClassLoader.loadLibraryWithPath String  libName,
ClassLoader  loader,
String  libraryPath
[static, package]
 

This method must be provided by the vm vendor, as it is called by java.lang.System.load().

System.load() cannot call Runtime.load() because the library is loaded using the ClassLoader of the calling method. Loads and links the library specified by the argument. No security check is done.

Parameters:
libName the name of the library to load
loader the classloader in which to load the library
libraryPath the library path to search, or null
Exceptions:
UnsatisfiedLinkError if the library could not be loaded

void java.lang.ClassLoader.setClassAssertionStatus String  cname,
boolean  enable
 

Sets the assertion status of a class.

Parameters:
cname Class name
enable Enable or disable assertion

void java.lang.ClassLoader.setPackageAssertionStatus String  pname,
boolean  enable
 

Sets the assertion status of a package.

Parameters:
pname Package name
enable Enable or disable assertion

void java.lang.ClassLoader.setDefaultAssertionStatus boolean  enable  ) 
 

Sets the default assertion status of a classloader.

Parameters:
enable Enable or disable assertion

void java.lang.ClassLoader.clearAssertionStatus  ) 
 

Clears the default, package and class assertion status of a classloader.

boolean java.lang.ClassLoader.getClassAssertionStatus String  cname  )  [package]
 

Answers the assertion status of the named class Returns the assertion status of the class or nested class if it has been set.

Otherwise returns the assertion status of its package or superpackage if that has been set. Otherwise returns the default assertion status. Returns 1 for enabled and 0 for disabled.

Returns:
int the assertion status.
Parameters:
cname String the name of class.

boolean java.lang.ClassLoader.getPackageAssertionStatus String  pname  )  [package]
 

Answers the assertion status of the named package Returns the assertion status of the named package or superpackage if that has been set.

Otherwise returns the default assertion status. Returns 1 for enabled and 0 for disabled.

Returns:
int the assertion status.
Parameters:
pname String the name of package.

boolean java.lang.ClassLoader.getDefaultAssertionStatus  )  [package]
 

Answers the default assertion status.

Returns:
boolean the default assertion status.


The documentation for this class was generated from the following file:
(c) Copyright 2005 The Apache Software Foundation or its licensors, as applicable.