001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.weblogic.transform;
006:
007: import com.tc.asm.ClassAdapter;
008: import com.tc.asm.ClassVisitor;
009: import com.tc.asm.Label;
010: import com.tc.asm.MethodVisitor;
011: import com.tc.asm.Opcodes;
012: import com.tc.object.bytecode.ClassAdapterFactory;
013:
014: public class EventsManagerAdapter extends ClassAdapter implements
015: Opcodes, ClassAdapterFactory {
016:
017: public EventsManagerAdapter() {
018: super (null);
019: }
020:
021: private EventsManagerAdapter(ClassVisitor cv, ClassLoader caller) {
022: super (cv);
023: }
024:
025: public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
026: return new EventsManagerAdapter(visitor, loader);
027: }
028:
029: public void visitEnd() {
030: addSesssionAttributeListeners();
031: addSessionListener();
032: super .visitEnd();
033: }
034:
035: // see the dummy EventsManager class in dso-weblogic-stubs for this method post-asm
036: private void addSessionListener() {
037: MethodVisitor mv = cv.visitMethod(ACC_PUBLIC,
038: "__tc_session_getHttpSessionListener",
039: "()[Ljavax/servlet/http/HttpSessionListener;", null,
040: null);
041: mv.visitCode();
042: mv.visitVarInsn(ALOAD, 0);
043: mv.visitFieldInsn(GETFIELD,
044: "weblogic/servlet/internal/EventsManager",
045: "sessListeners", "Ljava/util/List;");
046: Label notNull = new Label();
047: mv.visitJumpInsn(IFNONNULL, notNull);
048: mv.visitInsn(ICONST_0);
049: mv.visitTypeInsn(ANEWARRAY,
050: "javax/servlet/http/HttpSessionListener");
051: mv.visitInsn(ARETURN);
052: mv.visitLabel(notNull);
053: mv.visitVarInsn(ALOAD, 0);
054: mv.visitFieldInsn(GETFIELD,
055: "weblogic/servlet/internal/EventsManager",
056: "sessListeners", "Ljava/util/List;");
057: mv.visitInsn(ICONST_0);
058: mv.visitTypeInsn(ANEWARRAY,
059: "javax/servlet/http/HttpSessionListener");
060: mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List",
061: "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
062: mv.visitTypeInsn(CHECKCAST,
063: "[Ljavax/servlet/http/HttpSessionListener;");
064: mv.visitInsn(ARETURN);
065: mv.visitMaxs(0, 0);
066: mv.visitEnd();
067: }
068:
069: // see the dummy EventsManager class in dso-weblogic-stubs for this method post-asm
070: private void addSesssionAttributeListeners() {
071: MethodVisitor mv = cv.visitMethod(ACC_PUBLIC,
072: "__tc_session_getHttpSessionAttributeListeners",
073: "()[Ljavax/servlet/http/HttpSessionAttributeListener;",
074: null, null);
075: mv.visitCode();
076: mv.visitVarInsn(ALOAD, 0);
077: mv.visitFieldInsn(GETFIELD,
078: "weblogic/servlet/internal/EventsManager",
079: "sessAttrListeners", "Ljava/util/List;");
080: Label notNull = new Label();
081: mv.visitJumpInsn(IFNONNULL, notNull);
082: mv.visitInsn(ICONST_0);
083: mv.visitTypeInsn(ANEWARRAY,
084: "javax/servlet/http/HttpSessionAttributeListener");
085: mv.visitInsn(ARETURN);
086: mv.visitLabel(notNull);
087: mv.visitVarInsn(ALOAD, 0);
088: mv.visitFieldInsn(GETFIELD,
089: "weblogic/servlet/internal/EventsManager",
090: "sessAttrListeners", "Ljava/util/List;");
091: mv.visitInsn(ICONST_0);
092: mv.visitTypeInsn(ANEWARRAY,
093: "javax/servlet/http/HttpSessionAttributeListener");
094: mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List",
095: "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
096: mv.visitTypeInsn(CHECKCAST,
097: "[Ljavax/servlet/http/HttpSessionAttributeListener;");
098: mv.visitInsn(ARETURN);
099: mv.visitMaxs(0, 0);
100: mv.visitEnd();
101: }
102:
103: }
|