KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > core > ApplicationResponse


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.catalina.core;
20
21
22 import java.util.Locale JavaDoc;
23
24 import javax.servlet.ServletResponse JavaDoc;
25 import javax.servlet.ServletResponseWrapper JavaDoc;
26
27 import org.apache.catalina.util.StringManager;
28
29
30 /**
31  * Wrapper around a <code>javax.servlet.ServletResponse</code>
32  * that transforms an application response object (which might be the original
33  * one passed to a servlet, or might be based on the 2.3
34  * <code>javax.servlet.ServletResponseWrapper</code> class)
35  * back into an internal <code>org.apache.catalina.Response</code>.
36  * <p>
37  * <strong>WARNING</strong>: Due to Java's lack of support for multiple
38  * inheritance, all of the logic in <code>ApplicationResponse</code> is
39  * duplicated in <code>ApplicationHttpResponse</code>. Make sure that you
40  * keep these two classes in synchronization when making changes!
41  *
42  * @author Craig R. McClanahan
43  * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
44  */

45
46 class ApplicationResponse extends ServletResponseWrapper JavaDoc {
47
48
49     // ----------------------------------------------------------- Constructors
50

51
52     /**
53      * Construct a new wrapped response around the specified servlet response.
54      *
55      * @param response The servlet response being wrapped
56      */

57     public ApplicationResponse(ServletResponse JavaDoc response) {
58
59         this(response, false);
60
61     }
62
63
64     /**
65      * Construct a new wrapped response around the specified servlet response.
66      *
67      * @param response The servlet response being wrapped
68      * @param included <code>true</code> if this response is being processed
69      * by a <code>RequestDispatcher.include()</code> call
70      */

71     public ApplicationResponse(ServletResponse JavaDoc response, boolean included) {
72
73         super(response);
74         setIncluded(included);
75
76     }
77
78
79     // ----------------------------------------------------- Instance Variables
80

81
82     /**
83      * Is this wrapped response the subject of an <code>include()</code>
84      * call?
85      */

86     protected boolean included = false;
87
88
89     /**
90      * The string manager for this package.
91      */

92     protected static StringManager sm =
93         StringManager.getManager(Constants.Package);
94
95
96     // ------------------------------------------------ ServletResponse Methods
97

98
99     /**
100      * Disallow <code>reset()</code> calls on a included response.
101      *
102      * @exception IllegalStateException if the response has already
103      * been committed
104      */

105     public void reset() {
106
107         // If already committed, the wrapped response will throw ISE
108
if (!included || getResponse().isCommitted())
109             getResponse().reset();
110
111     }
112
113
114     /**
115      * Disallow <code>setContentLength()</code> calls on an included response.
116      *
117      * @param len The new content length
118      */

119     public void setContentLength(int len) {
120
121         if (!included)
122             getResponse().setContentLength(len);
123
124     }
125
126
127     /**
128      * Disallow <code>setContentType()</code> calls on an included response.
129      *
130      * @param type The new content type
131      */

132     public void setContentType(String JavaDoc type) {
133
134         if (!included)
135             getResponse().setContentType(type);
136
137     }
138
139
140     /**
141      * Ignore <code>setLocale()</code> calls on an included response.
142      *
143      * @param loc The new locale
144      */

145     public void setLocale(Locale JavaDoc loc) {
146         if (!included)
147             getResponse().setLocale(loc);
148     }
149
150
151     /**
152      * Ignore <code>setBufferSize()</code> calls on an included response.
153      *
154      * @param size The buffer size
155      */

156     public void setBufferSize(int size) {
157         if (!included)
158             getResponse().setBufferSize(size);
159     }
160
161
162     // ----------------------------------------- ServletResponseWrapper Methods
163

164
165     /**
166      * Set the response that we are wrapping.
167      *
168      * @param response The new wrapped response
169      */

170     public void setResponse(ServletResponse JavaDoc response) {
171
172         super.setResponse(response);
173
174     }
175
176
177     // -------------------------------------------------------- Package Methods
178

179
180     /**
181      * Return the included flag for this response.
182      */

183     boolean isIncluded() {
184
185         return (this.included);
186
187     }
188
189
190     /**
191      * Set the included flag for this response.
192      *
193      * @param included The new included flag
194      */

195     void setIncluded(boolean included) {
196
197         this.included = included;
198
199     }
200
201
202 }
203
Popular Tags