1 5 package org.terracotta.modules.struts_1_1; 6 7 import com.tc.asm.ClassAdapter; 8 import com.tc.asm.ClassVisitor; 9 import com.tc.asm.Label; 10 import com.tc.asm.MethodVisitor; 11 import com.tc.asm.Opcodes; 12 import com.tc.asm.Type; 13 import com.tc.object.bytecode.ByteCodeUtil; 14 import com.tc.object.bytecode.ClassAdapterFactory; 15 16 22 public class IncludeTagAdapter extends ClassAdapter implements Opcodes, ClassAdapterFactory { 23 24 public IncludeTagAdapter() { 25 super(null); 26 } 27 28 private IncludeTagAdapter(ClassVisitor cv, ClassLoader caller) { 29 super(cv); 30 } 31 32 public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) { 33 return new IncludeTagAdapter(visitor, loader); 34 } 35 36 public MethodVisitor visitMethod(int access, String name, String desc, String signature, String [] exceptions) { 37 if ("doStartTag".equals(name) && Type.getArgumentTypes(desc).length == 0) { 38 return super.visitMethod(ACC_PRIVATE, ByteCodeUtil.METHOD_RENAME_PREFIX + name, desc, signature, exceptions); 40 } 41 42 return super.visitMethod(access, name, desc, signature, exceptions); 43 } 44 45 public void visitEnd() { 46 addSessionLockingSupport(); 47 super.visitEnd(); 48 } 49 50 private void addSessionLockingSupport() { 51 MethodVisitor mv = super.visitMethod(ACC_PUBLIC, "doStartTag", "()I", null, 52 new String [] { "javax/servlet/jsp/JspException" }); 53 mv.visitCode(); 54 mv.visitVarInsn(ALOAD, 0); 55 mv.visitFieldInsn(GETFIELD, "org/apache/struts/taglib/bean/IncludeTag", "pageContext", 56 "Ljavax/servlet/jsp/PageContext;"); 57 mv.visitMethodInsn(INVOKEVIRTUAL, "javax/servlet/jsp/PageContext", "getSession", 58 "()Ljavax/servlet/http/HttpSession;"); 59 mv.visitVarInsn(ASTORE, 1); 60 mv.visitVarInsn(ALOAD, 1); 61 mv.visitTypeInsn(INSTANCEOF, "com/tc/session/SessionSupport"); 62 Label l2 = new Label(); 63 mv.visitJumpInsn(IFEQ, l2); 64 mv.visitVarInsn(ALOAD, 1); 65 mv.visitTypeInsn(CHECKCAST, "com/tc/session/SessionSupport"); 66 mv.visitMethodInsn(INVOKEINTERFACE, "com/tc/session/SessionSupport", "pauseRequest", "()V"); 67 mv.visitLabel(l2); 68 mv.visitVarInsn(ALOAD, 0); 69 mv.visitMethodInsn(INVOKESPECIAL, "org/apache/struts/taglib/bean/IncludeTag", ByteCodeUtil.METHOD_RENAME_PREFIX 70 + "doStartTag", "()I"); 71 mv.visitVarInsn(ISTORE, 4); 72 Label l4 = new Label(); 73 mv.visitJumpInsn(JSR, l4); 74 Label l5 = new Label(); 75 mv.visitLabel(l5); 76 mv.visitVarInsn(ILOAD, 4); 77 mv.visitInsn(IRETURN); 78 Label l6 = new Label(); 79 mv.visitLabel(l6); 80 mv.visitVarInsn(ASTORE, 3); 81 mv.visitJumpInsn(JSR, l4); 82 mv.visitVarInsn(ALOAD, 3); 83 mv.visitInsn(ATHROW); 84 mv.visitLabel(l4); 85 mv.visitVarInsn(ASTORE, 2); 86 mv.visitVarInsn(ALOAD, 1); 87 mv.visitTypeInsn(INSTANCEOF, "com/tc/session/SessionSupport"); 88 Label l9 = new Label(); 89 mv.visitJumpInsn(IFEQ, l9); 90 mv.visitVarInsn(ALOAD, 1); 91 mv.visitTypeInsn(CHECKCAST, "com/tc/session/SessionSupport"); 92 mv.visitMethodInsn(INVOKEINTERFACE, "com/tc/session/SessionSupport", "resumeRequest", "()V"); 93 mv.visitLabel(l9); 94 mv.visitVarInsn(RET, 2); 95 mv.visitTryCatchBlock(l2, l5, l6, null); 96 mv.visitMaxs(0, 0); 97 mv.visitEnd(); 98 } 99 100 } 101 | Popular Tags |