1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. *
  54. */
  55. package javax.servlet.jsp.tagext;
  56. /**
  57. * Information on the scripting variables that are created/modified by
  58. * a tag (at run-time). This information is provided by TagExtraInfo
  59. * classes and it is used by the translation phase of JSP.
  60. *
  61. * <p>
  62. * Scripting variables generated by a custom action may have scope values
  63. * of page, request, session, and application.
  64. *
  65. * <p>
  66. * The class name (VariableInfo.getClassName) in the returned objects
  67. * are used to determine the types of the scripting variables.
  68. * Because of this, a custom action cannot create a scripting variable
  69. * of a primitive type. The workaround is to use "boxed"
  70. * types.
  71. *
  72. * <p>
  73. * The class name may be a Fully Qualified Class Name, or a short
  74. * class name.
  75. *
  76. * <p>
  77. * If a Fully Qualified Class Name is provided, it should refer to a
  78. * class that should be in the CLASSPATH for the Web Application (see
  79. * Servlet 2.3 specification - essentially it is WEB-INF/lib and
  80. * WEB-INF/classes). Failure to be so will lead to a translation-time
  81. * error.
  82. *
  83. * <p>
  84. * If a short class name is given in the VariableInfo objects, then
  85. * the class name must be that of a public class in the context of the
  86. * import directives of the page where the custom action appears (will
  87. * check if there is a JLS verbiage to refer to). The class must also
  88. * be in the CLASSPATH for the Web Application (see Servlet 2.3
  89. * specification - essentially it is WEB-INF/lib and
  90. * WEB-INF/classes). Failure to be so will lead to a translation-time
  91. * error.
  92. *
  93. * <p><B>Usage Comments</B>
  94. * <p>
  95. * Frequently a fully qualified class name will refer to a class that
  96. * is known to the tag library and thus, delivered in the same JAR
  97. * file as the tag handlers. In most other remaining cases it will
  98. * refer to a class that is in the platform on which the JSP processor
  99. * is built (like J2EE). Using fully qualified class names in this
  100. * manner makes the usage relatively resistant to configuration
  101. * errors.
  102. *
  103. * <p>
  104. * A short name is usually generated by the tag library based on some
  105. * attributes passed through from the custom action user (the author),
  106. * and it is thus less robust: for instance a missing import directive
  107. * in the referring JSP page will lead to an invalid short name class
  108. * and a translation error.
  109. *
  110. * <p><B>Synchronization Protocol</B>
  111. *
  112. * <p>
  113. * The result of the invocation on getVariableInfo is an array of
  114. * VariableInfo objects. Each such object describes a scripting
  115. * variable by providing its name, its type, whether the variable is
  116. * new or not, and what its scope is. Scope is best described through
  117. * a picture:
  118. *
  119. * <p>
  120. * <IMG src="doc-files/VariableInfo-1.gif"/>
  121. *
  122. *<p>
  123. * The JSP 1.2 specification defines the interpretation of 3 values:
  124. *
  125. * <ul>
  126. * <li> NESTED, if the scripting variable is available between
  127. * the start tag and the end tag of the action that defines it.
  128. * <li>
  129. * AT_BEGIN, if the scripting variable is available from the start tag
  130. * of the action that defines it until the end of the scope.
  131. * <li> AT_END, if the scripting variable is available after the end tag
  132. * of the action that defines it until the end of the scope.
  133. * </ul>
  134. *
  135. * The scope value for a variable implies what methods may affect its
  136. * value and thus where synchronization is needed:
  137. *
  138. * <ul>
  139. * <li>
  140. * for NESTED, after doInitBody and doAfterBody for a tag handler implementing
  141. * BodyTag, and after doStartTag otherwise.
  142. * <li>
  143. * for AT_BEGIN, after doInitBody, doAfterBody, and doEndTag
  144. * for a tag handler implementing BodyTag, and doStartTag and doEndTag otherwise.
  145. * <li>
  146. * for AT_END, after doEndTag method.
  147. * </ul>
  148. *
  149. * <p><B>Variable Information in the TLD</B>
  150. * <p>
  151. * Scripting variable information can also be encoded directly for most cases
  152. * into the Tag Library Descriptor using the <variable> subelement of the
  153. * <tag> element. See the JSP specification.
  154. */
  155. public class VariableInfo {
  156. /**
  157. *Scope information that scripting variable is visible only within the start/end tags
  158. */
  159. public static final int NESTED = 0;
  160. /**
  161. * Scope information that scripting variable is visible after start tag
  162. */
  163. public static final int AT_BEGIN = 1;
  164. /**
  165. * Scope information that scripting variable is visible after end tag
  166. */
  167. public static final int AT_END = 2;
  168. /**
  169. * Constructor
  170. * These objects can be created (at translation time) by the TagExtraInfo
  171. * instances.
  172. *
  173. * @param id The name of the scripting variable
  174. * @param className The name of the scripting variable
  175. * @param declare If true, it is a new variable (in some languages this will
  176. * require a declaration)
  177. * @param scope Indication on the lexical scope of the variable
  178. */
  179. public VariableInfo(String varName,
  180. String className,
  181. boolean declare,
  182. int scope) {
  183. this.varName = varName;
  184. this.className = className;
  185. this.declare = declare;
  186. this.scope = scope;
  187. }
  188. // Accessor methods
  189. public String getVarName() { return varName; }
  190. public String getClassName() { return className; }
  191. public boolean getDeclare() { return declare; }
  192. public int getScope() { return scope; }
  193. // == private data
  194. private String varName;
  195. private String className;
  196. private boolean declare;
  197. private int scope;
  198. }