KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2003 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 ClassVisitorTee implements ClassVisitor {
21     private ClassVisitor cv1, cv2;
22     
23     public ClassVisitorTee(ClassVisitor cv1, ClassVisitor cv2) {
24         this.cv1 = cv1;
25         this.cv2 = cv2;
26     }
27
28     public void visit(int version,
29                       int access,
30                       String JavaDoc name,
31                       String JavaDoc signature,
32                       String JavaDoc superName,
33                       String JavaDoc[] interfaces) {
34         cv1.visit(version, access, name, signature, superName, interfaces);
35         cv2.visit(version, access, name, signature, superName, interfaces);
36     }
37
38     public void visitEnd() {
39         cv1.visitEnd();
40         cv2.visitEnd();
41         cv1 = cv2 = null;
42     }
43
44     public void visitInnerClass(String JavaDoc name, String JavaDoc outerName, String JavaDoc innerName, int access) {
45         cv1.visitInnerClass(name, outerName, innerName, access);
46         cv2.visitInnerClass(name, outerName, innerName, access);
47     }
48
49     public FieldVisitor visitField(int access,
50                                    String JavaDoc name,
51                                    String JavaDoc desc,
52                                    String JavaDoc signature,
53                                    Object JavaDoc value) {
54         FieldVisitor fv1 = cv1.visitField(access, name, desc, signature, value);
55         FieldVisitor fv2 = cv2.visitField(access, name, desc, signature, value);
56         if (fv1 == null)
57             return fv2;
58         if (fv2 == null)
59             return fv1;
60         return new FieldVisitorTee(fv1, fv2);
61     }
62
63
64     public MethodVisitor visitMethod(int access,
65                                      String JavaDoc name,
66                                      String JavaDoc desc,
67                                      String JavaDoc signature,
68                                      String JavaDoc[] exceptions) {
69         MethodVisitor mv1 = cv1.visitMethod(access, name, desc, signature, exceptions);
70         MethodVisitor mv2 = cv2.visitMethod(access, name, desc, signature, exceptions);
71         if (mv1 == null)
72             return mv2;
73         if (mv2 == null)
74             return mv1;
75         return new MethodVisitorTee(mv1, mv2);
76     }
77
78     public void visitSource(String JavaDoc source, String JavaDoc debug) {
79         cv1.visitSource(source, debug);
80         cv2.visitSource(source, debug);
81     }
82
83     public void visitOuterClass(String JavaDoc owner, String JavaDoc name, String JavaDoc desc) {
84         cv1.visitOuterClass(owner, name, desc);
85         cv2.visitOuterClass(owner, name, desc);
86     }
87
88     public AnnotationVisitor visitAnnotation(String JavaDoc desc, boolean visible) {
89         return AnnotationVisitorTee.getInstance(cv1.visitAnnotation(desc, visible),
90                                                 cv2.visitAnnotation(desc, visible));
91     }
92     
93     public void visitAttribute(Attribute attrs) {
94         cv1.visitAttribute(attrs);
95         cv2.visitAttribute(attrs);
96     }
97 }
98
Popular Tags