ClassTransformerChain.java revision 674060f01e9090cd21b3c5656cc3204912ad17a6
1/* 2 * Copyright 2003,2004 The Apache Software Foundation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package org.mockito.cglib.transform; 17 18import org.mockito.asm.*; 19 20public class ClassTransformerChain extends AbstractClassTransformer { 21 private ClassTransformer[] chain; 22 23 public ClassTransformerChain(ClassTransformer[] chain) { 24 this.chain = (ClassTransformer[])chain.clone(); 25 } 26 27 public void setTarget(ClassVisitor v) { 28 super.setTarget(chain[0]); 29 ClassVisitor next = v; 30 for (int i = chain.length - 1; i >= 0; i--) { 31 chain[i].setTarget(next); 32 next = chain[i]; 33 } 34 } 35 36 public MethodVisitor visitMethod(int access, 37 String name, 38 String desc, 39 String signature, 40 String[] exceptions) { 41 return cv.visitMethod(access, name, desc, signature, exceptions); 42 } 43 44 public String toString() { 45 StringBuffer sb = new StringBuffer(); 46 sb.append("ClassTransformerChain{"); 47 for (int i = 0; i < chain.length; i++) { 48 if (i > 0) { 49 sb.append(", "); 50 } 51 sb.append(chain[i].toString()); 52 } 53 sb.append("}"); 54 return sb.toString(); 55 } 56} 57