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 ClassPathAdapter extends ClassAdapter implements
15: ClassAdapterFactory {
16:
17: public ClassPathAdapter(ClassVisitor cv) {
18: super (cv);
19: }
20:
21: public ClassPathAdapter() {
22: super (null);
23: }
24:
25: public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
26: return new ClassPathAdapter(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:
34: if ("getClassLoader".equals(name)
35: & "()Ljava/lang/ClassLoader;".equals(desc)) {
36: mv = new GetClassLoaderAdapter(mv);
37: }
38:
39: return mv;
40: }
41:
42: private static class GetClassLoaderAdapter extends MethodAdapter
43: implements Opcodes {
44:
45: public GetClassLoaderAdapter(MethodVisitor mv) {
46: super (mv);
47: }
48:
49: public void visitInsn(int opcode) {
50: if (opcode == ARETURN) {
51: super .visitInsn(DUP);
52: super .visitMethodInsn(INVOKESTATIC,
53: "com/tc/jetty/JettyLoaderNaming",
54: "nameAndRegisterClasspathLoader",
55: "(Ljava/lang/ClassLoader;)V");
56: }
57:
58: super.visitInsn(opcode);
59: }
60: }
61:
62: }
|