org.apache.jdo.impl.enhancer
Class EnhancerClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byjava.security.SecureClassLoader
          extended byjava.net.URLClassLoader
              extended byorg.apache.jdo.impl.enhancer.EnhancerClassLoader

public class EnhancerClassLoader
extends java.net.URLClassLoader

Implements a ClassLoader which automatically enchances the .class files according to the EnhancerMetaData information in the jar archive.

Author:
Yury Kamen, Martin Zaun

Nested Class Summary
 
Nested classes inherited from class java.lang.ClassLoader
 
Field Summary
private  java.security.AccessControlContext acc
           
private  boolean debug
           
static java.lang.String DO_TIMING_STATISTICS
           
private  boolean doTiming
           
private  ClassFileEnhancer enhancer
           
private  EnhancerMetaData metaData
           
private  java.io.PrintWriter out
           
private  java.lang.ref.WeakReference outByteCodeRef
           
private  java.util.Properties settings
           
private  sun.misc.URLClassPath ucp
           
static java.lang.String VERBOSE_LEVEL
           
static java.lang.String VERBOSE_LEVEL_DEBUG
           
static java.lang.String VERBOSE_LEVEL_QUIET
           
static java.lang.String VERBOSE_LEVEL_VERBOSE
           
static java.lang.String VERBOSE_LEVEL_WARN
           
 
Fields inherited from class java.security.SecureClassLoader
 
Fields inherited from class java.lang.ClassLoader
 
Constructor Summary
  EnhancerClassLoader(java.lang.String classpath, EnhancerMetaData metaData, java.util.Properties settings, java.io.PrintWriter out)
          Creates a new EnhancerClassLoader for the specified url.
  EnhancerClassLoader(java.lang.String classpath, java.util.Properties settings, java.io.PrintWriter out)
          Creates a new EnhancerClassLoader for the specified url.
protected EnhancerClassLoader(java.net.URL[] urls)
          Creates a new EnhancerClassLoader for the specified url.
protected EnhancerClassLoader(java.net.URL[] urls, java.lang.ClassLoader loader)
          Creates a new EnhancerClassLoader for the specified url.
  EnhancerClassLoader(java.net.URL[] urls, EnhancerMetaData metaData, java.util.Properties settings, java.io.PrintWriter out)
          Creates a new EnhancerClassLoader for the specified url.
  EnhancerClassLoader(java.net.URL[] urls, java.util.Properties settings, java.io.PrintWriter out)
          Creates a new EnhancerClassLoader for the specified url.
 
Method Summary
protected  void addURL(java.net.URL url)
          Appends the specified URL to the list of URLs to search for classes and resources.
(package private) static void affirm(boolean cond)
           
private  void checkUCP(java.net.URL[] urls)
           
private  java.lang.Class defineClass(java.lang.String name, sun.misc.Resource res)
          Defines a Class using the class bytes obtained from the specified Resource.
private  byte[] enhance(java.lang.String name, byte[] data, int off, int len)
           
private  java.lang.Class findAndEnhanceClass(java.lang.String name)
          Finds and loads the class with the specified name from the URL search path.
private  void init(EnhancerMetaData metaData, java.util.Properties settings, java.io.PrintWriter out)
          Initialize the EnhancingClassLoader
private  boolean isSealed(java.lang.String name, java.util.jar.Manifest man)
          Returns true if the specified package name is sealed according to the given manifest.
 java.lang.Class loadClass(java.lang.String name, boolean resolve)
           
private  void message()
           
private  void message(java.lang.Exception e)
           
private  void message(java.lang.String s)
           
static java.net.URL[] pathToURLs(java.lang.String classpath)
           
 
Methods inherited from class java.net.URLClassLoader
definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DO_TIMING_STATISTICS

public static final java.lang.String DO_TIMING_STATISTICS
See Also:
Constant Field Values

VERBOSE_LEVEL

public static final java.lang.String VERBOSE_LEVEL
See Also:
Constant Field Values

VERBOSE_LEVEL_QUIET

public static final java.lang.String VERBOSE_LEVEL_QUIET
See Also:
Constant Field Values

VERBOSE_LEVEL_WARN

public static final java.lang.String VERBOSE_LEVEL_WARN
See Also:
Constant Field Values

VERBOSE_LEVEL_VERBOSE

public static final java.lang.String VERBOSE_LEVEL_VERBOSE
See Also:
Constant Field Values

VERBOSE_LEVEL_DEBUG

public static final java.lang.String VERBOSE_LEVEL_DEBUG
See Also:
Constant Field Values

debug

private boolean debug

doTiming

private boolean doTiming

out

private java.io.PrintWriter out

enhancer

private ClassFileEnhancer enhancer

metaData

private EnhancerMetaData metaData

settings

private java.util.Properties settings

outByteCodeRef

private java.lang.ref.WeakReference outByteCodeRef

ucp

private final sun.misc.URLClassPath ucp

acc

private final java.security.AccessControlContext acc
Constructor Detail

EnhancerClassLoader

protected EnhancerClassLoader(java.net.URL[] urls)
Creates a new EnhancerClassLoader for the specified url.

Parameters:
urls - the classpath to search

EnhancerClassLoader

protected EnhancerClassLoader(java.net.URL[] urls,
                              java.lang.ClassLoader loader)
Creates a new EnhancerClassLoader for the specified url.

Parameters:
urls - the classpath to search

EnhancerClassLoader

public EnhancerClassLoader(java.lang.String classpath,
                           java.util.Properties settings,
                           java.io.PrintWriter out)
Creates a new EnhancerClassLoader for the specified url.

Parameters:
classpath - the classpath to search

EnhancerClassLoader

public EnhancerClassLoader(java.net.URL[] urls,
                           java.util.Properties settings,
                           java.io.PrintWriter out)
Creates a new EnhancerClassLoader for the specified url.

Parameters:
urls - the classpath to search

EnhancerClassLoader

public EnhancerClassLoader(java.lang.String classpath,
                           EnhancerMetaData metaData,
                           java.util.Properties settings,
                           java.io.PrintWriter out)
Creates a new EnhancerClassLoader for the specified url.

Parameters:
classpath - the classpath to search

EnhancerClassLoader

public EnhancerClassLoader(java.net.URL[] urls,
                           EnhancerMetaData metaData,
                           java.util.Properties settings,
                           java.io.PrintWriter out)
Creates a new EnhancerClassLoader for the specified url.

Parameters:
urls - the classpath to search
Method Detail

pathToURLs

public static java.net.URL[] pathToURLs(java.lang.String classpath)

affirm

static final void affirm(boolean cond)

message

private final void message()

message

private final void message(java.lang.String s)

message

private final void message(java.lang.Exception e)

addURL

protected void addURL(java.net.URL url)
Appends the specified URL to the list of URLs to search for classes and resources.

Parameters:
url - the URL to be added to the search path of URLs

checkUCP

private void checkUCP(java.net.URL[] urls)

init

private void init(EnhancerMetaData metaData,
                  java.util.Properties settings,
                  java.io.PrintWriter out)
Initialize the EnhancingClassLoader


loadClass

public java.lang.Class loadClass(java.lang.String name,
                                 boolean resolve)
                          throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

findAndEnhanceClass

private java.lang.Class findAndEnhanceClass(java.lang.String name)
                                     throws java.lang.ClassNotFoundException
Finds and loads the class with the specified name from the URL search path. Any URLs referring to JAR files are loaded and opened as needed until the class is found.

Parameters:
name - the name of the class
Returns:
the resulting class
Throws:
java.lang.ClassNotFoundException - if the class could not be found

defineClass

private java.lang.Class defineClass(java.lang.String name,
                                    sun.misc.Resource res)
                             throws java.io.IOException,
                                    java.lang.ClassNotFoundException
Defines a Class using the class bytes obtained from the specified Resource. The resulting Class must be resolved before it can be used.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

enhance

private byte[] enhance(java.lang.String name,
                       byte[] data,
                       int off,
                       int len)
                throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

isSealed

private boolean isSealed(java.lang.String name,
                         java.util.jar.Manifest man)
Returns true if the specified package name is sealed according to the given manifest.