Skip to contentMethod: TagExtraInfo()
1: /*
2: * Copyright (c) 1997, 2021 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: * Copyright 2004 The Apache Software Foundation
5: *
6: * Licensed under the Apache License, Version 2.0 (the "License");
7: * you may not use this file except in compliance with the License.
8: * You may obtain a copy of the License at
9: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package jakarta.servlet.jsp.tagext;
20:
21: /**
22: * Optional class provided by the tag library author to describe additional translation-time information not described
23: * in the TLD. The TagExtraInfo class is mentioned in the Tag Library Descriptor file (TLD).
24: *
25: * <p>
26: * This class can be used:
27: * <ul>
28: * <li>to indicate that the tag defines scripting variables
29: * <li>to perform translation-time validation of the tag attributes.
30: * </ul>
31: *
32: * <p>
33: * It is the responsibility of the JSP translator that the initial value to be returned by calls to getTagInfo()
34: * corresponds to a TagInfo object for the tag being translated. If an explicit call to setTagInfo() is done, then the
35: * object passed will be returned in subsequent calls to getTagInfo().
36: *
37: * <p>
38: * The only way to affect the value returned by getTagInfo() is through a setTagInfo() call, and thus,
39: * TagExtraInfo.setTagInfo() is to be called by the JSP translator, with a TagInfo object that corresponds to the tag
40: * being translated. The call should happen before any invocation on validate() and before any invocation on
41: * getVariableInfo().
42: *
43: * <p>
44: * <b>NOTE:</b> It is a (translation time) error for a tag definition in a TLD with one or more variable subelements
45: * to have an associated TagExtraInfo implementation that returns a VariableInfo array with one or more elements from a
46: * call to getVariableInfo().
47: */
48: public abstract class TagExtraInfo {
49:
50: /**
51: * Sole constructor. (For invocation by subclass constructors, typically implicit.)
52: */
53: public TagExtraInfo() {
54: }
55:
56: /**
57: * information on scripting variables defined by the tag associated with this TagExtraInfo instance. Request-time
58: * attributes are indicated as such in the TagData parameter.
59: *
60: * @param data The TagData instance.
61: * @return An array of VariableInfo data, or null or a zero length array if no scripting variables are to be
62: * defined.
63: */
64: public VariableInfo[] getVariableInfo(TagData data) {
65: return ZERO_VARIABLE_INFO;
66: }
67:
68: /**
69: * Translation-time validation of the attributes. Request-time attributes are indicated as such in the TagData
70: * parameter. Note that the preferred way to do validation is with the validate() method, since it can return more
71: * detailed information.
72: *
73: * @param data The TagData instance.
74: * @return Whether this tag instance is valid.
75: * @see TagExtraInfo#validate
76: */
77: public boolean isValid(TagData data) {
78: return true;
79: }
80:
81: /**
82: * Translation-time validation of the attributes. Request-time attributes are indicated as such in the TagData
83: * parameter. Because of the higher quality validation messages possible, this is the preferred way to do validation
84: * (although isValid() still works).
85: *
86: * <p>
87: * JSP 2.0 and higher containers call validate() instead of isValid(). The default implementation of this method is
88: * to call isValid(). If isValid() returns false, a generic ValidationMessage[] is returned indicating isValid()
89: * returned false.
90: * </p>
91: *
92: * @param data The TagData instance.
93: * @return A null object, or zero length array if no errors, an array of ValidationMessages otherwise.
94: * @since JSP 2.0
95: */
96: public ValidationMessage[] validate(TagData data) {
97: ValidationMessage[] result = null;
98:
99: if (!isValid(data)) {
100: result = new ValidationMessage[] { new ValidationMessage(data.getId(), "isValid() == false") };
101: }
102:
103: return result;
104: }
105:
106: /**
107: * Set the TagInfo for this class.
108: *
109: * @param tagInfo The TagInfo this instance is extending
110: */
111: public final void setTagInfo(TagInfo tagInfo) {
112: this.tagInfo = tagInfo;
113: }
114:
115: /**
116: * Get the TagInfo for this class.
117: *
118: * @return the taginfo instance this instance is extending
119: */
120: public final TagInfo getTagInfo() {
121: return tagInfo;
122: }
123:
124: // private data
125: private TagInfo tagInfo;
126:
127: // zero length VariableInfo array
128: private static final VariableInfo[] ZERO_VARIABLE_INFO = {};
129: }