ClassLoader loader,
String className,
Class classBeingRedefined,
ProtectionDomain protectionDomain,
byte[] classfileBuffer) {
ClassFile classfile;
try {
// WARNING: classfile only
classfile = new ClassFile( new DataInputStream( new ByteArrayInputStream( classfileBuffer ) ) );
}
catch (IOException e) {
LOG.unableToBuildEnhancementMetamodel( className );
return classfileBuffer;
}
final ClassPool cp = new ClassPool();
cp.appendSystemPath();
cp.appendClassPath( new ClassClassPath( this.getClass() ) );
cp.appendClassPath( new ClassClassPath( classfile.getClass() ) );
try {
cp.makeClassIfNew( new ByteArrayInputStream( classfileBuffer ) );
}
catch (IOException e) {
throw new RuntimeException( e.getMessage(), e );
}
final FieldTransformer transformer = getFieldTransformer( classfile, cp );
if ( transformer != null ) {
LOG.debugf( "Enhancing %s", className );
DataOutputStream out = null;
try {
transformer.transform( classfile );
final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
out = new DataOutputStream( byteStream );
classfile.write( out );
return byteStream.toByteArray();
}
catch (Exception e) {
LOG.unableToTransformClass( e.getMessage() );
throw new HibernateException( "Unable to transform class: " + e.getMessage() );