gnu.gcj.runtime

Class SharedLibLoader


public class SharedLibLoader
extends ClassLoader

A ClassLoader backed by a gcj-compiled shared library.

Constructor Summary

SharedLibLoader(String libname)
Load a shared library, and asociate a ClassLoader with it.
SharedLibLoader(String libname, ClassLoader parent, int flags)
Load a shared library, and associate a ClassLoader with it.

Method Summary

Class<T>
findClass(String name)
Called for every class name that is needed but has not yet been defined by this classloader or one of its parents.
URL
findResource(String name)
Called whenever a resource is needed that could not be provided by one of the parents of this classloader.
Enumeration<E>
findResources(String name)
Called whenever all locations of a named resource are needed.

Methods inherited from class java.lang.ClassLoader

clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

SharedLibLoader

public SharedLibLoader(String libname)
Load a shared library, and asociate a ClassLoader with it.
Parameters:
libname - named of shared library (passed to dlopen)

SharedLibLoader

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

Method Details

findClass

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 by loadClass() after both findLoadedClass() and parent.loadClass() couldn't provide the requested class.

The default implementation throws a ClassNotFoundException. 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 the Class returned by findClass() will later be returned by findLoadedClass() 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

findResource

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 by getResource() after parent.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

findResources

public Enumeration<E> findResources(String name)
            throws IOException
Called whenever all locations of a named resource are needed. It is called by getResources() after it has called parent.getResources(). The results are combined by the getResources() 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 by findResource.

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

Copyright (C) 2001, 2003 Free Software Foundation This file is part of libgcj. This software is copyrighted work licensed under the terms of the Libgcj License. Please consult the file "LIBGCJ_LICENSE" for details.