001: /*
002: * Copyright (c) 1998-2003 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.servlet.jsp.tagext;
030:
031: /**
032: * TagExtraInfo classes generate VariableInfo objects to create
033: * runtime variables available to the tags.
034: *
035: * <p/>For example, a NESTED variable could be used like:
036: *
037: * <code><pre>
038: * <mytag:loop name='i' min='0' max='10'>
039: * Iter: <%= i %>
040: * </mytag:loop>
041: * </pre></code>
042: */
043: public class VariableInfo {
044: /**
045: * Constant for nested scope. A nested variable is only alive
046: * inside a tag's body:
047: *
048: * <code><pre>
049: * tag1.doInitBody();
050: * do {
051: * int foo = Integer.intValue(pageContext.getAttribute("foo"));
052: * ...
053: * } while (tag1.doAfterBody() == EVAL_BODY_TAG)
054: * </pre></code>
055: */
056: public static int NESTED = 0;
057: /**
058: * Constant for variables initialized at the beginning of a tag.
059: * These variables are initialized after doStartTag()
060: *
061: * <code><pre>
062: * int _tmp = tag1.doStartTag();
063: * int foo = Integer.intValue(pageContext.getAttribute("foo"));
064: * if (_tmp == EVAL_BODY_INCLUDE) {
065: * ...
066: * }
067: * </pre></code>
068: */
069: public static int AT_BEGIN = 1;
070: /**
071: * Constant for variables initialized at the end of a tag.
072: * These variables are initialized after doEndTag()
073: *
074: * <code><pre>
075: * int _tmp = tag1.doStartTag();
076: * if (_tmp == EVAL_BODY_INCLUDE) {
077: * ...
078: * }
079: * tag1.doEndTag();
080: * int foo = Integer.intValue(pageContext.getAttribute("foo"));
081: * </pre></code>
082: */
083: public static int AT_END = 2;
084:
085: private String varName;
086: private String className;
087: private boolean declare;
088: private int scope;
089:
090: /**
091: * Creates information for a variable. Generally called from a
092: * TagExtraInfo class.
093: *
094: * @param varName name of the variable
095: * @param className the java classname of the variable
096: * @param declare true if the variable should be declared
097: * @param scope the scope of the variable
098: */
099: public VariableInfo(String varName, String className,
100: boolean declare, int scope) {
101: this .varName = varName;
102: this .className = className;
103: this .declare = declare;
104: this .scope = scope;
105: }
106:
107: /**
108: * Returns the variable name.
109: */
110: public String getVarName() {
111: return varName;
112: }
113:
114: /**
115: * Returns the variable's Java class.
116: */
117: public String getClassName() {
118: return className;
119: }
120:
121: /**
122: * True if the variable should be declared. If false, the JSP engine
123: * assumes the variable is already declared and just assigns the value.
124: */
125: public boolean getDeclare() {
126: return declare;
127: }
128:
129: /**
130: * Returns the variable's scope.
131: *
132: * <ul>
133: * <li>AT_BEGIN - available as soon as the tag starts
134: * <li>NESTED - only available in the tag body
135: * <li>AT_END - only available after the tag ends.
136: */
137: public int getScope() {
138: return scope;
139: }
140: }
|