CglibClassTransformerpublic class CglibClassTransformer extends org.hibernate.bytecode.AbstractClassTransformerImpl Enhance the classes allowing them to implements InterceptFieldEnabled
This interface is then used by Hibernate for some optimizations. |
Fields Summary |
---|
private static Log | log |
Methods Summary |
---|
private org.objectweb.asm.Attribute[] | attributes()
return Attributes.getDefaultAttributes();
| protected byte[] | doTransform(java.lang.ClassLoader loader, java.lang.String className, java.lang.Class classBeingRedefined, java.security.ProtectionDomain protectionDomain, byte[] classfileBuffer)
ClassReader reader;
try {
reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
}
catch (IOException e) {
log.error( "Unable to read class", e );
throw new HibernateException( "Unable to read class: " + e.getMessage() );
}
String[] names = ClassNameReader.getClassInfo( reader );
ClassWriter w = new DebuggingClassWriter( true );
ClassTransformer t = getClassTransformer( names );
if ( t != null ) {
if ( log.isDebugEnabled() ) {
log.debug( "Enhancing " + className );
}
ByteArrayOutputStream out;
byte[] result;
try {
reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
new TransformingClassGenerator(
new ClassReaderGenerator( reader, attributes(), skipDebug() ), t
).generateClass( w );
out = new ByteArrayOutputStream();
out.write( w.toByteArray() );
result = out.toByteArray();
out.close();
}
catch (Exception e) {
log.error( "Unable to transform class", e );
throw new HibernateException( "Unable to transform class: " + e.getMessage() );
}
return result;
}
return classfileBuffer;
| private net.sf.cglib.transform.ClassTransformer | getClassTransformer(java.lang.String[] classInfo)
if ( isAlreadyInstrumented( classInfo ) ) {
return null;
}
return new InterceptFieldTransformer(
new InterceptFieldFilter() {
public boolean acceptRead(Type owner, String name) {
return fieldFilter.shouldTransformFieldAccess( classInfo[0], owner.getClassName(), name );
}
public boolean acceptWrite(Type owner, String name) {
return fieldFilter.shouldTransformFieldAccess( classInfo[0], owner.getClassName(), name );
}
}
);
| private boolean | isAlreadyInstrumented(java.lang.String[] classInfo)
for ( int i = 1; i < classInfo.length; i++ ) {
if ( InterceptFieldEnabled.class.getName().equals( classInfo[i] ) ) {
return true;
}
}
return false;
| private boolean | skipDebug()
return false;
|
|