1+ package name .dhruba .javaagent ;
2+
3+ import java .lang .instrument .IllegalClassFormatException ;
4+ import java .security .ProtectionDomain ;
5+
6+ import org .objectweb .asm .Opcodes ;
7+ import org .slf4j .Logger ;
8+ import org .slf4j .LoggerFactory ;
9+
10+ public class ClassFileTransformer implements java .lang .instrument .ClassFileTransformer , Opcodes {
11+
12+ static final Logger logger = LoggerFactory .getLogger (ClassFileTransformer .class );
13+
14+ @ Override
15+ public byte [] transform (ClassLoader loader , String className , Class <?> classBeingRedefined ,
16+ ProtectionDomain protectionDomain , byte [] classfileBuffer )
17+ throws IllegalClassFormatException {
18+ logger .info ("class file transformer invoked for className: {}" , className );
19+ /*
20+
21+ if (className.equals("name/dhruba/user/MyUser")) {
22+
23+ ClassWriter cw = new ClassWriter(0);
24+ MethodVisitor mv;
25+
26+ cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "name/dhruba/user/MyUser", null,
27+ "java/lang/Object", null);
28+
29+ cw.visitSource(null, null);
30+
31+ {
32+ mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
33+ mv.visitCode();
34+ Label l0 = new Label();
35+ mv.visitLabel(l0);
36+ mv.visitLineNumber(3, l0);
37+ mv.visitVarInsn(ALOAD, 0);
38+ mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
39+ mv.visitInsn(RETURN);
40+ Label l1 = new Label();
41+ mv.visitLabel(l1);
42+ mv.visitLocalVariable("this", "Lname/dhruba/user/MyUser;", null, l0, l1, 0);
43+ mv.visitMaxs(1, 1);
44+ mv.visitEnd();
45+ }
46+ {
47+ mv = cw.visitMethod(ACC_PUBLIC, "getName", "()Ljava/lang/String;", null, null);
48+ mv.visitCode();
49+ Label l0 = new Label();
50+ mv.visitLabel(l0);
51+ mv.visitLineNumber(6, l0);
52+ mv.visitLdcInsn("bar");
53+ mv.visitInsn(ARETURN);
54+ Label l1 = new Label();
55+ mv.visitLabel(l1);
56+ mv.visitLocalVariable("this", "Lname/dhruba/user/MyUser;", null, l0, l1, 0);
57+ mv.visitMaxs(1, 1);
58+ mv.visitEnd();
59+ }
60+ cw.visitEnd();
61+
62+ return cw.toByteArray();
63+ }
64+ */
65+
66+ return classfileBuffer ;
67+ }
68+
69+ }
0 commit comments