aicas logoJamaica 6.4 release 1

java.lang
Class ClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
Direct Known Subclasses:
SecureClassLoader

public abstract class ClassLoader
extends Object

ClassLoader provides a new name space for classes that are loaded into the system from an external source.

Since:
1.0

Constructor Summary
protected ClassLoader()
          Constructor to create a class loader with system class loader as parent.
protected ClassLoader(ClassLoader parent)
          Constructor to create a class loader with the given parent.
 
Method Summary
 void clearAssertionStatus()
          clearAssertionStatus removes all the assertion status settings for classes, packages and for this class loader.
protected  Class<?> defineClass(byte[] b, int off, int len)
          Deprecated. use defineClass(String,byte[],int,int) instead.
protected  Class<?> defineClass(String name, byte[] b, int off, int len)
          Define a class from the give class file data.
protected  Class<?> defineClass(String name, byte[] b, int off, int len, ProtectionDomain domain)
          Define a class from the give class file data.
protected  Class<?> defineClass(String name, ByteBuffer b, ProtectionDomain protectionDomain)
          defineClass
protected  Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase)
          Defines a Package object for classes that are loaded through this ClassLoader.
protected  Class<?> findClass(String name)
          Find a class with the given name.
protected  String findLibrary(String libname)
          findLibrary returns the path to load a shared library with the given name.
protected  Class<?> findLoadedClass(String name)
          findLoadedClass searches for a class with given name that was loaded by this class loader.
protected  URL findResource(String name)
          findResource find a resource with a given name.
protected  Enumeration<URL> findResources(String name)
          findResources returns an enumeration of URLs for the resource with the given name.
protected  Class<?> findSystemClass(String name)
          Load class from the system class loader.
protected  Package getPackage(String name)
          Get the Package object for the named package if it is defined in this ClassLoader or in one of its ancestors.
protected  Package[] getPackages()
          getPackages returns an array of all packages defined by this class loader and all of its ancestors.
 ClassLoader getParent()
          getParent return the parent class loader of this class loader instance.
 URL getResource(String name)
          getResource returns an URL for a resource with the given name.
 InputStream getResourceAsStream(String name)
          getResourceAsStream finds a resource with the given name and opens an InputStream to read the resource data.
 Enumeration<URL> getResources(String name)
          getResources returns an enumeration of URLs for the resource with the given name.
static ClassLoader getSystemClassLoader()
          getSystemClassLoader returns the system class loader.
static URL getSystemResource(String name)
          getSystemResource determines the location of a resource in the system class path.
static InputStream getSystemResourceAsStream(String name)
          getSystemResourceAsStream finds a resource of the system class loader with the given name and opens an InputStream to read the resource data.
static Enumeration<URL> getSystemResources(String name)
          getSystemResources determines the locations of all resources with a given name in the system class path.
 Class<?> loadClass(String name)
          Load a class from this class loader without resolving it.
protected  Class<?> loadClass(String name, boolean resolve)
          Load a class from this class loader, optionally resolving it.
protected  void resolveClass(Class<?> cl)
          Resolve a class.
 void setClassAssertionStatus(String name, boolean enabled)
          setClassAssertionStatus sets the assertion status for a class with a given name.
 void setDefaultAssertionStatus(boolean enabled)
          setDefaultAssertionStatus enables or disables assertion checking for classes loaded via this class loader.
 void setPackageAssertionStatus(String name, boolean enabled)
          setPackageAssertionStatus sets the assertion status for all classes in a package and all sub-packages of this package.
protected  void setSigners(Class<?> c, Object[] signers)
          setSigners sets the signers for a class to the given object array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassLoader

protected ClassLoader(ClassLoader parent)
Constructor to create a class loader with the given parent.

Parameters:
parent - the parent class loader.
Throws:
if - SecurityManager sm is installed and sm.checkCreateClassLoader() throws this exception.
Since:
1.2

ClassLoader

protected ClassLoader()
Constructor to create a class loader with system class loader as parent.

Throws:
if - SecurityManager sm is installed and sm.checkCreateClassLoader() throws this exception.
Method Detail

loadClass

public Class<?> loadClass(String name)
                   throws ClassNotFoundException
Load a class from this class loader without resolving it. This is equivalent to loadClass(name,false).

Parameters:
name - the class name, e.g., "java.lang.Object"
Returns:
the loaded class, never null
Throws:
ClassNotFoundException - if loading of the class failed.

loadClass

protected Class<?> loadClass(String name,
                             boolean resolve)
                      throws ClassNotFoundException
Load a class from this class loader, optionally resolving it. The class is first searched for using the parent class loader's laodClass(String) routine. If this fails, findClass(name) will be called on this class loader. If this succeeds and resolve is true, the found class will be resolved.

Parameters:
name - the class name, e.g., "java.lang.Object"
resolve - true if the class should be resolved.
Returns:
the loaded class, never null
Throws:
ClassNotFoundException - if loading of the class failed.

findClass

protected Class<?> findClass(String name)
                      throws ClassNotFoundException
Find a class with the given name. This method has to be redefined by a user class loader to obtain the class from this class loader's source. The default implementation always throws ClassNotFoundException.

Parameters:
name - the class name, e.g. "jav.lang.Object"
Returns:
the class if it was found, never null
Throws:
ClassNotFoundException - if the class was not found.
Since:
1.2

defineClass

protected final Class<?> defineClass(byte[] b,
                                     int off,
                                     int len)
                              throws ClassFormatError
Deprecated. use defineClass(String,byte[],int,int) instead.

Define a class from the give class file data.

Parameters:
b - the bytecode array for the class file data
off - the starting index of the class file data in b
len - the length of the class file data in b
Returns:
the class object if everything went well
Throws:
LinkageError - if linking of the class failed.
ClassFormatError - if the class file data did not specify a proper class file
OutOfMemoryError - if loading failed due to low memory
StackOverflowError - if loading failed due to stack overflow
ClassNotFoundException - if loading failed because super class or super interface was not found.
IndexOutOfBoundsException - if off<0, len<0 or off+len>b.length.
SecurityException - if loaded class is in package "java..." or class loaded into package with signed classes.

defineClass

protected final Class<?> defineClass(String name,
                                     byte[] b,
                                     int off,
                                     int len)
                              throws ClassFormatError
Define a class from the give class file data.

Parameters:
name - the expected name of the class
b - the bytecode array for the class file data
off - the starting index of the class file data in b
len - the length of the class file data in b
Returns:
the class object if everything went well
Throws:
LinkageError - if linking of the class failed.
ClassFormatError - if the class file data did not specify a proper class file
OutOfMemoryError - if loading failed due to low memory
StackOverflowError - if loading failed due to stack overflow
ClassNotFoundException - if loading failed because super class or super interface was not found.
IndexOutOfBoundsException - if off<0, len<0 or off+len>b.length.
SecurityException - if loaded class is in package "java..." or class loaded into package with signed classes.
Since:
1.1

defineClass

protected final Class<?> defineClass(String name,
                                     byte[] b,
                                     int off,
                                     int len,
                                     ProtectionDomain domain)
                              throws ClassFormatError
Define a class from the give class file data.

Parameters:
name - the expected name of the class
b - the bytecode array for the class file data
off - the starting index of the class file data in b
len - the length of the class file data in b
domain - the protection domain of the class
Returns:
the class object if everything went well
Throws:
LinkageError - if linking of the class failed.
ClassFormatError - if the class file data did not specify a proper class file or the class that was specified has a different name than the name argument that was specified
OutOfMemoryError - if loading failed due to low memory
StackOverflowError - if loading failed due to stack overflow
ClassNotFoundException - if loading failed because super class or super interface was not found.
IndexOutOfBoundsException - if off<0, len<0 or off+len>b.length.
SecurityException - if loaded class is in package "java..." or class loaded into package with signed classes.

resolveClass

protected final void resolveClass(Class<?> cl)
Resolve a class. If lazy linking of classes is enabled this function has no effect, since Jamaica then links the class on demand. If lazy linking is disabled, the class will be fully loaded and missing classes will cause an Error to be thrown.

Parameters:
cl - The class to be linked.
Throws:
NullPointerException - if cl==null

findSystemClass

protected final Class<?> findSystemClass(String name)
                                  throws ClassNotFoundException
Load class from the system class loader.

Parameters:
name - of the class, using '.' as package separator.
Returns:
the class loaded via system class loader.
Throws:
ClassNotFoundException - if loading of the class failed.
LinkageError - if linking of the class failed.

getParent

public final ClassLoader getParent()
getParent return the parent class loader of this class loader instance. The parent class loader was provided as an argument to the constructor of this class loader, or it was set to the system class loader by the constructor with no arguments.

Returns:
the parent class loader.
Throws:
SecurityException - if a SecurityManager sm is installed and the caller of this method was loaded by a class loader that is not an ancestor of this and sm.checkPermission(new RuntimePermission("getClassLoader")) throws this exception.
Since:
1.2

setSigners

protected final void setSigners(Class<?> c,
                                Object[] signers)
setSigners sets the signers for a class to the given object array.

Parameters:
c - the class whose signers should be set.
signers - an array of the signers.
Since:
1.1

findLoadedClass

protected final Class<?> findLoadedClass(String name)
findLoadedClass searches for a class with given name that was loaded by this class loader.

Parameters:
name - the name of the class, e.g., "java.lang.Object"
Returns:
the loaded class if it was found, null otherwise.
Since:
1.1

getResource

public URL getResource(String name)
getResource returns an URL for a resource with the given name.

Parameters:
name - the resource.
Returns:
the URL
Since:
1.1

getResources

public Enumeration<URL> getResources(String name)
                              throws IOException
getResources returns an enumeration of URLs for the resource with the given name.

Parameters:
name - the name of the resource
Returns:
an enumeration of URLs with this name, never null.
Throws:
IOException - if an IOException occurs while collecting the resources.
Since:
1.2

findResources

protected Enumeration<URL> findResources(String name)
                                  throws IOException
findResources returns an enumeration of URLs for the resource with the given name. This method should be redefined to return resource locations for this class loader.

Parameters:
name - the name of the resource
Returns:
an Enumeration of URL instances for locations of the resource.
Throws:
IOException - if an IOException occurs while collecting the resources.
Since:
1.2

findResource

protected URL findResource(String name)
findResource find a resource with a given name. This method should be redefined to return a resource location for this class loader.

Parameters:
name - the name of the resource
Returns:
the resource, null if not found.
Since:
1.2

getSystemResource

public static URL getSystemResource(String name)
getSystemResource determines the location of a resource in the system class path.

Parameters:
name - the name of the resource
Returns:
the location of the resource or null if not found.
Since:
1.1

getSystemResources

public static Enumeration<URL> getSystemResources(String name)
                                           throws IOException
getSystemResources determines the locations of all resources with a given name in the system class path.

Parameters:
name - the name of the resource.
Returns:
an Enumeration of URL instances of all locations of that resource, never null.
Throws:
IOException - if an IOException occurs while collecting the resources.
Since:
1.2

getResourceAsStream

public InputStream getResourceAsStream(String name)
getResourceAsStream finds a resource with the given name and opens an InputStream to read the resource data.

Parameters:
name - name of the resource
Returns:
InputStream instance that is ready to read the resource data, null if resource not found.
Since:
1.1

getSystemResourceAsStream

public static InputStream getSystemResourceAsStream(String name)
getSystemResourceAsStream finds a resource of the system class loader with the given name and opens an InputStream to read the resource data.

Parameters:
name - name of the resource
Returns:
InputStream instance that is ready to read the resource data, null if resource not found.
Since:
1.1

getSystemClassLoader

public static ClassLoader getSystemClassLoader()
getSystemClassLoader returns the system class loader.

Returns:
the system class loader.
Throws:
SecurityException - if a SecurityManager sm is installed and the caller of this method was loaded by a class loader that is not an ancestor of this and sm.checkPermission(new RuntimePermission("getClassLoader")) throws this exception.
IllegalStateException - if this is called from the constructor of the system class loader instance.
Error - if property "java.system.class.loader" is defined and the corresponding class loader could not be loaded or instantiated.

definePackage

protected Package definePackage(String name,
                                String specTitle,
                                String specVersion,
                                String specVendor,
                                String implTitle,
                                String implVersion,
                                String implVendor,
                                URL sealBase)
                         throws IllegalArgumentException
Defines a Package object for classes that are loaded through this ClassLoader. Making this routine work in non-heap memory this routines wraps the original code of this routines which is located in the definePackageHelper function.

Parameters:
name - of the package to define
specTitle - its specification title
specVersion - its specification version
specVendor - its specification vendor
implTitle - its implementation title
implVersion - its implementation version
implVendor - its implementation vendor.
sealBase - null for a non-sealed package, else URL to code base for seal.
Returns:
the new Package object for the named package
Throws:
IllegalArgumentException - if the package is already defined
Since:
1.2

getPackage

protected Package getPackage(String name)
Get the Package object for the named package if it is defined in this ClassLoader or in one of its ancestors. A Package object exists if at least one class was loaded from this package.

Parameters:
name - of the Package
Returns:
Package object or null if the package does not exist.
Since:
1.2

getPackages

protected Package[] getPackages()
getPackages returns an array of all packages defined by this class loader and all of its ancestors. Making this routine work in non-heap memory this routines wraps the original code of this routines which is located in the getPackagesHelper function.

Returns:
an array of all packages, never null.
Since:
1.2

findLibrary

protected String findLibrary(String libname)
findLibrary returns the path to load a shared library with the given name.

For JamaicaVM, this always returns null.

Parameters:
libname - the library name.
Returns:
the absolute path to the library, null if library not found.

setDefaultAssertionStatus

public void setDefaultAssertionStatus(boolean enabled)
setDefaultAssertionStatus enables or disables assertion checking for classes loaded via this class loader.

Parameters:
enabled - true to enable assertion checking, false to disable checking.
Since:
1.4

setPackageAssertionStatus

public void setPackageAssertionStatus(String name,
                                      boolean enabled)
setPackageAssertionStatus sets the assertion status for all classes in a package and all sub-packages of this package.

Parameters:
name - the name of the package
enabled - true to enable assertion checking, false to disable checking.
Since:
1.4

setClassAssertionStatus

public void setClassAssertionStatus(String name,
                                    boolean enabled)
setClassAssertionStatus sets the assertion status for a class with a given name.

Parameters:
name - the class name
enabled - true to enable assertion checking, false to disable checking.
Since:
1.4

clearAssertionStatus

public void clearAssertionStatus()
clearAssertionStatus removes all the assertion status settings for classes, packages and for this class loader. Assertion status will be set to false.

Since:
1.4

defineClass

protected final Class<?> defineClass(String name,
                                     ByteBuffer b,
                                     ProtectionDomain protectionDomain)
                              throws ClassFormatError
defineClass

Parameters:
name -
b -
protectionDomain -
Returns:
The Class object created from the data, and optional ProtectionDomain.
Throws:
ClassFormatError
Since:
1.5

aicas logoJamaica 6.4 release 1

aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2015 aicas GmbH. All Rights Reserved.