1 16 package net.sf.cglib.transform.hook; 17 18 import java.util.Hashtable ; 19 import net.sf.cglib.core.*; 20 import net.sf.cglib.transform.*; 21 import org.codehaus.aspectwerkz.hook.ClassPreProcessor; 22 import org.objectweb.asm.ClassReader; 23 import org.objectweb.asm.ClassWriter; 24 25 abstract public class AbstractPreProcessor implements ClassPreProcessor { 26 public void initialize(Hashtable hashtable) { 27 } 28 29 public byte[] preProcess(String name, byte[] abyte, ClassLoader caller) { 30 try { 31 ClassTransformer t = getClassTransformer(name); 32 if (t == null) 33 return abyte; 34 ClassWriter w = new DebuggingClassWriter(true); 35 ClassGenerator gen = new ClassReaderGenerator(new ClassReader(abyte), false); 36 gen = new TransformingClassGenerator(gen, t); 37 gen.generateClass(w); 38 return w.toByteArray(); 39 } catch (Exception e) { 40 throw new CodeGenerationException(e); 41 } 42 } 43 44 abstract protected ClassTransformer getClassTransformer(String name); 45 } 46 | Popular Tags |