com.javageeks.classloader
Class StrategyClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--com.javageeks.classloader.StrategyClassLoader
All Implemented Interfaces:
ClassLoaderStrategy, java.io.Serializable

public class StrategyClassLoader
extends java.lang.ClassLoader
implements ClassLoaderStrategy

StrategyClassLoader uses the Strategy pattern to implement more reusable (and chainable) ClassLoader-possibilities.

Note that the StrategyClassLoader itself in turn implements the ClassLoaderStrategy interface; this means that instances of the StrategyClassLoader could, in turn, be used within a StrategyClassLoader. The need for this isn't obvious until one considers the CompositeClassLoader, which uses a collection of ClassLoaderStrategy-implementing classes to do its work. Without implementing this interface, StrategyClassLoader would be unable to participate in that system.

See Also:
Serialized Form

Constructor Summary
StrategyClassLoader(ClassLoaderStrategy strategy)
          Construct using the given Strategy instance and use the ClassLoader that loaded this class as the parent.
StrategyClassLoader(ClassLoaderStrategy strategy, java.lang.ClassLoader parent)
          Construct using the given Strategy instance and use the ClassLoader passed in as the parent.
 
Method Summary
protected  java.lang.Class findClass(java.lang.String name)
          Find the class bytecode; defers to the Strategy's findClassBytes method.
 byte[] findClassBytes(java.lang.String className)
          Return byte array (which will be turned into a Class instance via ClassLoader.defineClass) for class
 java.lang.String findLibraryPath(java.lang.String libraryName)
          Return full path to native library given by the name libraryName.
 java.util.Enumeration findResourcesEnum(java.lang.String resourceName)
          Return Enumeration of resources corresponding to resourceName.
 java.net.URL findResourceURL(java.lang.String resourceName)
          Return URL for resource given by resourceName
static void main(java.lang.String[] args)
          For JDK1.1 use, uncomment the following method
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StrategyClassLoader

public StrategyClassLoader(ClassLoaderStrategy strategy)
Construct using the given Strategy instance and use the ClassLoader that loaded this class as the parent.

StrategyClassLoader

public StrategyClassLoader(ClassLoaderStrategy strategy,
                           java.lang.ClassLoader parent)
Construct using the given Strategy instance and use the ClassLoader passed in as the parent.
Method Detail

findClassBytes

public byte[] findClassBytes(java.lang.String className)
Return byte array (which will be turned into a Class instance via ClassLoader.defineClass) for class
Specified by:
findClassBytes in interface ClassLoaderStrategy

findResourceURL

public java.net.URL findResourceURL(java.lang.String resourceName)
Return URL for resource given by resourceName
Specified by:
findResourceURL in interface ClassLoaderStrategy

findResourcesEnum

public java.util.Enumeration findResourcesEnum(java.lang.String resourceName)
Return Enumeration of resources corresponding to resourceName.
Specified by:
findResourcesEnum in interface ClassLoaderStrategy

findLibraryPath

public java.lang.String findLibraryPath(java.lang.String libraryName)
Return full path to native library given by the name libraryName.
Specified by:
findLibraryPath in interface ClassLoaderStrategy

findClass

protected java.lang.Class findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Find the class bytecode; defers to the Strategy's findClassBytes method.
Overrides:
findClass in class java.lang.ClassLoader

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
For JDK1.1 use, uncomment the following method