KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > weblogic > servlet > internal > TerracottaServletResponseImpl


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

4 package weblogic.servlet.internal;
5
6 import com.terracotta.session.TerracottaRequest;
7 import com.terracotta.session.TerracottaResponse;
8
9 import java.io.IOException JavaDoc;
10 import java.io.PrintWriter JavaDoc;
11 import java.lang.reflect.Method JavaDoc;
12 import java.lang.reflect.Modifier JavaDoc;
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Locale JavaDoc;
18 import java.util.Set JavaDoc;
19
20 import javax.servlet.ServletOutputStream JavaDoc;
21 import javax.servlet.http.Cookie JavaDoc;
22
23 /**
24  * The whole point of this class is to remain type compatible with weblogic's internal response types. There are places
25  * in their container where the concrete type of the resposne needs to be instanceof compatible with their type. This
26  * class also must reside in the weblogic package such that it can override and delegate package private methods. This
27  * class is instrumented at runtime to override all non-private methods of ServletResponseImpl and delegate the
28  * nativeResponse instance
29  */

30 public final class TerracottaServletResponseImpl extends ServletResponseImpl implements TerracottaResponse {
31   private final TerracottaRequest req;
32   private final ServletResponseImpl nativeResponse;
33
34   public TerracottaServletResponseImpl(TerracottaRequest req, ServletResponseImpl response) {
35     this.req = req;
36     this.nativeResponse = response;
37   }
38
39   public String JavaDoc encodeRedirectUrl(String JavaDoc url) {
40     return encodeRedirectURL(url);
41   }
42
43   public String JavaDoc encodeUrl(String JavaDoc url) {
44     return encodeURL(url);
45   }
46
47   public String JavaDoc encodeRedirectURL(final String JavaDoc url) {
48     return req.encodeRedirectURL(url);
49   }
50
51   public String JavaDoc encodeURL(final String JavaDoc url) {
52     return req.encodeURL(url);
53   }
54
55   public void addCookie(Cookie JavaDoc arg0) {
56     nativeResponse.addCookie(arg0);
57   }
58
59   public void addDateHeader(String JavaDoc arg0, long arg1) {
60     nativeResponse.addDateHeader(arg0, arg1);
61   }
62
63   public void addHeader(String JavaDoc arg0, String JavaDoc arg1) {
64     nativeResponse.addHeader(arg0, arg1);
65   }
66
67   public void addIntHeader(String JavaDoc arg0, int arg1) {
68     nativeResponse.addIntHeader(arg0, arg1);
69   }
70
71   public boolean containsHeader(String JavaDoc arg0) {
72     return nativeResponse.containsHeader(arg0);
73   }
74
75   public void flushBuffer() throws IOException JavaDoc {
76     nativeResponse.flushBuffer();
77   }
78
79   public int getBufferSize() {
80     return nativeResponse.getBufferSize();
81   }
82
83   public String JavaDoc getCharacterEncoding() {
84     return nativeResponse.getCharacterEncoding();
85   }
86
87   public String JavaDoc getContentType() {
88     return nativeResponse.getContentType();
89   }
90
91   public Locale JavaDoc getLocale() {
92     return nativeResponse.getLocale();
93   }
94
95   public ServletOutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
96     return nativeResponse.getOutputStream();
97   }
98
99   public PrintWriter JavaDoc getWriter() throws IOException JavaDoc {
100     return nativeResponse.getWriter();
101   }
102
103   public boolean isCommitted() {
104     return nativeResponse.isCommitted();
105   }
106
107   public void reset() {
108     nativeResponse.reset();
109   }
110
111   public void resetBuffer() {
112     nativeResponse.resetBuffer();
113   }
114
115   public void sendError(int arg0, String JavaDoc arg1) throws IOException JavaDoc {
116     nativeResponse.sendError(arg0, arg1);
117   }
118
119   public void sendError(int arg0) throws IOException JavaDoc {
120     nativeResponse.sendError(arg0);
121   }
122
123   public void sendRedirect(String JavaDoc arg0) throws IOException JavaDoc {
124     nativeResponse.sendRedirect(arg0);
125   }
126
127   public void setBufferSize(int arg0) {
128     nativeResponse.setBufferSize(arg0);
129   }
130
131   public void setCharacterEncoding(String JavaDoc arg0) {
132     nativeResponse.setCharacterEncoding(arg0);
133   }
134
135   public void setContentLength(int arg0) {
136     nativeResponse.setContentLength(arg0);
137   }
138
139   public void setContentType(String JavaDoc arg0) {
140     nativeResponse.setContentType(arg0);
141   }
142
143   public void setDateHeader(String JavaDoc arg0, long arg1) {
144     nativeResponse.setDateHeader(arg0, arg1);
145   }
146
147   public void setHeader(String JavaDoc arg0, String JavaDoc arg1) {
148     nativeResponse.setHeader(arg0, arg1);
149   }
150
151   public void setIntHeader(String JavaDoc arg0, int arg1) {
152     nativeResponse.setIntHeader(arg0, arg1);
153   }
154
155   public void setLocale(Locale JavaDoc arg0) {
156     nativeResponse.setLocale(arg0);
157   }
158
159   public void setStatus(int arg0, String JavaDoc arg1) {
160     nativeResponse.setStatus(arg0, arg1);
161   }
162
163   public void setStatus(int arg0) {
164     nativeResponse.setStatus(arg0);
165   }
166
167   static {
168     Set JavaDoc superMethods = methodsFor(ServletResponseImpl.class);
169     Set JavaDoc thisMethods = methodsFor(TerracottaServletResponseImpl.class);
170
171     List JavaDoc missing = new ArrayList JavaDoc();
172
173     for (Iterator JavaDoc i = superMethods.iterator(); i.hasNext();) {
174       String JavaDoc method = (String JavaDoc) i.next();
175
176       if (!thisMethods.contains(method)) {
177         // This class should be overriding all methods on the super class
178
missing.add(method);
179       }
180     }
181
182     if (!missing.isEmpty()) { throw new RuntimeException JavaDoc("Missing overrides:\n" + missing); }
183   }
184
185   private static Set JavaDoc methodsFor(Class JavaDoc c) {
186     Method JavaDoc[] methods = c.getDeclaredMethods();
187
188     Set JavaDoc set = new HashSet JavaDoc();
189     for (int i = 0; i < methods.length; i++) {
190       Method JavaDoc m = methods[i];
191
192       int access = m.getModifiers();
193
194       if (Modifier.isAbstract(access) || Modifier.isStatic(access) || Modifier.isPrivate(access)) {
195         continue;
196       }
197
198       StringBuffer JavaDoc sig = new StringBuffer JavaDoc();
199       sig.append(m.getName()).append('(');
200
201       Class JavaDoc[] parameterTypes = m.getParameterTypes();
202       for (int j = 0; j < parameterTypes.length; j++) {
203         sig.append(parameterTypes[j].getName());
204         if (j < (parameterTypes.length - 1)) {
205           sig.append(',');
206         }
207       }
208       sig.append(')');
209
210       set.add(sig.toString());
211     }
212     return set;
213   }
214
215 }
216
Popular Tags