KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 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 abstract public class AbstractClassFilterTransformer extends AbstractClassTransformer {
21     private ClassTransformer pass;
22     private ClassVisitor target;
23
24     public void setTarget(ClassVisitor target) {
25         super.setTarget(target);
26         pass.setTarget(target);
27     }
28
29     protected AbstractClassFilterTransformer(ClassTransformer pass) {
30         this.pass = pass;
31     }
32
33     abstract protected boolean accept(int version, int access, String JavaDoc name, String JavaDoc signature, String JavaDoc superName, String JavaDoc[] interfaces);
34
35     public void visit(int version,
36                       int access,
37                       String JavaDoc name,
38                       String JavaDoc signature,
39                       String JavaDoc superName,
40                       String JavaDoc[] interfaces) {
41         target = accept(version, access, name, signature, superName, interfaces) ? pass : cv;
42         target.visit(version, access, name, signature, superName, interfaces);
43     }
44     
45     public void visitSource(String JavaDoc source, String JavaDoc debug) {
46         target.visitSource(source, debug);
47     }
48     
49     public void visitOuterClass(String JavaDoc owner, String JavaDoc name, String JavaDoc desc) {
50         target.visitOuterClass(owner, name, desc);
51     }
52     
53     public AnnotationVisitor visitAnnotation(String JavaDoc desc, boolean visible) {
54         return target.visitAnnotation(desc, visible);
55     }
56     
57     public void visitAttribute(Attribute attr) {
58         target.visitAttribute(attr);
59     }
60     
61     public void visitInnerClass(String JavaDoc name, String JavaDoc outerName, String JavaDoc innerName, int access) {
62         target.visitInnerClass(name, outerName, innerName, access);
63     }
64
65     public FieldVisitor visitField(int access,
66                                    String JavaDoc name,
67                                    String JavaDoc desc,
68                                    String JavaDoc signature,
69                                    Object JavaDoc value) {
70         return target.visitField(access, name, desc, signature, value);
71     }
72     
73     public MethodVisitor visitMethod(int access,
74                                      String JavaDoc name,
75                                      String JavaDoc desc,
76                                      String JavaDoc signature,
77                                      String JavaDoc[] exceptions) {
78         return target.visitMethod(access, name, desc, signature, exceptions);
79     }
80
81     public void visitEnd() {
82         target.visitEnd();
83         target = null; // just to be safe
84
}
85 }
86
Popular Tags