View Javadoc
1 package net.sf.cglib.transform; 2 3 4 5 import java.io.*; 6 7 import java.util.*; 8 9 import net.sf.cglib.core.*; 10 11 import org.apache.tools.ant.BuildException; 12 13 import org.objectweb.asm.ClassAdapter; 14 15 import org.objectweb.asm.ClassReader; 16 17 import org.objectweb.asm.ClassWriter; 18 19 20 21 abstract public class AbstractTransformTask extends AbstractProcessTask { 22 23 private boolean verbose; 24 25 26 27 public void setVerbose(boolean verbose) { 28 29 this.verbose = verbose; 30 31 } 32 33 34 35 abstract protected ClassTransformer getClassTransformer(String name); 36 37 38 39 protected void processFile(File file) throws Exception { 40 41 ClassWriter w = new DebuggingClassWriter(true); 42 43 String name = ClassNameReader.getClassName(getClassReader(file)); 44 45 ClassTransformer t = getClassTransformer(name); 46 47 if (t != null) { 48 49 new TransformingClassGenerator(new ClassReaderGenerator(getClassReader(file), true), t).generateClass(w); 50 51 FileOutputStream fos = new FileOutputStream(file); 52 53 fos.write(w.toByteArray()); 54 55 fos.close(); 56 57 if (verbose) { 58 59 System.out.println("Enhancing class " + name); 60 61 } 62 63 } 64 65 } 66 67 68 69 private static ClassReader getClassReader(File file) throws Exception { 70 71 InputStream in = new BufferedInputStream(new FileInputStream(file)); 72 73 ClassReader r = new ClassReader(in); 74 75 in.close(); 76 77 return r; 78 79 } 80 81 } 82

This page was automatically generated by Maven