1 5 package com.tc.tomcat.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.ClassAdapterFactory; 14 15 public class ContainerBaseAdapter extends ClassAdapter implements Opcodes, ClassAdapterFactory { 16 17 public ContainerBaseAdapter() { 18 super(null); 19 } 20 21 private ContainerBaseAdapter(ClassVisitor cv, ClassLoader caller) { 22 super(cv); 23 } 24 25 public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) { 26 return new ContainerBaseAdapter(visitor, loader); 27 } 28 29 public MethodVisitor visitMethod(int access, String name, String desc, String signature, String [] exceptions) { 30 MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 31 if ("<init>".equals(name)) { 32 mv = new PipelineAdapter(mv); 33 } 34 return mv; 35 } 36 37 private static class PipelineAdapter extends MethodAdapter implements Opcodes { 38 39 public PipelineAdapter(MethodVisitor mv) { 40 super(mv); 41 } 42 43 public void visitFieldInsn(int opcode, String owner, String name, String desc) { 44 if (PUTFIELD == opcode) { 45 if ("org/apache/catalina/core/ContainerBase".equals(owner) && "pipeline".equals(name)) { 46 47 mv.visitVarInsn(ALOAD, 0); 49 mv.visitTypeInsn(INSTANCEOF, "org/apache/catalina/Engine"); 50 Label notEngine = new Label(); 51 mv.visitJumpInsn(IFEQ, notEngine); 52 mv.visitInsn(POP); 53 mv.visitVarInsn(ALOAD, 0); 54 mv.visitMethodInsn(INVOKESTATIC, "com/tc/tomcat/session/VersionHelper", "createTerracottaPipeline", 55 "(Lorg/apache/catalina/Container;)Lorg/apache/catalina/Pipeline;"); 56 mv.visitLabel(notEngine); 57 } 58 } 59 60 super.visitFieldInsn(opcode, owner, name, desc); 61 } 62 63 } 64 65 } 66 | Popular Tags |