01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.tomcat.transform;
06:
07: import com.tc.asm.ClassAdapter;
08: import com.tc.asm.ClassVisitor;
09: 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.ClassAdapterFactory;
14:
15: public class ContainerBaseAdapter extends ClassAdapter implements
16: Opcodes, ClassAdapterFactory {
17:
18: public ContainerBaseAdapter() {
19: super (null);
20: }
21:
22: private ContainerBaseAdapter(ClassVisitor cv, ClassLoader caller) {
23: super (cv);
24: }
25:
26: public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
27: return new ContainerBaseAdapter(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 ("<init>".equals(name)) {
35: mv = new PipelineAdapter(mv);
36: }
37: return mv;
38: }
39:
40: private static class PipelineAdapter extends MethodAdapter
41: implements Opcodes {
42:
43: public PipelineAdapter(MethodVisitor mv) {
44: super (mv);
45: }
46:
47: public void visitFieldInsn(int opcode, String owner,
48: String name, String desc) {
49: if (PUTFIELD == opcode) {
50: if ("org/apache/catalina/core/ContainerBase"
51: .equals(owner)
52: && "pipeline".equals(name)) {
53:
54: // check if this is an engine (if so, then install the magic TC pipeline)
55: mv.visitVarInsn(ALOAD, 0);
56: mv.visitTypeInsn(INSTANCEOF,
57: "org/apache/catalina/Engine");
58: Label notEngine = new Label();
59: mv.visitJumpInsn(IFEQ, notEngine);
60: mv.visitInsn(POP);
61: mv.visitVarInsn(ALOAD, 0);
62: mv
63: .visitMethodInsn(
64: INVOKESTATIC,
65: "com/tc/tomcat/session/VersionHelper",
66: "createTerracottaPipeline",
67: "(Lorg/apache/catalina/Container;)Lorg/apache/catalina/Pipeline;");
68: mv.visitLabel(notEngine);
69: }
70: }
71:
72: super.visitFieldInsn(opcode, owner, name, desc);
73: }
74:
75: }
76:
77: }
|