1 16 17 package org.springframework.orm.jpa.persistenceunit; 18 19 import java.lang.instrument.ClassFileTransformer ; 20 import java.security.ProtectionDomain ; 21 22 import javax.persistence.spi.ClassTransformer; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 import org.springframework.util.Assert; 28 29 38 class ClassFileTransformerAdapter implements ClassFileTransformer { 39 40 private static final Log logger = LogFactory.getLog(ClassFileTransformerAdapter.class); 41 42 private final ClassTransformer classTransformer; 43 44 45 public ClassFileTransformerAdapter(ClassTransformer classTransformer) { 46 Assert.notNull(classTransformer, "ClassTransformer must not be null"); 47 this.classTransformer = classTransformer; 48 } 49 50 51 public byte[] transform( 52 ClassLoader loader, String className, Class <?> classBeingRedefined, 53 ProtectionDomain protectionDomain, byte[] classfileBuffer) { 54 55 try { 56 byte[] transformed = this.classTransformer.transform( 57 loader, className, classBeingRedefined, protectionDomain, classfileBuffer); 58 if (transformed != null && logger.isDebugEnabled()) { 59 logger.debug("Transformer of class [" + this.classTransformer.getClass().getName() + 60 "] transformed class [" + className + "]; bytes in=" + 61 classfileBuffer.length + "; bytes out=" + transformed.length); 62 } 63 return transformed; 64 } 65 catch (ClassCircularityError ex) { 66 logger.error("Error weaving class [" + className + "] with " + 67 "transformer of class [" + this.classTransformer.getClass().getName() + "]", ex); 68 throw new IllegalStateException ("Could not weave class [" + className + "]", ex); 69 } 70 catch (Throwable ex) { 71 if (logger.isWarnEnabled()) { 72 logger.warn("Error weaving class [" + className + "] with " + 73 "transformer of class [" + this.classTransformer.getClass().getName() + "]", ex); 74 } 75 throw new IllegalStateException ("Could not weave class [" + className + "]", ex); 77 } 78 } 79 80 81 @Override 82 public String toString() { 83 return "Standard ClassFileTransformer wrapping JPA transformer: " + this.classTransformer; 84 } 85 86 } 87 | Popular Tags |