KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > weblogic > transform > WebAppServletContextAdapter


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.weblogic.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.MethodVisitor;
11 import com.tc.asm.Opcodes;
12 import com.tc.object.bytecode.ByteCodeUtil;
13 import com.tc.object.bytecode.ClassAdapterFactory;
14
15 public class WebAppServletContextAdapter extends ClassAdapter implements Opcodes, ClassAdapterFactory {
16
17   public WebAppServletContextAdapter() {
18     super(null);
19   }
20
21   private WebAppServletContextAdapter(ClassVisitor cv, ClassLoader JavaDoc caller) {
22     super(cv);
23   }
24
25   public ClassAdapter create(ClassVisitor visitor, ClassLoader JavaDoc loader) {
26     return new WebAppServletContextAdapter(visitor, loader);
27   }
28
29   public void visit(int version, int access, String JavaDoc name, String JavaDoc signature, String JavaDoc superName, String JavaDoc[] interfaces) {
30     interfaces = ByteCodeUtil.addInterfaces(interfaces, new String JavaDoc[] { "com/terracotta/session/WebAppConfig" });
31     super.visit(version, access, name, signature, superName, interfaces);
32   }
33
34   public void visitEnd() {
35     addSesssionAttributeListeners();
36     addSessionListener();
37     addSessionCookieComment();
38     addSessionCookieDomain();
39     addSessionCookieMaxAge();
40     addSessionCookieName();
41     addSessionCookiePath();
42     addSessionCookieSecure();
43     addSessionCookieEnabled();
44     addSessionIdLength();
45     addSessionTimeoutSeconds();
46     addServerId();
47     addSessionTrackingEnabled();
48     addSessionUrlRewritingEnabled();
49     super.visitEnd();
50   }
51
52   private void addSessionListener() {
53     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getHttpSessionListener",
54                                       "()[Ljavax/servlet/http/HttpSessionListener;", null, null);
55     mv.visitCode();
56     mv.visitVarInsn(ALOAD, 0);
57     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessListeners", "Ljava/util/List;");
58     Label notNull = new Label();
59     mv.visitJumpInsn(IFNONNULL, notNull);
60     mv.visitInsn(ICONST_0);
61     mv.visitTypeInsn(ANEWARRAY, "javax/servlet/http/HttpSessionListener");
62     mv.visitInsn(ARETURN);
63     mv.visitLabel(notNull);
64     mv.visitVarInsn(ALOAD, 0);
65     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessListeners", "Ljava/util/List;");
66     mv.visitInsn(ICONST_0);
67     mv.visitTypeInsn(ANEWARRAY, "javax/servlet/http/HttpSessionListener");
68     mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
69     mv.visitTypeInsn(CHECKCAST, "[Ljavax/servlet/http/HttpSessionListener;");
70     mv.visitInsn(ARETURN);
71     mv.visitMaxs(0, 0);
72     mv.visitEnd();
73   }
74
75   private void addSesssionAttributeListeners() {
76     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getHttpSessionAttributeListeners",
77                                       "()[Ljavax/servlet/http/HttpSessionAttributeListener;", null, null);
78     mv.visitCode();
79     mv.visitVarInsn(ALOAD, 0);
80     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessAttrListeners",
81                       "Ljava/util/List;");
82     Label notNull = new Label();
83     mv.visitJumpInsn(IFNONNULL, notNull);
84     mv.visitInsn(ICONST_0);
85     mv.visitTypeInsn(ANEWARRAY, "javax/servlet/http/HttpSessionAttributeListener");
86     mv.visitInsn(ARETURN);
87     mv.visitLabel(notNull);
88     mv.visitVarInsn(ALOAD, 0);
89     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessAttrListeners",
90                       "Ljava/util/List;");
91     mv.visitInsn(ICONST_0);
92     mv.visitTypeInsn(ANEWARRAY, "javax/servlet/http/HttpSessionAttributeListener");
93     mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
94     mv.visitTypeInsn(CHECKCAST, "[Ljavax/servlet/http/HttpSessionAttributeListener;");
95     mv.visitInsn(ARETURN);
96     mv.visitMaxs(0, 0);
97     mv.visitEnd();
98   }
99
100   private void addSessionCookieComment() {
101     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getCookieComment", "()Ljava/lang/String;", null, null);
102     mv.visitCode();
103     mv.visitVarInsn(ALOAD, 0);
104     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessionCookieComment",
105                       "Ljava/lang/String;");
106     mv.visitInsn(ARETURN);
107     mv.visitMaxs(0, 0);
108     mv.visitEnd();
109   }
110
111   private void addSessionCookieDomain() {
112     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getCookieDomain", "()Ljava/lang/String;", null, null);
113     mv.visitCode();
114     mv.visitVarInsn(ALOAD, 0);
115     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessionCookieDomain",
116                       "Ljava/lang/String;");
117     mv.visitInsn(ARETURN);
118     mv.visitMaxs(0, 0);
119     mv.visitEnd();
120   }
121
122   private void addSessionCookieMaxAge() {
123     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getCookieMaxAgeSecs", "()I", null, null);
124     mv.visitCode();
125     mv.visitVarInsn(ALOAD, 0);
126     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessionCookieMaxAgeSecs", "I");
127     mv.visitInsn(IRETURN);
128     mv.visitMaxs(0, 0);
129     mv.visitEnd();
130   }
131
132   private void addSessionCookieName() {
133     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getCookieName", "()Ljava/lang/String;", null, null);
134     mv.visitCode();
135     mv.visitVarInsn(ALOAD, 0);
136     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessionCookieName",
137                       "Ljava/lang/String;");
138     mv.visitInsn(ARETURN);
139     mv.visitMaxs(0, 0);
140     mv.visitEnd();
141   }
142
143   private void addSessionCookiePath() {
144     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getCookiePath", "()Ljava/lang/String;", null, null);
145     mv.visitCode();
146     mv.visitVarInsn(ALOAD, 0);
147     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessionCookiePath",
148                       "Ljava/lang/String;");
149     mv.visitInsn(ARETURN);
150     mv.visitMaxs(0, 0);
151     mv.visitEnd();
152   }
153
154   private void addSessionCookieSecure() {
155     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getCookieSecure", "()Z", null, null);
156     mv.visitCode();
157     mv.visitVarInsn(ALOAD, 0);
158     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessionCookieSecure", "Z");
159     mv.visitInsn(IRETURN);
160     mv.visitMaxs(0, 0);
161     mv.visitEnd();
162   }
163
164   private void addSessionCookieEnabled() {
165     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getCookiesEnabled", "()Z", null, null);
166     mv.visitCode();
167     mv.visitVarInsn(ALOAD, 0);
168     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessionCookiesEnabled", "Z");
169     mv.visitInsn(IRETURN);
170     mv.visitMaxs(0, 0);
171     mv.visitEnd();
172   }
173
174   private void addSessionIdLength() {
175     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getIdLength", "()I", null, null);
176     mv.visitCode();
177     mv.visitVarInsn(ALOAD, 0);
178     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessionIDLength", "I");
179     mv.visitInsn(IRETURN);
180     mv.visitMaxs(0, 0);
181     mv.visitEnd();
182   }
183
184   private void addServerId() {
185     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getServerId", "()Ljava/lang/String;", null, null);
186     mv.visitCode();
187     mv.visitVarInsn(ALOAD, 0);
188     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "httpServer",
189                       "Lweblogic/servlet/internal/HttpServer;");
190     mv.visitMethodInsn(INVOKEVIRTUAL, "weblogic/servlet/internal/HttpServer", "getServerHash", "()Ljava/lang/String;");
191     mv.visitInsn(ARETURN);
192     mv.visitMaxs(0, 0);
193     mv.visitEnd();
194   }
195
196   private void addSessionTimeoutSeconds() {
197
198     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getSessionTimeoutSecs", "()I", null, null);
199     mv.visitCode();
200     mv.visitVarInsn(ALOAD, 0);
201     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessionTimeoutSecs", "I");
202     mv.visitInsn(IRETURN);
203     mv.visitMaxs(0, 0);
204     mv.visitEnd();
205   }
206
207   private void addSessionTrackingEnabled() {
208     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getTrackingEnabled", "()Z", null, null);
209     mv.visitCode();
210     mv.visitVarInsn(ALOAD, 0);
211     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessionTrackingEnabled", "Z");
212     mv.visitInsn(IRETURN);
213     mv.visitMaxs(0, 0);
214     mv.visitEnd();
215   }
216
217   private void addSessionUrlRewritingEnabled() {
218     MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "__tc_session_getURLRewritingEnabled", "()Z", null, null);
219     mv.visitCode();
220     mv.visitVarInsn(ALOAD, 0);
221     mv.visitFieldInsn(GETFIELD, "weblogic/servlet/internal/WebAppServletContext", "sessionURLRewritingEnabled", "Z");
222     mv.visitInsn(IRETURN);
223     mv.visitMaxs(0, 0);
224     mv.visitEnd();
225   }
226 }
227
Popular Tags