1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * Portions Copyright Apache Software Foundation.
7 *
8 * The contents of this file are subject to the terms of either the GNU
9 * General Public License Version 2 only ("GPL") or the Common Development
10 * and Distribution License("CDDL") (collectively, the "License"). You
11 * may not use this file except in compliance with the License. You can obtain
12 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
13 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
14 * language governing permissions and limitations under the License.
15 *
16 * When distributing the software, include this License Header Notice in each
17 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
18 * Sun designates this particular file as subject to the "Classpath" exception
19 * as provided by Sun in the GPL Version 2 section of the License file that
20 * accompanied this code. If applicable, add the following below the License
21 * Header, with the fields enclosed by brackets [] replaced by your own
22 * identifying information: "Portions Copyrighted [year]
23 * [name of copyright owner]"
24 *
25 * Contributor(s):
26 *
27 * If you wish your version of this file to be governed by only the CDDL or
28 * only the GPL Version 2, indicate your decision by adding "[Contributor]
29 * elects to include this software in this distribution under the [CDDL or GPL
30 * Version 2] license." If you don't indicate a single choice of license, a
31 * recipient has the option to distribute your version of this file under
32 * either the CDDL, the GPL Version 2 or to extend the choice of license to
33 * its licensees as provided above. However, if you add GPL Version 2 code
34 * and therefore, elected the GPL Version 2 license, then the option applies
35 * only if the new code is made subject to such option by the copyright
36 * holder.
37 */
38
39 package javax.servlet.jsp.tagext;
40
41 import javax.servlet.jsp;
42
43
44 /**
45 * The auxiliary interface of a Tag, IterationTag or BodyTag tag
46 * handler that wants additional hooks for managing resources.
47 *
48 * <p>This interface provides two new methods: doCatch(Throwable)
49 * and doFinally(). The prototypical invocation is as follows:
50 *
51 * <pre>
52 * h = get a Tag(); // get a tag handler, perhaps from pool
53 *
54 * h.setPageContext(pc); // initialize as desired
55 * h.setParent(null);
56 * h.setFoo("foo");
57 *
58 * // tag invocation protocol; see Tag.java
59 * try {
60 * doStartTag()...
61 * ....
62 * doEndTag()...
63 * } catch (Throwable t) {
64 * // react to exceptional condition
65 * h.doCatch(t);
66 * } finally {
67 * // restore data invariants and release per-invocation resources
68 * h.doFinally();
69 * }
70 *
71 * ... other invocations perhaps with some new setters
72 * ...
73 * h.release(); // release long-term resources
74 * </pre>
75 */
76
77 public interface TryCatchFinally {
78
79 /**
80 * Invoked if a Throwable occurs while evaluating the BODY
81 * inside a tag or in any of the following methods:
82 * Tag.doStartTag(), Tag.doEndTag(),
83 * IterationTag.doAfterBody() and BodyTag.doInitBody().
84 *
85 * <p>This method is not invoked if the Throwable occurs during
86 * one of the setter methods.
87 *
88 * <p>This method may throw an exception (the same or a new one)
89 * that will be propagated further up the nest chain. If an exception
90 * is thrown, doFinally() will be invoked.
91 *
92 * <p>This method is intended to be used to respond to an exceptional
93 * condition.
94 *
95 * @param t The throwable exception navigating through this tag.
96 * @throws Throwable if the exception is to be rethrown further up
97 * the nest chain.
98 */
99
100 void doCatch(Throwable t) throws Throwable;
101
102 /**
103 * Invoked in all cases after doEndTag() for any class implementing
104 * Tag, IterationTag or BodyTag. This method is invoked even if
105 * an exception has occurred in the BODY of the tag,
106 * or in any of the following methods:
107 * Tag.doStartTag(), Tag.doEndTag(),
108 * IterationTag.doAfterBody() and BodyTag.doInitBody().
109 *
110 * <p>This method is not invoked if the Throwable occurs during
111 * one of the setter methods.
112 *
113 * <p>This method should not throw an Exception.
114 *
115 * <p>This method is intended to maintain per-invocation data
116 * integrity and resource management actions.
117 */
118
119 void doFinally();
120 }