001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package javax.servlet.jsp;
018:
019: import java.util.Enumeration;
020:
021: import javax.el.ELContext;
022: import javax.servlet.jsp.el.ExpressionEvaluator;
023: import javax.servlet.jsp.el.VariableResolver;
024:
025: /**
026: * <p>
027: * <code>JspContext</code> serves as the base class for the
028: * PageContext class and abstracts all information that is not specific
029: * to servlets. This allows for Simple Tag Extensions to be used
030: * outside of the context of a request/response Servlet.
031: * <p>
032: * The JspContext provides a number of facilities to the
033: * page/component author and page implementor, including:
034: * <ul>
035: * <li>a single API to manage the various scoped namespaces
036: * <li>a mechanism to obtain the JspWriter for output
037: * <li>a mechanism to expose page directive attributes to the
038: * scripting environment
039: * </ul>
040: *
041: * <p><B>Methods Intended for Container Generated Code</B>
042: * <p>
043: * The following methods enable the <B>management of nested</B> JspWriter
044: * streams to implement Tag Extensions: <code>pushBody()</code> and
045: * <code>popBody()</code>
046: *
047: * <p><B>Methods Intended for JSP authors</B>
048: * <p>
049: * Some methods provide <B>uniform access</B> to the diverse objects
050: * representing scopes.
051: * The implementation must use the underlying machinery
052: * corresponding to that scope, so information can be passed back and
053: * forth between the underlying environment (e.g. Servlets) and JSP pages.
054: * The methods are:
055: * <code>setAttribute()</code>, <code>getAttribute()</code>,
056: * <code>findAttribute()</code>, <code>removeAttribute()</code>,
057: * <code>getAttributesScope()</code> and
058: * <code>getAttributeNamesInScope()</code>.
059: *
060: * <p>
061: * The following methods provide <B>convenient access</B> to implicit objects:
062: * <code>getOut()</code>
063: *
064: * <p>
065: * The following methods provide <B>programmatic access</b> to the
066: * Expression Language evaluator:
067: * <code>getExpressionEvaluator()</code>, <code>getVariableResolver()</code>
068: *
069: * @since 2.0
070: */
071:
072: public abstract class JspContext {
073:
074: /**
075: * Sole constructor. (For invocation by subclass constructors,
076: * typically implicit.)
077: */
078: public JspContext() {
079: }
080:
081: /**
082: * Register the name and value specified with page scope semantics.
083: * If the value passed in is <code>null</code>, this has the same
084: * effect as calling
085: * <code>removeAttribute( name, PageContext.PAGE_SCOPE )</code>.
086: *
087: * @param name the name of the attribute to set
088: * @param value the value to associate with the name, or null if the
089: * attribute is to be removed from the page scope.
090: * @throws NullPointerException if the name is null
091: */
092:
093: abstract public void setAttribute(String name, Object value);
094:
095: /**
096: * Register the name and value specified with appropriate
097: * scope semantics. If the value passed in is <code>null</code>,
098: * this has the same effect as calling
099: * <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 name, Object value,
115: int scope);
116:
117: /**
118: * Returns the object associated with the name in the page scope or null
119: * if not found.
120: *
121: * @param name the name of the attribute to get
122: * @return the object associated with the name in the page scope
123: * or null if not found.
124: *
125: * @throws NullPointerException if the name is null
126: */
127:
128: abstract public Object getAttribute(String name);
129:
130: /**
131: * Return the object associated with the name in the specified
132: * scope or null if not found.
133: *
134: * @param name the name of the attribute to set
135: * @param scope the scope with which to associate the name/object
136: * @return the object associated with the name in the specified
137: * scope or null if not found.
138: *
139: * @throws NullPointerException if the name is null
140: * @throws IllegalArgumentException if the scope is invalid
141: * @throws IllegalStateException if the scope is
142: * PageContext.SESSION_SCOPE but the page that was requested
143: * does not participate in a session or the session has been
144: * invalidated.
145: */
146:
147: abstract public Object getAttribute(String name, int scope);
148:
149: /**
150: * Searches for the named attribute in page, request, session (if valid),
151: * and application scope(s) in order and returns the value associated or
152: * null.
153: *
154: * @param name the name of the attribute to search for
155: * @return the value associated or null
156: * @throws NullPointerException if the name is null
157: */
158:
159: abstract public Object findAttribute(String name);
160:
161: /**
162: * Remove the object reference associated with the given name
163: * from all scopes. Does nothing if there is no such object.
164: *
165: * @param name The name of the object to remove.
166: * @throws NullPointerException if the name is null
167: */
168:
169: abstract public void removeAttribute(String name);
170:
171: /**
172: * Remove the object reference associated with the specified name
173: * in the given scope. Does nothing if there is no such object.
174: *
175: * @param name The name of the object to remove.
176: * @param scope The scope where to look.
177: * @throws IllegalArgumentException if the scope is invalid
178: * @throws IllegalStateException if the scope is
179: * PageContext.SESSION_SCOPE but the page that was requested
180: * does not participate in a session or the session has been
181: * invalidated.
182: * @throws NullPointerException if the name is null
183: */
184:
185: abstract public void removeAttribute(String name, int scope);
186:
187: /**
188: * Get the scope where a given attribute is defined.
189: *
190: * @param name the name of the attribute to return the scope for
191: * @return the scope of the object associated with the name specified or 0
192: * @throws NullPointerException if the name is null
193: */
194:
195: abstract public int getAttributesScope(String name);
196:
197: /**
198: * Enumerate all the attributes in a given scope.
199: *
200: * @param scope the scope to enumerate all the attributes for
201: * @return an enumeration of names (java.lang.String) of all the
202: * attributes the specified scope
203: * @throws IllegalArgumentException if the scope is invalid
204: * @throws IllegalStateException if the scope is
205: * PageContext.SESSION_SCOPE but the page that was requested
206: * does not participate in a session or the session has been
207: * invalidated.
208: */
209:
210: abstract public Enumeration<String> getAttributeNamesInScope(
211: int scope);
212:
213: /**
214: * The current value of the out object (a JspWriter).
215: *
216: * @return the current JspWriter stream being used for client response
217: */
218: abstract public JspWriter getOut();
219:
220: /**
221: * Provides programmatic access to the ExpressionEvaluator.
222: * The JSP Container must return a valid instance of an
223: * ExpressionEvaluator that can parse EL expressions.
224: *
225: * @return A valid instance of an ExpressionEvaluator.
226: * @since 2.0
227: */
228: public abstract ExpressionEvaluator getExpressionEvaluator();
229:
230: public abstract ELContext getELContext();
231:
232: /**
233: * Returns an instance of a VariableResolver that provides access to the
234: * implicit objects specified in the JSP specification using this JspContext
235: * as the context object.
236: *
237: * @return A valid instance of a VariableResolver.
238: * @since 2.0
239: */
240: public abstract VariableResolver getVariableResolver();
241:
242: /**
243: * Return a new JspWriter object that sends output to the
244: * provided Writer. Saves the current "out" JspWriter,
245: * and updates the value of the "out" attribute in the
246: * page scope attribute namespace of the JspContext.
247: * <p>The returned JspWriter must implement all methods and
248: * behave as though it were unbuffered. More specifically:
249: * <ul>
250: * <li>clear() must throw an IOException</li>
251: * <li>clearBuffer() does nothing</li>
252: * <li>getBufferSize() always returns 0</li>
253: * <li>getRemaining() always returns 0</li>
254: * </ul>
255: * </p>
256: *
257: * @param writer The Writer for the returned JspWriter to send
258: * output to.
259: * @return a new JspWriter that writes to the given Writer.
260: * @since 2.0
261: */
262: public JspWriter pushBody(java.io.Writer writer) {
263: return null; // XXX to implement
264: }
265:
266: /**
267: * Return the previous JspWriter "out" saved by the matching
268: * pushBody(), and update the value of the "out" attribute in
269: * the page scope attribute namespace of the JspContext.
270: *
271: * @return the saved JspWriter.
272: */
273: public JspWriter popBody() {
274: return null; // XXX to implement
275: }
276: }
|