KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > cglib > transform > ClassTransformerChain


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  */

16 package net.sf.cglib.transform;
17
18 import org.objectweb.asm.*;
19
20 public 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 JavaDoc name,
38                                      String JavaDoc desc,
39                                      String JavaDoc signature,
40                                      String JavaDoc[] exceptions) {
41         return cv.visitMethod(access, name, desc, signature, exceptions);
42     }
43
44     public String JavaDoc toString() {
45         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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
Popular Tags