1 4 package com.tc.geronimo.transform; 5 6 import com.tc.asm.ClassAdapter; 7 import com.tc.asm.ClassVisitor; 8 import com.tc.asm.MethodAdapter; 9 import com.tc.asm.MethodVisitor; 10 import com.tc.asm.Opcodes; 11 import com.tc.asm.Type; 12 import com.tc.object.bytecode.ClassAdapterFactory; 13 14 public class HostGBeanAdapter extends ClassAdapter implements ClassAdapterFactory { 15 16 public HostGBeanAdapter() { 17 super(null); 18 } 19 20 private HostGBeanAdapter(ClassVisitor cv, ClassLoader caller) { 21 super(cv); 22 } 23 24 public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) { 25 return new HostGBeanAdapter(visitor, loader); 26 } 27 28 public MethodVisitor visitMethod(int access, String name, String desc, String signature, String [] exceptions) { 29 MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 30 31 if ("<init>".equals(name) && Type.getArgumentTypes(desc).length > 0) { 32 mv = new CstrAdapter(mv); 33 } 34 35 return mv; 36 37 } 38 39 private static class CstrAdapter extends MethodAdapter implements Opcodes { 40 41 private boolean done = false; 42 43 public CstrAdapter(MethodVisitor mv) { 44 super(mv); 45 } 46 47 public void visitMethodInsn(int opcode, String owner, String name, String desc) { 48 super.visitMethodInsn(opcode, owner, name, desc); 49 50 if (INVOKESPECIAL == opcode & "<init>".equals(name)) { 51 if (!done) { 52 done = true; 53 mv.visitVarInsn(ALOAD, 0); 54 mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;"); 55 mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getClassLoader", "()Ljava/lang/ClassLoader;"); 56 mv.visitMethodInsn(INVOKESTATIC, "com/tc/object/bytecode/hook/impl/SessionsHelper", "injectClasses", 57 "(Ljava/lang/ClassLoader;)V"); 58 } 59 } 60 61 } 62 63 } 64 65 } 66 | Popular Tags |