com.go.trove.util
Class ClassInjector

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--com.go.trove.util.ClassInjector

public class ClassInjector
extends java.lang.ClassLoader

A special ClassLoader that allows classes to be defined by directly injecting the bytecode. All classes other than those injected are loaded from the parent ClassLoader, which is the ClassLoader that loaded this class. If a directory is passed in, the ClassInjector looks there for non-injected class files before asking the parent ClassLoader for a class.

Version:
29 , 7/30/01
Author:
Brian S O'Neill

Constructor Summary
ClassInjector()
          Construct a ClassInjector that uses the ClassLoader that loaded this class as a parent, and it has no root class directory or root package.
ClassInjector(java.lang.ClassLoader parent)
          Construct a ClassInjector that has no root class directory or root package.
ClassInjector(java.lang.ClassLoader parent, java.io.File[] rootClassDirs, java.lang.String rootPackage)
           
ClassInjector(java.lang.ClassLoader parent, java.io.File[] rootClassDirs, java.lang.String rootPackage, boolean keepRawBytecode)
           
ClassInjector(java.lang.ClassLoader parent, java.io.File rootClassDir, java.lang.String rootPackage)
           
ClassInjector(java.io.File[] rootClassDirs, java.lang.String rootPackage)
          Construct a ClassInjector that uses the ClassLoader that loaded this class as a parent.
ClassInjector(java.io.File rootClassDir, java.lang.String rootPackage)
          Construct a ClassInjector that uses the ClassLoader that loaded this class as a parent.
 
Method Summary
protected  void define(java.lang.String name, byte[] data)
           
static ClassInjector getInstance()
          Returns a shared ClassInjector instance.
static ClassInjector getInstance(java.lang.ClassLoader loader)
          Returns a shared ClassInjector instance for the given ClassLoader.
 java.net.URL getResource(java.lang.String name)
           
 java.io.OutputStream getStream(java.lang.String name)
          Get a stream used to define a class.
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
           
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassInjector

public ClassInjector()
Construct a ClassInjector that uses the ClassLoader that loaded this class as a parent, and it has no root class directory or root package.

ClassInjector

public ClassInjector(java.lang.ClassLoader parent)
Construct a ClassInjector that has no root class directory or root package.
Parameters:
parent - optional parent ClassLoader to default to when a class cannot be loaded with this ClassInjector.

ClassInjector

public ClassInjector(java.io.File rootClassDir,
                     java.lang.String rootPackage)
Construct a ClassInjector that uses the ClassLoader that loaded this class as a parent.
Parameters:
rootClassDir - optional directory to look for non-injected classes
rootPackage - optional package name for the root directory

ClassInjector

public ClassInjector(java.lang.ClassLoader parent,
                     java.io.File rootClassDir,
                     java.lang.String rootPackage)
Parameters:
parent - optional parent ClassLoader to default to when a class cannot be loaded with this ClassInjector.
rootClassDir - optional directory to look for non-injected classes
rootPackage - optional package name for the root directory

ClassInjector

public ClassInjector(java.io.File[] rootClassDirs,
                     java.lang.String rootPackage)
Construct a ClassInjector that uses the ClassLoader that loaded this class as a parent.
Parameters:
rootClassDirs - optional directories to look for non-injected classes
rootPackage - optional package name for the root directory

ClassInjector

public ClassInjector(java.lang.ClassLoader parent,
                     java.io.File[] rootClassDirs,
                     java.lang.String rootPackage)
Parameters:
parent - optional parent ClassLoader to default to when a class cannot be loaded with this ClassInjector.
rootClassDirs - optional directories to look for non-injected classes
rootPackage - optional package name for the root directory

ClassInjector

public ClassInjector(java.lang.ClassLoader parent,
                     java.io.File[] rootClassDirs,
                     java.lang.String rootPackage,
                     boolean keepRawBytecode)
Parameters:
parent - optional parent ClassLoader to default to when a class cannot be loaded with this ClassInjector.
rootClassDirs - optional directories to look for non-injected classes
rootPackage - optional package name for the root directory
keepRawBytecode - if true, will cause the ClassInjector to store the raw bytecode of defined classes.
Method Detail

getInstance

public static ClassInjector getInstance()
Returns a shared ClassInjector instance.

getInstance

public static ClassInjector getInstance(java.lang.ClassLoader loader)
Returns a shared ClassInjector instance for the given ClassLoader.

getStream

public java.io.OutputStream getStream(java.lang.String name)
Get a stream used to define a class. Close the stream to finish the definition.
Parameters:
the - fully qualified name of the class to be defined.

getResource

public java.net.URL getResource(java.lang.String name)
Overrides:
getResource in class java.lang.ClassLoader

loadClass

protected java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
Overrides:
loadClass in class java.lang.ClassLoader

define

protected void define(java.lang.String name,
                      byte[] data)