Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.lang.ClassLoader
gnu.gcj.runtime.SharedLibLoader
public class SharedLibLoader
extends ClassLoader
Constructor Summary | |
| |
|
Method Summary | |
Class<T> | |
URL |
|
Enumeration<E> |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public SharedLibLoader(String libname)
Load a shared library, and asociate a ClassLoader with it.
- Parameters:
libname
- named of shared library (passed to dlopen)
public SharedLibLoader(String libname, ClassLoader parent, int flags)
Load a shared library, and associate a ClassLoader with it.
- Parameters:
libname
- named of shared library (passed to dlopen)parent
- the parent ClassLoader
public Class<T> findClass(String name) throws ClassNotFoundException
Called for every class name that is needed but has not yet been defined by this classloader or one of its parents. It is called byloadClass()
after bothfindLoadedClass()
andparent.loadClass()
couldn't provide the requested class. The default implementation throws aClassNotFoundException
. Subclasses should override this method. An implementation of this method in a subclass should get the class bytes of the class (if it can find them), if the package of the requested class doesn't exist it should define the package and finally it should call define the actual class. It does not have to resolve the class. It should look something like the following:
// Get the bytes that describe the requested class byte[] classBytes = classLoaderSpecificWayToFindClassBytes(name); // Get the package name int lastDot = name.lastIndexOf('.'); if (lastDot != -1) { String packageName = name.substring(0, lastDot); // Look if the package already exists if (getPackage(packageName) == null) { // define the package definePackage(packageName, ...); } } // Define and return the class return defineClass(name, classBytes, 0, classBytes.length);loadClass()
makes sure that theClass
returned byfindClass()
will later be returned byfindLoadedClass()
when the same class name is requested.
- Overrides:
- findClass in interface ClassLoader
- Parameters:
name
- class name to find (including the package name)
- Returns:
- the requested Class
- Throws:
ClassNotFoundException
- when the class can not be found
- Since:
- 1.2
public URL findResource(String name)
Called whenever a resource is needed that could not be provided by one of the parents of this classloader. It is called bygetResource()
afterparent.getResource()
couldn't provide the requested resource. The default implementation always returns null. Subclasses should override this method when they can provide a way to return a URL to a named resource.
- Overrides:
- findResource in interface ClassLoader
- Parameters:
name
- the name of the resource to be found
- Returns:
- a URL to the named resource or null when not found
- Since:
- 1.2
public Enumeration<E> findResources(String name) throws IOException
Called whenever all locations of a named resource are needed. It is called bygetResources()
after it has calledparent.getResources()
. The results are combined by thegetResources()
method. The default implementation always returns an empty Enumeration. Subclasses should override it when they can provide an Enumeration of URLs (possibly just one element) to the named resource. The first URL of the Enumeration should be the same as the one returned byfindResource
.
- Overrides:
- findResources in interface ClassLoader
- Parameters:
name
- the name of the resource to be found
- Returns:
- a possibly empty Enumeration of URLs to the named resource
- Throws:
IOException
- if I/O errors occur in the process
- Since:
- 1.2