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.Label;
09: import com.tc.asm.MethodAdapter;
10: import com.tc.asm.MethodVisitor;
11: import com.tc.asm.Opcodes;
12: import com.tc.object.bytecode.ByteCodeUtil;
13: import com.tc.object.bytecode.ClassAdapterFactory;
14:
15: public class ProxyMethodInterceptorAdapter extends ClassAdapter
16: implements ClassAdapterFactory {
17:
18: public ProxyMethodInterceptorAdapter() {
19: super (null);
20: }
21:
22: private ProxyMethodInterceptorAdapter(ClassVisitor cv,
23: ClassLoader caller) {
24: super (cv);
25: }
26:
27: public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
28: return new ProxyMethodInterceptorAdapter(visitor, loader);
29: }
30:
31: public MethodVisitor visitMethod(int access, String name,
32: String desc, String signature, String[] exceptions) {
33: // public final Object intercept(Object object, Method method, Object args[], MethodProxy proxy)
34:
35: MethodVisitor mv = super .visitMethod(access, name, desc,
36: signature, exceptions);
37:
38: if ("intercept".equals(name)) {
39: return new InterceptAdapter(mv);
40: }
41:
42: return mv;
43:
44: }
45:
46: private static class InterceptAdapter extends MethodAdapter
47: implements Opcodes {
48:
49: public InterceptAdapter(MethodVisitor mv) {
50: super (mv);
51: }
52:
53: public void visitCode() {
54: super .visitCode();
55:
56: // For DSO introduced methods -- no interceptor exists, just call super in this
57: mv.visitVarInsn(ALOAD, 2);
58: mv.visitMethodInsn(INVOKEVIRTUAL,
59: "java/lang/reflect/Method", "getName",
60: "()Ljava/lang/String;");
61: mv.visitLdcInsn(ByteCodeUtil.TC_METHOD_PREFIX);
62: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String",
63: "startsWith", "(Ljava/lang/String;)Z");
64: Label notTC = new Label();
65: mv.visitJumpInsn(IFEQ, notTC);
66: mv.visitVarInsn(ALOAD, 4);
67: mv.visitVarInsn(ALOAD, 1);
68: mv.visitVarInsn(ALOAD, 3);
69: mv
70: .visitMethodInsn(INVOKEVIRTUAL,
71: "net/sf/cglib/proxy/MethodProxy",
72: "invokeSuper",
73: "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;");
74: mv.visitInsn(ARETURN);
75: mv.visitLabel(notTC);
76: }
77:
78: }
79:
80: }
|