01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.geronimo.transform;
05:
06: import com.tc.asm.ClassAdapter;
07: import com.tc.asm.ClassVisitor;
08: import com.tc.asm.MethodAdapter;
09: 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
15: ClassAdapterFactory {
16:
17: public HostGBeanAdapter() {
18: super (null);
19: }
20:
21: private HostGBeanAdapter(ClassVisitor cv, ClassLoader caller) {
22: super (cv);
23: }
24:
25: public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
26: return new HostGBeanAdapter(visitor, loader);
27: }
28:
29: public MethodVisitor visitMethod(int access, String name,
30: String desc, String signature, String[] exceptions) {
31: MethodVisitor mv = super .visitMethod(access, name, desc,
32: signature, exceptions);
33:
34: if ("<init>".equals(name)
35: && Type.getArgumentTypes(desc).length > 0) {
36: mv = new CstrAdapter(mv);
37: }
38:
39: return mv;
40:
41: }
42:
43: private static class CstrAdapter extends MethodAdapter implements
44: Opcodes {
45:
46: private boolean done = false;
47:
48: public CstrAdapter(MethodVisitor mv) {
49: super (mv);
50: }
51:
52: public void visitMethodInsn(int opcode, String owner,
53: String name, String desc) {
54: super .visitMethodInsn(opcode, owner, name, desc);
55:
56: if (INVOKESPECIAL == opcode & "<init>".equals(name)) {
57: if (!done) {
58: done = true;
59: mv.visitVarInsn(ALOAD, 0);
60: mv.visitMethodInsn(INVOKEVIRTUAL,
61: "java/lang/Object", "getClass",
62: "()Ljava/lang/Class;");
63: mv.visitMethodInsn(INVOKEVIRTUAL,
64: "java/lang/Class", "getClassLoader",
65: "()Ljava/lang/ClassLoader;");
66: mv
67: .visitMethodInsn(
68: INVOKESTATIC,
69: "com/tc/object/bytecode/hook/impl/SessionsHelper",
70: "injectClasses",
71: "(Ljava/lang/ClassLoader;)V");
72: }
73: }
74:
75: }
76:
77: }
78:
79: }
|