FileDocCategorySizeDatePackage
InstrumentedClassLoader.javaAPI DocHibernate 3.2.51635Thu Aug 03 15:35:26 BST 2006org.hibernate.bytecode

InstrumentedClassLoader

public class InstrumentedClassLoader extends ClassLoader
A specialized classloader which performs bytecode enhancement on class definitions as they are loaded into the classloader scope.
author
Emmanuel Bernard
author
Steve Ebersole

Fields Summary
private ClassTransformer
classTransformer
Constructors Summary
public InstrumentedClassLoader(ClassLoader parent, ClassTransformer classTransformer)

		super( parent );
		this.classTransformer = classTransformer;
	
Methods Summary
public java.lang.ClassloadClass(java.lang.String name)

		if ( name.startsWith( "java." ) || classTransformer == null ) {
			return getParent().loadClass( name );
		}

		Class c = findLoadedClass( name );
		if ( c != null ) {
			return c;
		}

		InputStream is = this.getResourceAsStream( name.replace( '.", '/" ) + ".class" );
		if ( is == null ) {
			throw new ClassNotFoundException( name + " not found" );
		}

		try {
			byte[] originalBytecode = ByteCodeHelper.readByteCode( is );
			byte[] transformedBytecode = classTransformer.transform( getParent(), name, null, null, originalBytecode );
			if ( originalBytecode == transformedBytecode ) {
				// no transformations took place, so handle it as we would a
				// non-instrumented class
				return getParent().loadClass( name );
			}
			else {
				return defineClass( name, transformedBytecode, 0, transformedBytecode.length );
			}
		}
		catch( Throwable t ) {
			throw new ClassNotFoundException( name + " not found", t );
		}