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 org.terracotta.modules.jetty_6_1.adapters;
06:
07: import com.tc.asm.ClassAdapter;
08: import com.tc.asm.ClassVisitor;
09: import com.tc.asm.MethodAdapter;
10: import com.tc.asm.MethodVisitor;
11: import com.tc.asm.Opcodes;
12: import com.tc.object.bytecode.ClassAdapterFactory;
13:
14: public class WebAppClassLoaderAdapter extends ClassAdapter implements
15: ClassAdapterFactory {
16:
17: public WebAppClassLoaderAdapter(ClassVisitor cv) {
18: super (cv);
19: }
20:
21: public WebAppClassLoaderAdapter() {
22: super (null);
23: }
24:
25: public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
26: return new WebAppClassLoaderAdapter(visitor);
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: if ("<init>".equals(name)) {
34: mv = new InitAdapter(mv);
35: }
36:
37: return mv;
38: }
39:
40: private static class InitAdapter extends MethodAdapter implements
41: Opcodes {
42:
43: public InitAdapter(MethodVisitor mv) {
44: super (mv);
45: }
46:
47: public void visitInsn(int opcode) {
48: if (opcode == RETURN) {
49: super .visitVarInsn(ALOAD, 0);
50: super .visitMethodInsn(INVOKESTATIC,
51: "com/tc/jetty/JettyLoaderNaming",
52: "nameAndRegisterWebAppLoader",
53: "(Ljava/lang/ClassLoader;)V");
54: }
55:
56: super.visitInsn(opcode);
57: }
58: }
59:
60: }
|