001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Portions Copyright Apache Software Foundation.
007: *
008: * The contents of this file are subject to the terms of either the GNU
009: * General Public License Version 2 only ("GPL") or the Common Development
010: * and Distribution License("CDDL") (collectively, the "License"). You
011: * may not use this file except in compliance with the License. You can obtain
012: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
013: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
014: * language governing permissions and limitations under the License.
015: *
016: * When distributing the software, include this License Header Notice in each
017: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
018: * Sun designates this particular file as subject to the "Classpath" exception
019: * as provided by Sun in the GPL Version 2 section of the License file that
020: * accompanied this code. If applicable, add the following below the License
021: * Header, with the fields enclosed by brackets [] replaced by your own
022: * identifying information: "Portions Copyrighted [year]
023: * [name of copyright owner]"
024: *
025: * Contributor(s):
026: *
027: * If you wish your version of this file to be governed by only the CDDL or
028: * only the GPL Version 2, indicate your decision by adding "[Contributor]
029: * elects to include this software in this distribution under the [CDDL or GPL
030: * Version 2] license." If you don't indicate a single choice of license, a
031: * recipient has the option to distribute your version of this file under
032: * either the CDDL, the GPL Version 2 or to extend the choice of license to
033: * its licensees as provided above. However, if you add GPL Version 2 code
034: * and therefore, elected the GPL Version 2 license, then the option applies
035: * only if the new code is made subject to such option by the copyright
036: * holder.
037: */
038: package javax.servlet.jsp;
039:
040: import java.util.Enumeration;
041:
042: import javax.servlet.jsp.el.ExpressionEvaluator;
043: import javax.servlet.jsp.el.VariableResolver;
044:
045: import javax.el.ELContext;
046:
047: /**
048: * <p>
049: * <code>JspContext</code> serves as the base class for the
050: * PageContext class and abstracts all information that is not specific
051: * to servlets. This allows for Simple Tag Extensions to be used
052: * outside of the context of a request/response Servlet.
053: * <p>
054: * The JspContext provides a number of facilities to the
055: * page/component author and page implementor, including:
056: * <ul>
057: * <li>a single API to manage the various scoped namespaces
058: * <li>a mechanism to obtain the JspWriter for output
059: * <li>a mechanism to expose page directive attributes to the
060: * scripting environment
061: * </ul>
062: *
063: * <p><B>Methods Intended for Container Generated Code</B>
064: * <p>
065: * The following methods enable the <B>management of nested</B> JspWriter
066: * streams to implement Tag Extensions: <code>pushBody()</code> and
067: * <code>popBody()</code>
068: *
069: * <p><B>Methods Intended for JSP authors</B>
070: * <p>
071: * Some methods provide <B>uniform access</B> to the diverse objects
072: * representing scopes.
073: * The implementation must use the underlying machinery
074: * corresponding to that scope, so information can be passed back and
075: * forth between the underlying environment (e.g. Servlets) and JSP pages.
076: * The methods are:
077: * <code>setAttribute()</code>, <code>getAttribute()</code>,
078: * <code>findAttribute()</code>, <code>removeAttribute()</code>,
079: * <code>getAttributesScope()</code> and
080: * <code>getAttributeNamesInScope()</code>.
081: *
082: * <p>
083: * The following methods provide <B>convenient access</B> to implicit objects:
084: * <code>getOut()</code>
085: *
086: * <p>
087: * The following methods provide <B>programmatic access</b> to the
088: * Expression Language evaluator:
089: * <code>getExpressionEvaluator()</code>, <code>getVariableResolver()</code>
090: *
091: * @since JSP 2.0
092: */
093:
094: public abstract class JspContext {
095:
096: /**
097: * Sole constructor. (For invocation by subclass constructors,
098: * typically implicit.)
099: */
100: public JspContext() {
101: }
102:
103: /**
104: * Register the name and value specified with page scope semantics.
105: * If the value passed in is <code>null</code>, this has the same
106: * effect as calling
107: * <code>removeAttribute( name, PageContext.PAGE_SCOPE )</code>.
108: *
109: * @param name the name of the attribute to set
110: * @param value the value to associate with the name, or null if the
111: * attribute is to be removed from the page scope.
112: * @throws NullPointerException if the name is null
113: */
114:
115: abstract public void setAttribute(String name, Object value);
116:
117: /**
118: * Register the name and value specified with appropriate
119: * scope semantics. If the value passed in is <code>null</code>,
120: * this has the same effect as calling
121: * <code>removeAttribute( name, scope )</code>.
122: *
123: * @param name the name of the attribute to set
124: * @param value the object to associate with the name, or null if
125: * the attribute is to be removed from the specified scope.
126: * @param scope the scope with which to associate the name/object
127: *
128: * @throws NullPointerException if the name is null
129: * @throws IllegalArgumentException if the scope is invalid
130: * @throws IllegalStateException if the scope is
131: * PageContext.SESSION_SCOPE but the page that was requested
132: * does not participate in a session or the session has been
133: * invalidated.
134: */
135:
136: abstract public void setAttribute(String name, Object value,
137: int scope);
138:
139: /**
140: * Returns the object associated with the name in the page scope or null
141: * if not found.
142: *
143: * @param name the name of the attribute to get
144: * @return the object associated with the name in the page scope
145: * or null if not found.
146: *
147: * @throws NullPointerException if the name is null
148: */
149:
150: abstract public Object getAttribute(String name);
151:
152: /**
153: * Return the object associated with the name in the specified
154: * scope or null if not found.
155: *
156: * @param name the name of the attribute to set
157: * @param scope the scope with which to associate the name/object
158: * @return the object associated with the name in the specified
159: * scope or null if not found.
160: *
161: * @throws NullPointerException if the name is null
162: * @throws IllegalArgumentException if the scope is invalid
163: * @throws IllegalStateException if the scope is
164: * PageContext.SESSION_SCOPE but the page that was requested
165: * does not participate in a session or the session has been
166: * invalidated.
167: */
168:
169: abstract public Object getAttribute(String name, int scope);
170:
171: /**
172: * Searches for the named attribute in page, request, session (if valid),
173: * and application scope(s) in order and returns the value associated or
174: * null.
175: *
176: * @param name the name of the attribute to search for
177: * @return the value associated or null
178: * @throws NullPointerException if the name is null
179: */
180:
181: abstract public Object findAttribute(String name);
182:
183: /**
184: * Remove the object reference associated with the given name
185: * from all scopes. Does nothing if there is no such object.
186: *
187: * @param name The name of the object to remove.
188: * @throws NullPointerException if the name is null
189: */
190:
191: abstract public void removeAttribute(String name);
192:
193: /**
194: * Remove the object reference associated with the specified name
195: * in the given scope. Does nothing if there is no such object.
196: *
197: * @param name The name of the object to remove.
198: * @param scope The scope where to look.
199: * @throws IllegalArgumentException if the scope is invalid
200: * @throws IllegalStateException if the scope is
201: * PageContext.SESSION_SCOPE but the page that was requested
202: * does not participate in a session or the session has been
203: * invalidated.
204: * @throws NullPointerException if the name is null
205: */
206:
207: abstract public void removeAttribute(String name, int scope);
208:
209: /**
210: * Get the scope where a given attribute is defined.
211: *
212: * @param name the name of the attribute to return the scope for
213: * @return the scope of the object associated with the name specified or 0
214: * @throws NullPointerException if the name is null
215: */
216:
217: abstract public int getAttributesScope(String name);
218:
219: /**
220: * Enumerate all the attributes in a given scope.
221: *
222: * @param scope the scope to enumerate all the attributes for
223: * @return an enumeration of names (java.lang.String) of all the
224: * attributes the specified scope
225: * @throws IllegalArgumentException if the scope is invalid
226: * @throws IllegalStateException if the scope is
227: * PageContext.SESSION_SCOPE but the page that was requested
228: * does not participate in a session or the session has been
229: * invalidated.
230: */
231:
232: abstract public Enumeration<String> getAttributeNamesInScope(
233: int scope);
234:
235: /**
236: * The current value of the out object (a JspWriter).
237: *
238: * @return the current JspWriter stream being used for client response
239: */
240: abstract public JspWriter getOut();
241:
242: /**
243: * Provides programmatic access to the ExpressionEvaluator.
244: * The JSP Container must return a valid instance of an
245: * ExpressionEvaluator that can parse EL expressions.
246: *
247: * @deprecated As of JSP 2.1, replaced by
248: * {@link JspApplicationContext#getExpressionFactory}
249: * @return A valid instance of an ExpressionEvaluator.
250: * @since JSP 2.0
251: */
252: public abstract ExpressionEvaluator getExpressionEvaluator();
253:
254: /**
255: * Returns an instance of a VariableResolver that provides access to the
256: * implicit objects specified in the JSP specification using this JspContext
257: * as the context object.
258: *
259: * @deprecated As of JSP 2.1, replaced by {@link ELContext#getELResolver},
260: * which can be obtained by
261: * <code>jspContext.getELContext().getELResolver()</code>.
262: * @return A valid instance of a VariableResolver.
263: * @since JSP 2.0
264: */
265: public abstract VariableResolver getVariableResolver();
266:
267: /**
268: * Returns the <code>ELContext</code> associated with this
269: * <code>JspContext</code>.
270: *
271: * <p>The <code>ELContext</code> is created lazily and is reused if
272: * it already exists. There is a new <code>ELContext</code> for each
273: * <code>JspContext</code>.</p>
274: *
275: * <p>The <code>ELContext</code> must contain the <code>ELResolver</code>
276: * described in the JSP specification (and in the javadocs for
277: * {@link JspApplicationContext#addELResolver}).</p>
278: *
279: * @return The <code>ELContext</code> associated with this
280: * <code>JspContext</code>.
281: * @since JSP 2.1
282: */
283: public abstract ELContext getELContext();
284:
285: /**
286: * Return a new JspWriter object that sends output to the
287: * provided Writer. Saves the current "out" JspWriter,
288: * and updates the value of the "out" attribute in the
289: * page scope attribute namespace of the JspContext.
290: * <p>The returned JspWriter must implement all methods and
291: * behave as though it were unbuffered. More specifically:
292: * <ul>
293: * <li>clear() must throw an IOException</li>
294: * <li>clearBuffer() does nothing</li>
295: * <li>getBufferSize() always returns 0</li>
296: * <li>getRemaining() always returns 0</li>
297: * </ul>
298: * </p>
299: *
300: * @param writer The Writer for the returned JspWriter to send
301: * output to.
302: * @return a new JspWriter that writes to the given Writer.
303: * @since JSP 2.0
304: */
305: public JspWriter pushBody(java.io.Writer writer) {
306: return null; // XXX to implement
307: }
308:
309: /**
310: * Return the previous JspWriter "out" saved by the matching
311: * pushBody(), and update the value of the "out" attribute in
312: * the page scope attribute namespace of the JspContext.
313: *
314: * @return the saved JspWriter.
315: */
316: public JspWriter popBody() {
317: return null; // XXX to implement
318: }
319: }
|