java.lang
public
abstract
class
java.lang.ClassLoader
A ClassLoader is used for loading classes.
VM Implementors Note
This class must be implemented by the VM. The documented methods and natives
must be implemented to support other provided class implementations in this
package.
Known Direct Subclasses
PathClassLoader |
Simple ClassLoader implementation. |
SecureClassLoader |
SecureClassLoaders are used to dynamically load, link and install classes
into a running image. |
Known Indirect Subclasses
URLClassLoader |
This class loader is responsible for loading classes and resources from a
list of URLs which can refer to either directories or JAR files. |
Summary
Protected Constructors
Public Methods
Protected Methods
|
|
final |
|
|
Class<?> |
defineClass(byte[] classRep, int offset, int length) |
|
|
final |
|
|
Class<?> |
defineClass(String name, ByteBuffer b, ProtectionDomain protectionDomain) |
|
|
final |
|
|
Class<?> |
defineClass(String className, byte[] classRep, int offset, int length, ProtectionDomain protectionDomain) |
|
|
final |
|
|
Class<?> |
defineClass(String className, byte[] classRep, int offset, int length) |
|
|
|
|
|
Package |
definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) |
|
|
|
|
|
Class<?> |
findClass(String className) |
|
|
|
|
|
String |
findLibrary(String libName) |
|
|
final |
|
|
Class<?> |
findLoadedClass(String className) |
|
|
|
|
|
URL |
findResource(String resName) |
|
|
|
|
|
Enumeration<URL> |
findResources(String resName) |
|
|
final |
|
|
Class<?> |
findSystemClass(String className) |
|
|
|
|
|
Package |
getPackage(String name) |
|
|
|
|
|
Package[] |
getPackages() |
|
|
|
|
|
Class<?> |
loadClass(String className, boolean resolve) |
|
|
final |
|
|
void |
resolveClass(Class<?> clazz) |
|
|
final |
|
|
void |
setSigners(Class<?> c, Object[] signers) |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Protected Constructors
protected
ClassLoader()
Constructs a new instance of this class with the system class loader as
its parent.
Throws
SecurityException
| if a security manager exists and it does not
allow the creation of new ClassLoaders.
|
protected
ClassLoader(ClassLoader parentLoader)
Constructs a new instance of this class with the given class loader as
its parent.
Parameters
parentLoader
| The ClassLoader to use as the new class loaders
parent. |
Public Methods
public
void
clearAssertionStatus()
Clears the default, package and class assertion status of a classloader
public
final
ClassLoader
getParent()
Returns the specified ClassLoader's parent.
Throws
SecurityException
| if a security manager exists and it does not
allow the parent loader to be retrieved.
|
public
URL
getResource(String resName)
Returns 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.
Parameters
resName
| String the name of the resource to find. |
Returns
- The location of the resource.
public
InputStream
getResourceAsStream(String resName)
Returns 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.
Parameters
resName
| String the name of the resource to find. |
Returns
- A stream on the resource or null.
Returns 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
- The location of the resources.
public
static
ClassLoader
getSystemClassLoader()
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.
Throws
SecurityException
| if a security manager exists and it does not
allow access to the system class loader.
|
public
static
URL
getSystemResource(String resName)
Returns an URL specifying a resource which can be found by looking up
resName using the system class loader's resource lookup algorithm.
Parameters
resName
| The name of the resource to find. |
Returns
- A URL specifying a system resource or null.
public
static
InputStream
getSystemResourceAsStream(String resName)
Returns 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.
Parameters
resName
| The name of the resource to find. |
Returns
- A stream on the resource or null.
public
static
Enumeration<URL>
getSystemResources(String resName)
Returns an Enumeration of URLs containing all resources which can be
found by looking up resName using the system class loader's resource
lookup algorithm.
Parameters
resName
| String the name of the resource to find.
|
Returns
- An Enumeration of URLs containing the system resources
public
Class<?>
loadClass(String className)
Invoked by the Virtual Machine when resolving class references.
Equivalent to loadClass(className, false);
Parameters
className
| The name of the class to search for. |
public
void
setClassAssertionStatus(String cname, boolean enable)
Sets the assertion status of a class.
Parameters
cname
| Class name |
enable
| Enable or disable assertion
|
public
void
setDefaultAssertionStatus(boolean enable)
Sets the default assertion status of a classloader
Parameters
enable
| Enable or disable assertion
|
public
void
setPackageAssertionStatus(String pname, boolean enable)
Sets the assertion status of a package.
Parameters
pname
| Package name |
enable
| Enable or disable assertion
|
Protected Methods
protected
final
Class<?>
defineClass(byte[] classRep, int offset, int length)
This method is deprecated.
Use defineClass(String, byte[], int, int)
Constructs a new class from an array of bytes containing a class
definition in class file format.
Parameters
classRep
| A memory image of a class file. |
offset
| The offset into the classRep. |
length
| The length of the class file. |
Defines a new class for the name, bytecodes in the byte buffer and the
protection domain.
Parameters
name
| The name of the class to define. |
b
| The byte buffer containing the bytecodes of the new class. |
protectionDomain
| The protection domain this class belongs to. |
protected
final
Class<?>
defineClass(String className, byte[] classRep, int offset, int length, ProtectionDomain protectionDomain)
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
| The name of the new class. |
classRep
| A memory image of a class file. |
offset
| The offset into the classRep. |
length
| The length of the class file. |
protectionDomain
| The protection domain this class should belongs
to.
|
protected
final
Class<?>
defineClass(String className, byte[] classRep, int offset, int length)
Constructs a new class from an array of bytes containing a class
definition in class file format.
Parameters
className
| The name of the new class |
classRep
| A memory image of a class file |
offset
| The offset into the classRep |
length
| The length of the class file
|
protected
Package
definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase)
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 |
sealBase
| If sealBase is null, the package is left unsealed.
Otherwise, the the package is sealed using this URL. |
protected
Class<?>
findClass(String className)
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.
Parameters
className
| The name of the class to search for. |
protected
String
findLibrary(String libName)
Returns 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".
Parameters
libName
| The name of the library to find.
|
Returns
- The library file name or null.
protected
final
Class<?>
findLoadedClass(String className)
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.
Parameters
className
| The name of the class to search for.
|
protected
URL
findResource(String resName)
Returns 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.
Parameters
resName
| The name of the resource to find.
|
Returns
- The location of the resource.
Returns 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
| The name of the resource to find. |
Returns
- The locations of the resources.
protected
final
Class<?>
findSystemClass(String className)
Attempts to load a class using the system class loader. Note that the
class has already been been linked.
Parameters
className
| The name of the class to search for. |
Returns
- The class which was loaded.
protected
Package
getPackage(String name)
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
protected
Package[]
getPackages()
Return all the packages known to this class loader.
Returns
- All the packages known to this classloader
protected
Class<?>
loadClass(String className, boolean resolve)
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
Parameters
className
| The name of the class to search for. |
resolve
| Indicates if class should be resolved after loading.
Note: On the android reference implementation this parameter
does not have any effect. |
protected
final
void
resolveClass(Class<?> clazz)
Forces a class to be linked (initialized). If the class has already been
linked this operation has no effect.
Note that for the android reference implementation this method does not
have any effect.
protected
final
void
setSigners(Class<?> c, Object[] signers)
Sets the signers of a class.
Parameters
c
| The Class object |
signers
| The signers for the class
|