1 17 package org.apache.geronimo.transformer; 18 19 import java.lang.instrument.ClassFileTransformer ; 20 import java.lang.instrument.IllegalClassFormatException ; 21 import java.security.ProtectionDomain ; 22 import java.util.List ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 26 29 public class TransformerCollection implements ClassFileTransformer { 30 31 private final List <ClassFileTransformer > transformers = new ArrayList <ClassFileTransformer >(); 32 33 public byte[] transform(ClassLoader loader, String className, Class <?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { 34 boolean changed = false; 35 for (ClassFileTransformer transformer : transformers) { 36 byte[] transformed = transformer.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer); 37 if (transformed != null) { 38 changed = true; 39 classfileBuffer = transformed; 40 } 41 } 42 return changed? classfileBuffer: null; 43 } 44 45 public void addTransformer(ClassFileTransformer classFileTransformer) { 46 transformers.add(classFileTransformer); 47 } 48 49 public void removeTransformer(ClassFileTransformer classFileTransformer) { 50 transformers.remove(classFileTransformer); 51 } 52 } 53 | Popular Tags |