KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > servlet > jsp > JspContext


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 package javax.servlet.jsp;
18
19 import java.util.Enumeration JavaDoc;
20
21 import javax.el.ELContext;
22 import javax.servlet.jsp.el.ExpressionEvaluator JavaDoc;
23 import javax.servlet.jsp.el.VariableResolver JavaDoc;
24
25 /**
26  * <p>
27  * <code>JspContext</code> serves as the base class for the
28  * PageContext class and abstracts all information that is not specific
29  * to servlets. This allows for Simple Tag Extensions to be used
30  * outside of the context of a request/response Servlet.
31  * <p>
32  * The JspContext provides a number of facilities to the
33  * page/component author and page implementor, including:
34  * <ul>
35  * <li>a single API to manage the various scoped namespaces
36  * <li>a mechanism to obtain the JspWriter for output
37  * <li>a mechanism to expose page directive attributes to the
38  * scripting environment
39  * </ul>
40  *
41  * <p><B>Methods Intended for Container Generated Code</B>
42  * <p>
43  * The following methods enable the <B>management of nested</B> JspWriter
44  * streams to implement Tag Extensions: <code>pushBody()</code> and
45  * <code>popBody()</code>
46  *
47  * <p><B>Methods Intended for JSP authors</B>
48  * <p>
49  * Some methods provide <B>uniform access</B> to the diverse objects
50  * representing scopes.
51  * The implementation must use the underlying machinery
52  * corresponding to that scope, so information can be passed back and
53  * forth between the underlying environment (e.g. Servlets) and JSP pages.
54  * The methods are:
55  * <code>setAttribute()</code>, <code>getAttribute()</code>,
56  * <code>findAttribute()</code>, <code>removeAttribute()</code>,
57  * <code>getAttributesScope()</code> and
58  * <code>getAttributeNamesInScope()</code>.
59  *
60  * <p>
61  * The following methods provide <B>convenient access</B> to implicit objects:
62  * <code>getOut()</code>
63  *
64  * <p>
65  * The following methods provide <B>programmatic access</b> to the
66  * Expression Language evaluator:
67  * <code>getExpressionEvaluator()</code>, <code>getVariableResolver()</code>
68  *
69  * @since 2.0
70  */

71
72 public abstract class JspContext {
73
74     /**
75      * Sole constructor. (For invocation by subclass constructors,
76      * typically implicit.)
77      */

78     public JspContext() {
79     }
80     
81     /**
82      * Register the name and value specified with page scope semantics.
83      * If the value passed in is <code>null</code>, this has the same
84      * effect as calling
85      * <code>removeAttribute( name, PageContext.PAGE_SCOPE )</code>.
86      *
87      * @param name the name of the attribute to set
88      * @param value the value to associate with the name, or null if the
89      * attribute is to be removed from the page scope.
90      * @throws NullPointerException if the name is null
91      */

92
93     abstract public void setAttribute(String JavaDoc name, Object JavaDoc value);
94
95     /**
96      * Register the name and value specified with appropriate
97      * scope semantics. If the value passed in is <code>null</code>,
98      * this has the same effect as calling
99      * <code>removeAttribute( name, scope )</code>.
100      *
101      * @param name the name of the attribute to set
102      * @param value the object to associate with the name, or null if
103      * the attribute is to be removed from the specified scope.
104      * @param scope the scope with which to associate the name/object
105      *
106      * @throws NullPointerException if the name is null
107      * @throws IllegalArgumentException if the scope is invalid
108      * @throws IllegalStateException if the scope is
109      * PageContext.SESSION_SCOPE but the page that was requested
110      * does not participate in a session or the session has been
111      * invalidated.
112      */

113
114     abstract public void setAttribute(String JavaDoc name, Object JavaDoc value, int scope);
115
116     /**
117      * Returns the object associated with the name in the page scope or null
118      * if not found.
119      *
120      * @param name the name of the attribute to get
121      * @return the object associated with the name in the page scope
122      * or null if not found.
123      *
124      * @throws NullPointerException if the name is null
125      */

126
127     abstract public Object JavaDoc getAttribute(String JavaDoc name);
128
129     /**
130      * Return the object associated with the name in the specified
131      * scope or null if not found.
132      *
133      * @param name the name of the attribute to set
134      * @param scope the scope with which to associate the name/object
135      * @return the object associated with the name in the specified
136      * scope or null if not found.
137      *
138      * @throws NullPointerException if the name is null
139      * @throws IllegalArgumentException if the scope is invalid
140      * @throws IllegalStateException if the scope is
141      * PageContext.SESSION_SCOPE but the page that was requested
142      * does not participate in a session or the session has been
143      * invalidated.
144      */

145
146     abstract public Object JavaDoc getAttribute(String JavaDoc name, int scope);
147
148     /**
149      * Searches for the named attribute in page, request, session (if valid),
150      * and application scope(s) in order and returns the value associated or
151      * null.
152      *
153      * @param name the name of the attribute to search for
154      * @return the value associated or null
155      * @throws NullPointerException if the name is null
156      */

157
158     abstract public Object JavaDoc findAttribute(String JavaDoc name);
159
160     /**
161      * Remove the object reference associated with the given name
162      * from all scopes. Does nothing if there is no such object.
163      *
164      * @param name The name of the object to remove.
165      * @throws NullPointerException if the name is null
166      */

167
168     abstract public void removeAttribute(String JavaDoc name);
169
170     /**
171      * Remove the object reference associated with the specified name
172      * in the given scope. Does nothing if there is no such object.
173      *
174      * @param name The name of the object to remove.
175      * @param scope The scope where to look.
176      * @throws IllegalArgumentException if the scope is invalid
177      * @throws IllegalStateException if the scope is
178      * PageContext.SESSION_SCOPE but the page that was requested
179      * does not participate in a session or the session has been
180      * invalidated.
181      * @throws NullPointerException if the name is null
182      */

183
184     abstract public void removeAttribute(String JavaDoc name, int scope);
185
186     /**
187      * Get the scope where a given attribute is defined.
188      *
189      * @param name the name of the attribute to return the scope for
190      * @return the scope of the object associated with the name specified or 0
191      * @throws NullPointerException if the name is null
192      */

193
194     abstract public int getAttributesScope(String JavaDoc name);
195
196     /**
197      * Enumerate all the attributes in a given scope.
198      *
199      * @param scope the scope to enumerate all the attributes for
200      * @return an enumeration of names (java.lang.String) of all the
201      * attributes the specified scope
202      * @throws IllegalArgumentException if the scope is invalid
203      * @throws IllegalStateException if the scope is
204      * PageContext.SESSION_SCOPE but the page that was requested
205      * does not participate in a session or the session has been
206      * invalidated.
207      */

208
209     abstract public Enumeration JavaDoc<String JavaDoc> getAttributeNamesInScope(int scope);
210
211     /**
212      * The current value of the out object (a JspWriter).
213      *
214      * @return the current JspWriter stream being used for client response
215      */

216     abstract public JspWriter JavaDoc getOut();
217     
218     /**
219      * Provides programmatic access to the ExpressionEvaluator.
220      * The JSP Container must return a valid instance of an
221      * ExpressionEvaluator that can parse EL expressions.
222      *
223      * @return A valid instance of an ExpressionEvaluator.
224      * @since 2.0
225      */

226     public abstract ExpressionEvaluator JavaDoc getExpressionEvaluator();
227     
228     
229     public abstract ELContext getELContext();
230     
231     /**
232      * Returns an instance of a VariableResolver that provides access to the
233      * implicit objects specified in the JSP specification using this JspContext
234      * as the context object.
235      *
236      * @return A valid instance of a VariableResolver.
237      * @since 2.0
238      */

239     public abstract VariableResolver JavaDoc getVariableResolver();
240     
241     /**
242      * Return a new JspWriter object that sends output to the
243      * provided Writer. Saves the current "out" JspWriter,
244      * and updates the value of the "out" attribute in the
245      * page scope attribute namespace of the JspContext.
246      * <p>The returned JspWriter must implement all methods and
247      * behave as though it were unbuffered. More specifically:
248      * <ul>
249      * <li>clear() must throw an IOException</li>
250      * <li>clearBuffer() does nothing</li>
251      * <li>getBufferSize() always returns 0</li>
252      * <li>getRemaining() always returns 0</li>
253      * </ul>
254      * </p>
255      *
256      * @param writer The Writer for the returned JspWriter to send
257      * output to.
258      * @return a new JspWriter that writes to the given Writer.
259      * @since 2.0
260      */

261     public JspWriter JavaDoc pushBody( java.io.Writer JavaDoc writer ) {
262         return null; // XXX to implement
263
}
264     
265     /**
266      * Return the previous JspWriter "out" saved by the matching
267      * pushBody(), and update the value of the "out" attribute in
268      * the page scope attribute namespace of the JspContext.
269      *
270      * @return the saved JspWriter.
271      */

272     public JspWriter JavaDoc popBody() {
273         return null; // XXX to implement
274
}
275 }
276
Popular Tags