KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > servlet > jsp > tagext > JspFragment


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 package javax.servlet.jsp.tagext;
19
20 import java.io.IOException JavaDoc;
21 import java.io.Writer JavaDoc;
22 import javax.servlet.jsp.*;
23
24 /**
25  * Encapsulates a portion of JSP code in an object that
26  * can be invoked as many times as needed. JSP Fragments are defined
27  * using JSP syntax as the body of a tag for an invocation to a SimpleTag
28  * handler, or as the body of a <jsp:attribute> standard action
29  * specifying the value of an attribute that is declared as a fragment,
30  * or to be of type JspFragment in the TLD.
31  * <p>
32  * The definition of the JSP fragment must only contain template
33  * text and JSP action elements. In other words, it must not contain
34  * scriptlets or scriptlet expressions. At translation time, the
35  * container generates an implementation of the JspFragment abstract class
36  * capable of executing the defined fragment.
37  * <p>
38  * A tag handler can invoke the fragment zero or more times, or
39  * pass it along to other tags, before returning. To communicate values
40  * to/from a JSP fragment, tag handlers store/retrieve values in
41  * the JspContext associated with the fragment.
42  * <p>
43  * Note that tag library developers and page authors should not generate
44  * JspFragment implementations manually.
45  * <p>
46  * <i>Implementation Note</i>: It is not necessary to generate a
47  * separate class for each fragment. One possible implementation is
48  * to generate a single helper class for each page that implements
49  * JspFragment. Upon construction, a discriminator can be passed to
50  * select which fragment that instance will execute.
51  *
52  * @since 2.0
53  */

54 public abstract class JspFragment {
55
56     /**
57      * Executes the fragment and directs all output to the given Writer,
58      * or the JspWriter returned by the getOut() method of the JspContext
59      * associated with the fragment if out is null.
60      *
61      * @param out The Writer to output the fragment to, or null if
62      * output should be sent to JspContext.getOut().
63      * @throws javax.servlet.jsp.JspException Thrown if an error occured
64      * while invoking this fragment.
65      * @throws javax.servlet.jsp.SkipPageException Thrown if the page
66      * that (either directly or indirectly) invoked the tag handler that
67      * invoked this fragment is to cease evaluation. The container
68      * must throw this exception if a Classic Tag Handler returned
69      * Tag.SKIP_PAGE or if a Simple Tag Handler threw SkipPageException.
70      * @throws java.io.IOException If there was an error writing to the
71      * stream.
72      */

73     public abstract void invoke( Writer JavaDoc out )
74         throws JspException, IOException JavaDoc;
75
76     /**
77      * Returns the JspContext that is bound to this JspFragment.
78      *
79      * @return The JspContext used by this fragment at invocation time.
80      */

81     public abstract JspContext getJspContext();
82
83 }
84
Popular Tags