com.ibm.as400.ui.framework.java
Class FileClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by com.ibm.as400.ui.framework.java.FileClassLoader

public class FileClassLoader
extends ClassLoader

A class loader which is capable of locating and loading class files from its own internally defined classpath. FileClassLoader was developed to solve two problems:

For more information on class loaders and namespaces see Inside the Java Virtual Machine by Bill Venners, ISBN 0-07-135093-4.

Since:
v5r1m0
Author:
Andreas Schauberer, Doug Petty

Constructor Summary
Constructor and Description
FileClassLoader()
          Creates a new FileClassLoader object.
FileClassLoader(String classpath)
          Creates a new FileClassLoader object using the specified classpath.
 
Method Summary
Modifier and Type Method and Description
 void addPath(String pathname)
          Appends a new file or directory name to the classpath for this FileClassLoader.
 void clearCache()
          Clears the cached classes on a user request before the garbage collector gets invoked.
 String getClasspath()
          Returns the classpath for this FileClassLoader.
 URL getResource(String name)
          Finds the resource with the given name.
 InputStream getResourceAsStream(String name)
          Returns an input stream for reading the specified resource.
 Class loadClass(String name, boolean resolve)
          Loads the class with the specified name.
 boolean removePath(String pathname)
          Removes the specified file or directory name from the classpath for this FileClassLoader.
 void setClasspath(String classpath)
          Sets the classpath for this FileClassLoader.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileClassLoader

public FileClassLoader()
Creates a new FileClassLoader object. The parent class loader is the ClassLoader returned by the method getSystemClassLoader().

If there is a security manager, its checkCreateClassLoader method is called. This may result in a security exception.

Throws:
SecurityException - if a security manager exists and its checkCreateClassLoader method doesn't allow creation of a new class loader.
Since:
v5r1m0
See Also:
SecurityException, SecurityManager.checkCreateClassLoader()

FileClassLoader

public FileClassLoader(String classpath)
Creates a new FileClassLoader object using the specified classpath. The parent class loader is the ClassLoader returned by the method getSystemClassLoader().

If there is a security manager, its checkCreateClassLoader method is called. This may result in a security exception.

Parameters:
classpath - The classpath string that this FileClassLoader will use when searching for class files.
Throws:
SecurityException - if a security manager exists and its checkCreateClassLoader method doesn't allow creation of a new class loader.
Since:
v5r1m0
See Also:
SecurityException, SecurityManager.checkCreateClassLoader()
Method Detail

setClasspath

public void setClasspath(String classpath)
Sets the classpath for this FileClassLoader.

Parameters:
classpath - The classpath string that this FileClassLoader will use when searching for class files.
Since:
v5r1m0

addPath

public void addPath(String pathname)
Appends a new file or directory name to the classpath for this FileClassLoader.

Parameters:
pathname - A valid name of a file system directory, ZIP file, or JAR file. The name may either be an absolute pathname or specified relative to the current directory.
Throws:
IllegalArgumentException - If the specified pathname is not a valid file system directory, ZIP file name or JAR file name.
Since:
v5r1m0

removePath

public boolean removePath(String pathname)
Removes the specified file or directory name from the classpath for this FileClassLoader.

Parameters:
pathname - The name of a file system directory, ZIP file, or JAR file.
Returns:
true if the path was successfully removed; false if the classpath does not contain the path.
Since:
v5r1m0

getClasspath

public String getClasspath()
Returns the classpath for this FileClassLoader.

Returns:
The classpath string for this FileClassLoader.
Since:
v5r1m0

loadClass

public Class loadClass(String name,
                       boolean resolve)
                throws ClassNotFoundException
Loads the class with the specified name. This method delegates to the system class loader for the core Java API, and attempts to load class files from the classpath for everything else.

Overrides:
loadClass in class ClassLoader
Parameters:
name - the name of the class
resolve - if true then resolve the class
Returns:
the resulting Class object
Throws:
ClassNotFoundException - if the class could not be found
Since:
v5r1m0

getResourceAsStream

public InputStream getResourceAsStream(String name)
Returns an input stream for reading the specified resource.

This method will first attempt to load the resource from the classpath. If that fails then this method will call the system class loader to find the resource.

Overrides:
getResourceAsStream in class ClassLoader
Parameters:
name - the resource name
Returns:
an input stream for reading the resource, or null if the resource could not be found
Since:
v5r1m0

getResource

public URL getResource(String name)
Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

The name of a resource is a "/"-separated path name that identifies the resource.

This method will first attempt to load the resource from the classpath. If that fails then this method will call the system class loader to find the resource.

Overrides:
getResource in class ClassLoader
Parameters:
name - resource name
Returns:
a URL for reading the resource, or null if the resource could not be found or the caller doesn't have adequate privileges to get the resource.
Since:
v5r1m0

clearCache

public void clearCache()
Clears the cached classes on a user request before the garbage collector gets invoked.

Since:
v5r1m0f