001: /*
002: * The Apache Software License, Version 1.1
003: *
004: * Copyright (c) 1999 The Apache Software Foundation. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution, if
020: * any, must include the following acknowlegement:
021: * "This product includes software developed by the
022: * Apache Software Foundation (http://www.apache.org/)."
023: * Alternately, this acknowlegement may appear in the software itself,
024: * if and wherever such third-party acknowlegements normally appear.
025: *
026: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
027: * Foundation" must not be used to endorse or promote products derived
028: * from this software without prior written permission. For written
029: * permission, please contact apache@apache.org.
030: *
031: * 5. Products derived from this software may not be called "Apache"
032: * nor may "Apache" appear in their names without prior written
033: * permission of the Apache Group.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: *
049: * This software consists of voluntary contributions made by many
050: * individuals on behalf of the Apache Software Foundation. For more
051: * information on the Apache Software Foundation, please see
052: * <http://www.apache.org/>.
053: *
054: */
055:
056: package com.sun.portal.providers.jsp.jasper3.jasper.compiler;
057:
058: import java.util.Hashtable;
059: import java.util.Stack;
060:
061: import javax.servlet.jsp.tagext.TagLibraryInfo;
062: import javax.servlet.jsp.tagext.TagInfo;
063: import javax.servlet.jsp.tagext.VariableInfo;
064: import javax.servlet.jsp.tagext.TagData;
065: import javax.servlet.jsp.tagext.Tag;
066: import javax.servlet.jsp.tagext.BodyTag;
067:
068: /**
069: * Custom tag support.
070: *
071: * @author Anil K. Vijendran
072: */
073: public class TagEndGenerator extends TagGeneratorBase implements
074: ServiceMethodPhase {
075: String prefix, shortTagName;
076: TagLibraryInfo tli;
077: TagInfo ti;
078: Hashtable attrs;
079: TagLibraries libraries;
080:
081: public TagEndGenerator(String prefix, String shortTagName,
082: Hashtable attrs, TagLibraryInfo tli, TagInfo ti,
083: TagLibraries libraries, Stack tagHandlerStack,
084: Hashtable tagVarNumbers) {
085: setTagHandlerStack(tagHandlerStack);
086: setTagVarNumbers(tagVarNumbers);
087: this .prefix = prefix;
088: this .shortTagName = shortTagName;
089: this .tli = tli;
090: this .ti = ti;
091: this .attrs = attrs;
092: this .libraries = libraries;
093: }
094:
095: public void generate(ServletWriter writer, Class phase) {
096: TagVariableData tvd = tagEnd();
097: String thVarName = tvd.tagHandlerInstanceName;
098: String evalVarName = tvd.tagEvalVarName;
099:
100: VariableInfo[] vi = ti.getVariableInfo(new TagData(attrs));
101:
102: Class tagHandlerClass = libraries.getTagCache(prefix,
103: shortTagName).getTagHandlerClass();
104: boolean implements BodyTag = BodyTag.class
105: .isAssignableFrom(tagHandlerClass);
106:
107: writer.popIndent();
108:
109: if (implements BodyTag)
110: writer.println("} while (" + thVarName
111: + ".doAfterBody() == BodyTag.EVAL_BODY_TAG);");
112: else
113: writer.println("} while (false);");
114:
115: declareVariables(writer, vi, false, true, VariableInfo.AT_BEGIN);
116:
117: if (implements BodyTag) {
118: writer.popIndent(); // try
119:
120: /** FIXME: REMOVE BEGIN */
121: // writer.println("} catch (Throwable t) {");
122: // writer.pushIndent();
123: // writer.println("System.err.println(\"Caught: \");");
124: // writer.println("t.printStackTrace();");
125: // writer.popIndent();
126: /** FIXME: REMOVE END */
127:
128: writer.println("} finally {");
129: writer.pushIndent();
130: writer.println("if (" + evalVarName
131: + " != Tag.EVAL_BODY_INCLUDE)");
132: writer.pushIndent();
133: writer.println("out = pageContext.popBody();");
134: writer.popIndent();
135:
136: writer.popIndent();
137: writer.println("}");
138: }
139:
140: writer.popIndent(); // EVAL_BODY
141: writer.println("}");
142:
143: writer.println("if (" + thVarName
144: + ".doEndTag() == Tag.SKIP_PAGE)");
145: writer.pushIndent();
146: writer.println("return;");
147: writer.popIndent();
148:
149: writer.popIndent(); // try
150:
151: /** FIXME: REMOVE BEGIN */
152: // writer.println("} catch (Throwable t) {");
153: // writer.pushIndent();
154: // writer.println("System.err.println(\"Caught: \");");
155: // writer.println("t.printStackTrace();");
156: // writer.popIndent();
157: /** FIXME: REMOVE END */
158:
159: // A@ changes for fixing the try/finally problem found in the reliability testing
160: //writer.println("} finally {");
161: writer.pushIndent();
162: writer.println(thVarName + ".release();");
163: writer.popIndent();
164:
165: // A@ changes for fixing the try/finally problem found in the reliability testing
166: //writer.println("}");
167:
168: // Need to declare and update AT_END variables here.
169: declareVariables(writer, vi, true, true, VariableInfo.AT_END);
170: }
171: }
|