01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.jboss.transform;
06:
07: import com.tc.asm.ClassAdapter;
08: import com.tc.asm.ClassVisitor;
09: import com.tc.asm.MethodVisitor;
10: import com.tc.asm.Opcodes;
11: import com.tc.asm.Type;
12: import com.tc.asm.commons.LocalVariablesSorter;
13: import com.tc.object.bytecode.ClassAdapterFactory;
14:
15: public class MainAdapter extends ClassAdapter implements
16: ClassAdapterFactory {
17:
18: public MainAdapter() {
19: super (null);
20: }
21:
22: private MainAdapter(ClassVisitor cv, ClassLoader caller) {
23: super (cv);
24: }
25:
26: public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
27: return new MainAdapter(visitor, loader);
28: }
29:
30: public MethodVisitor visitMethod(int access, String name,
31: String desc, String signature, String[] exceptions) {
32: MethodVisitor mv = super .visitMethod(access, name, desc,
33: signature, exceptions);
34: if (!"boot".equals(name)) {
35: return mv;
36: }
37: return new BootAdapter(access, desc, mv);
38: }
39:
40: private static class BootAdapter extends LocalVariablesSorter
41: implements Opcodes {
42:
43: private int serverSlot;
44: private int configSlot;
45:
46: public BootAdapter(int access, String desc, MethodVisitor mv) {
47: super (access, desc, mv);
48: serverSlot = newLocal(Type
49: .getObjectType("org/jboss/system/server/Server"));
50: configSlot = newLocal(Type
51: .getObjectType("org/jboss/system/server/ServerConfig"));
52: }
53:
54: public void visitMethodInsn(int opcode, String owner,
55: String name, String desc) {
56: super .visitMethodInsn(opcode, owner, name, desc);
57:
58: if ((opcode == INVOKEVIRTUAL)
59: && "org/jboss/system/server/ServerLoader"
60: .equals(owner) && "load".equals(name)) {
61: super .visitInsn(DUP);
62: super .visitVarInsn(ASTORE, serverSlot);
63: } else if ((opcode == INVOKEINTERFACE)
64: && "org/jboss/system/server/Server".equals(owner)
65: && "init".equals(name)) {
66: super .visitVarInsn(ALOAD, serverSlot);
67: super .visitMethodInsn(INVOKEINTERFACE,
68: "org/jboss/system/server/Server", "getConfig",
69: "()Lorg/jboss/system/server/ServerConfig;");
70: super .visitVarInsn(ASTORE, configSlot);
71: super .visitVarInsn(ALOAD, serverSlot);
72: super .visitMethodInsn(INVOKEVIRTUAL,
73: "java/lang/Object", "getClass",
74: "()Ljava/lang/Class;");
75: super .visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class",
76: "getClassLoader", "()Ljava/lang/ClassLoader;");
77: super .visitVarInsn(ALOAD, configSlot);
78: super .visitMethodInsn(INVOKEINTERFACE,
79: "org/jboss/system/server/ServerConfig",
80: "getServerHomeDir", "()Ljava/io/File;");
81: super .visitVarInsn(ALOAD, configSlot);
82: super .visitMethodInsn(INVOKEINTERFACE,
83: "org/jboss/system/server/ServerConfig",
84: "getServerBaseDir", "()Ljava/io/File;");
85: super .visitVarInsn(ALOAD, configSlot);
86: super .visitMethodInsn(INVOKEINTERFACE,
87: "org/jboss/system/server/ServerConfig",
88: "getServerTempDir", "()Ljava/io/File;");
89: super
90: .visitMethodInsn(INVOKESTATIC,
91: "com/tc/jboss/JBossLoaderNaming",
92: "initialize",
93: "(Ljava/lang/ClassLoader;Ljava/io/File;Ljava/io/File;Ljava/io/File;)V");
94: }
95: }
96: }
97: }
|