KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > weblogic > transform > EJBCodeGeneratorAdapter


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.weblogic.transform;
6
7 import com.tc.asm.ClassAdapter;
8 import com.tc.asm.ClassVisitor;
9 import com.tc.asm.Label;
10 import com.tc.asm.MethodAdapter;
11 import com.tc.asm.MethodVisitor;
12 import com.tc.asm.Opcodes;
13 import com.tc.object.bytecode.ByteCodeUtil;
14 import com.tc.object.bytecode.ClassAdapterFactory;
15
16 public class EJBCodeGeneratorAdapter extends ClassAdapter implements ClassAdapterFactory {
17
18   public EJBCodeGeneratorAdapter() {
19     super(null);
20   }
21
22   private EJBCodeGeneratorAdapter(ClassVisitor cv, ClassLoader JavaDoc caller) {
23     super(cv);
24   }
25
26   public ClassAdapter create(ClassVisitor visitor, ClassLoader JavaDoc loader) {
27     return new EJBCodeGeneratorAdapter(visitor, loader);
28   }
29
30   public MethodVisitor visitMethod(int access, String JavaDoc name, String JavaDoc desc, String JavaDoc signature, String JavaDoc[] exceptions) {
31     MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
32     if ("appendInterfaceMethodDeclaration".equals(name)) {
33       mv = new AppendInterfaceMethodDeclarationAdapter(mv);
34     }
35     return mv;
36   }
37
38   private static class AppendInterfaceMethodDeclarationAdapter extends MethodAdapter implements Opcodes {
39
40     public AppendInterfaceMethodDeclarationAdapter(MethodVisitor mv) {
41       super(mv);
42       Label l = new Label();
43       mv.visitVarInsn(ALOAD, 2);
44       mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "getName", "()Ljava/lang/String;");
45       mv.visitLdcInsn(ByteCodeUtil.TC_METHOD_PREFIX);
46       mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "startsWith", "(Ljava/lang/String;)Z");
47       mv.visitJumpInsn(IFEQ, l);
48       mv.visitInsn(RETURN);
49       mv.visitLabel(l);
50     }
51
52   }
53
54 }
55
Popular Tags