|
Build 1.1_r1 (from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.ClassLoader
public abstract class ClassLoader
Loads classes and resources from a repository. One or more class loaders are installed at runtime. These are consulted whenever the runtime system needs a specific class that is not yet available in-memory. Typically, class loaders are grouped into a tree where child class loaders delegate all requests to parent class loaders. Only if the parent class loader cannot satisfy the request, the child class loader itself tries to handle it.
ClassLoader is an abstract class that implements the common
infrastructure required by all class loaders. Android provides several
concrete implementations of the class, with
PathClassLoader being the one typically used. Other
applications may implement subclasses of ClassLoader to provide
special ways for loading classes.
Class| Constructor Summary | |
|---|---|
protected |
ClassLoader()
Constructs a new instance of this class with the system class loader as its parent. |
protected |
ClassLoader(ClassLoader parentLoader)
Constructs a new instance of this class with the specified class loader as its parent. |
| Method Summary | |
|---|---|
void |
clearAssertionStatus()
Sets the default assertion status for this class loader to false
and removes any package default and class assertion status settings. |
protected Class<?> |
defineClass(byte[] classRep,
int offset,
int length)
Deprecated. Use defineClass(String, byte[], int, int) |
protected 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. |
protected 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 specified protection domain to the new class. |
protected Class<?> |
defineClass(String name,
ByteBuffer b,
ProtectionDomain protectionDomain)
Defines a new class with the specified name, byte code from the byte buffer and the optional protection domain. |
protected Package |
definePackage(String name,
String specTitle,
String specVersion,
String specVendor,
String implTitle,
String implVersion,
String implVendor,
URL sealBase)
Defines and returns a new Package using the specified
information. |
protected Class<?> |
findClass(String className)
Overridden by subclasses, throws a ClassNotFoundException by
default. |
protected String |
findLibrary(String libName)
Returns the absolute path of the native library with the specified name, or null. |
protected Class<?> |
findLoadedClass(String className)
Returns the class with the specified name if it has already been loaded by the virtual machine or null if it has not yet been loaded. |
protected URL |
findResource(String resName)
Finds the URL of the resource with the specified name. |
protected Enumeration<URL> |
findResources(String resName)
Finds an enumeration of URLs for the resource with the specified name. |
protected Class<?> |
findSystemClass(String className)
Finds the class with the specified name, loading it using the system class loader if necessary. |
(package private) boolean |
getClassAssertionStatus(String cname)
Returns the assertion status of the named class Returns the assertion status of the class or nested class if it has been set. |
(package private) boolean |
getDefaultAssertionStatus()
Returns the default assertion status |
(package private) static Package |
getPackage(ClassLoader loader,
String name)
Gets the package with the specified name, searching it in the specified class loader. |
protected Package |
getPackage(String name)
Returns the package with the specified name. |
(package private) boolean |
getPackageAssertionStatus(String pname)
Returns the assertion status of the named package Returns the assertion status of the named package or superpackage if that has been set. |
protected Package[] |
getPackages()
Returns all the packages known to this class loader. |
ClassLoader |
getParent()
Returns this class loader's parent. |
URL |
getResource(String resName)
Returns the URL of the resource with the specified name. |
InputStream |
getResourceAsStream(String resName)
Returns a stream for the resource with the specified name. |
Enumeration<URL> |
getResources(String resName)
Returns an enumeration of URLs for the resource with the specified name. |
(package private) Object[] |
getSigners(Class<?> c)
Gets the signers of the specified class. |
(package private) static ClassLoader |
getStackClassLoader(int depth)
This must be provided by the VM vendor. |
static ClassLoader |
getSystemClassLoader()
Returns the system class loader. |
static URL |
getSystemResource(String resName)
Finds the URL of the resource with the specified name. |
static InputStream |
getSystemResourceAsStream(String resName)
Returns a stream for the resource with the specified name. |
static Enumeration<URL> |
getSystemResources(String resName)
Returns an enumeration of URLs for the resource with the specified name. |
(package private) boolean |
isAncestorOf(ClassLoader child)
Returns true if the receiver is ancestor of another class loader. |
(package private) boolean |
isSystemClassLoader()
Indicates whether this class loader is the system class loader. |
Class<?> |
loadClass(String className)
Loads the class with the specified name. |
protected Class<?> |
loadClass(String className,
boolean resolve)
Loads the class with the specified name, optionally linking it after loading. |
(package private) 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(). |
(package private) 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(). |
protected void |
resolveClass(Class<?> clazz)
Forces a class to be linked (initialized). |
void |
setClassAssertionStatus(String cname,
boolean enable)
Sets the assertion status of the class with the specified name. |
void |
setDefaultAssertionStatus(boolean enable)
Sets the default assertion status for this class loader. |
void |
setPackageAssertionStatus(String pname,
boolean enable)
Sets the assertion status of the package with the specified name. |
protected void |
setSigners(Class<?> c,
Object[] signers)
Sets the signers of the specified class. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected ClassLoader()
SecurityException - if a security manager exists and it does not allow the
creation of a new ClassLoader.protected ClassLoader(ClassLoader parentLoader)
parentLoader - The ClassLoader to use as the new class loader's
parent.
SecurityException - if a security manager exists and it does not allow the
creation of new a new ClassLoader.| Method Detail |
|---|
public static ClassLoader getSystemClassLoader()
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 neither null nor 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 that it is ok to access the system class loader. If
not, a SecurityException is thrown.
SecurityException - if a security manager exists and it does not allow access to
the system class loader.public static URL getSystemResource(String resName)
resName - the name of the resource to find.
URL object for the requested resource or null
if the resource can not be found.Class.getResource(java.lang.String)
public static Enumeration<URL> getSystemResources(String resName)
throws IOException
resName - the name of the resource to find.
URL objects containing the requested
resources.
IOException - if an I/O error occurs.public static InputStream getSystemResourceAsStream(String resName)
resName - the name of the resource to find.
null.Class.getResourceAsStream(java.lang.String)
@Deprecated
protected final Class<?> defineClass(byte[] classRep,
int offset,
int length)
throws ClassFormatError
defineClass(String, byte[], int, int)
classRep - the memory image of a class file.offset - the offset into classRep.length - the length of the class file.
Class object created from the specified subset of
data in classRep.
ClassFormatError - if classRep does not contain a valid class.
IndexOutOfBoundsException - if offset < 0, length < 0 or if
offset + length is greater than the length of
classRep.
protected final Class<?> defineClass(String className,
byte[] classRep,
int offset,
int length)
throws ClassFormatError
className - the expected name of the new class, may be null if not
known.classRep - the memory image of a class file.offset - the offset into classRep.length - the length of the class file.
Class object created from the specified subset of
data in classRep.
ClassFormatError - if classRep does not contain a valid class.
IndexOutOfBoundsException - if offset < 0, length < 0 or if
offset + length is greater than the length of
classRep.
protected final Class<?> defineClass(String className,
byte[] classRep,
int offset,
int length,
ProtectionDomain protectionDomain)
throws ClassFormatError
null then a default protection domain is assigned to the class.
className - the expected name of the new class, may be null if not
known.classRep - the memory image of a class file.offset - the offset into classRep.length - the length of the class file.protectionDomain - the protection domain to assign to the loaded class, may be
null.
Class object created from the specified subset of
data in classRep.
ClassFormatError - if classRep does not contain a valid class.
IndexOutOfBoundsException - if offset < 0, length < 0 or if
offset + length is greater than the length of
classRep.
NoClassDefFoundError - if className is not equal to the name of the class
contained in classRep.
protected final Class<?> defineClass(String name,
ByteBuffer b,
ProtectionDomain protectionDomain)
throws ClassFormatError
null then a default protection domain is assigned to
the class.
name - the expected name of the new class, may be null if not
known.b - the byte buffer containing the byte code of the new class.protectionDomain - the protection domain to assign to the loaded class, may be
null.
Class object created from the data in b.
ClassFormatError - if b does not contain a valid class.
NoClassDefFoundError - if className is not equal to the name of the class
contained in b.
protected Class<?> findClass(String className)
throws ClassNotFoundException
ClassNotFoundException by
default. This method is called by loadClass after the parent
ClassLoader has failed to find a loaded class of the same name.
className - the name of the class to look for.
Class object that is found.
ClassNotFoundException - if the class cannot be found.protected final Class<?> findLoadedClass(String className)
null if it has not yet been loaded.
className - the name of the class to look for.
Class object or null if the requested class
has not been loaded.
protected final Class<?> findSystemClass(String className)
throws ClassNotFoundException
className - the name of the class to look for.
Class object with the requested className.
ClassNotFoundException - if the class can not be found.public final ClassLoader getParent()
null.
SecurityException - if a security manager exists and it does not allow to
retrieve the parent class loader.public URL getResource(String resName)
findResource(String) is called to
find the requested resource.
resName - the name of the resource to find.
URL object for the requested resource or null
if either the resource can not be found or a security manager
does not allow to access the resource.Class.getResource(java.lang.String)
public Enumeration<URL> getResources(String resName)
throws IOException
findResources(String) to get additional
URLs. The returned enumeration contains the URL objects of both
find operations.
resName - the name of the resource to find.
URL objects for the requested resource.
IOException - if an I/O error occurs.public InputStream getResourceAsStream(String resName)
getResource(String) for a description of the lookup algorithm
used to find the resource.
resName - the name of the resource to find.
null if either the resource
can not be found or a security manager does not allow to access
the resource.Class.getResourceAsStream(java.lang.String)
public Class<?> loadClass(String className)
throws ClassNotFoundException
loadClass(className, false).
Note: In the Android reference implementation, the
second parameter of loadClass(String, boolean) is ignored
anyway.
className - the name of the class to look for.
Class object.
ClassNotFoundException - if the class can not be found.
protected Class<?> loadClass(String className,
boolean resolve)
throws ClassNotFoundException
findLoadedClass(String) to determine if the requested
class has already been loaded.findClass(String) to find the class.
Note: In the Android reference implementation, the
resolve parameter is ignored; classes are never linked.
className - the name of the class to look for.resolve - Indicates if the class should be resolved after loading. This
parameter is ignored on the Android reference implementation;
classes are not resolved.
Class object.
ClassNotFoundException - if the class can not be found.protected final void resolveClass(Class<?> clazz)
Note: In the Android reference implementation, this method has no effect.
clazz - the class to link.final boolean isSystemClassLoader()
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.
true if the receiver is a system class loaderClass.getClassLoaderImpl()final boolean isAncestorOf(ClassLoader child)
Returns true if the receiver is ancestor of another class loader. It also returns true if the two class loader are equal.
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. The method is also required in other places where class loaders are accesses.
child - A child candidate
true if the receiver is ancestor of, or equal to,
the parameterprotected URL findResource(String resName)
null; it should be overridden in
subclasses.
resName - the name of the resource to find.
URL object for the requested resource.
protected Enumeration<URL> findResources(String resName)
throws IOException
Enumeration; it should
be overridden in subclasses.
resName - the name of the resource to find.
URL objects for the requested resource.
IOException - if an I/O error occurs.protected String findLibrary(String libName)
null. If this method returns null then the virtual
machine searches the directories specified by the system property
"java.library.path".
This implementation always returns null.
libName - the name of the library to find.
protected Package getPackage(String name)
name - the name of the package to find.
null if the package
can not be found.
static Package getPackage(ClassLoader loader,
String name)
loader - the class loader to search the package in.name - the name of the package to find.
null if the package
can not be found.protected Package[] getPackages()
protected Package definePackage(String name,
String specTitle,
String specVersion,
String specVendor,
String implTitle,
String implVersion,
String implVendor,
URL sealBase)
throws IllegalArgumentException
Package using the specified
information. If sealBase is null, the package is left
unsealed. Otherwise, the package is sealed using this URL.
name - the name of the package.specTitle - the title of the specification.specVersion - the version of the specification.specVendor - the vendor of the specification.implTitle - the implementation title.implVersion - the implementation version.implVendor - the specification vendor.sealBase - the URL used to seal this package or null to leave the
package unsealed.
Package object that has been created.
IllegalArgumentException - if a package with the specified name already exists.final Object[] getSigners(Class<?> c)
null.
c - the Class object for which to get the signers.
c.
protected final void setSigners(Class<?> c,
Object[] signers)
c - the Class object for which to set the signers.signers - the signers for c.static final ClassLoader getStackClassLoader(int depth)
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:
depth - the stack depth of the requested ClassLoader
static void loadLibraryWithClassLoader(String libName,
ClassLoader loader)
libName - the name of the library to loadloader - the classloader in which to load the library
UnsatisfiedLinkError - if the library could not be loaded
SecurityException - if the library was not allowed to be loaded
Note: This method does nothing in the Android reference implementation.
static void loadLibraryWithPath(String libName,
ClassLoader loader,
String libraryPath)
Note: This method does nothing in the Android reference implementation.
libName - the name of the library to loadloader - the classloader in which to load the librarylibraryPath - the library path to search, or null
UnsatisfiedLinkError - if the library could not be loaded
public void setClassAssertionStatus(String cname,
boolean enable)
Note: This method does nothing in the Android reference implementation.
cname - the name of the class for which to set the assertion status.enable - the new assertion status.
public void setPackageAssertionStatus(String pname,
boolean enable)
Note: This method does nothing in the Android reference implementation.
pname - the name of the package for which to set the assertion status.enable - the new assertion status.public void setDefaultAssertionStatus(boolean enable)
Note: This method does nothing in the Android reference implementation.
enable - the new assertion status.public void clearAssertionStatus()
false
and removes any package default and class assertion status settings.
Note: This method does nothing in the Android reference implementation.
boolean getClassAssertionStatus(String cname)
cname - the name of class.
boolean getPackageAssertionStatus(String pname)
pname - the name of package.
boolean getDefaultAssertionStatus()
|
Build 1.1_r1 (from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||