Skip to contentMethod: toString()
1: /*
2: * Copyright (c) 1997, 2020 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: * Information on the attributes of a Tag, available at translation time. This class is instantiated from the Tag
23: * Library Descriptor file (TLD).
24: * <p>
25: * Only the information needed to generate code is included here. Other information like SCHEMA for validation belongs
26: * elsewhere.
27: * <p>
28: * Note from the Expert Group:<br>
29: * This should have been designed as an interface. Every time we change the TLD, we need to add a new constructor to
30: * this class (not good). This class should only be instantiated by container implementations (not by JSP developers).
31: */
32: public class TagAttributeInfo {
33:
34: /**
35: * "id" is wired in to be ID. There is no real benefit in having it be something else IDREFs are not handled any
36: * differently.
37: */
38: public static final String ID = "id";
39:
40: /**
41: * Constructor for TagAttributeInfo. This class is to be instantiated only from the TagLibrary code under request
42: * from some JSP code that is parsing a TLD (Tag Library Descriptor).
43: *
44: * @param name The name of the attribute.
45: * @param required If this attribute is required in tag instances.
46: * @param type The name of the type of the attribute.
47: * @param reqTime Whether this attribute holds a request-time Attribute.
48: */
49: public TagAttributeInfo(String name, boolean required, String type, boolean reqTime) {
50: this.name = name;
51: this.required = required;
52: this.type = type;
53: this.reqTime = reqTime;
54: }
55:
56: /**
57: * JSP 2.0 Constructor for TagAttributeInfo. This class is to be instantiated only from the TagLibrary code under
58: * request from some JSP code that is parsing a TLD (Tag Library Descriptor).
59: *
60: * @param name The name of the attribute.
61: * @param required If this attribute is required in tag instances.
62: * @param type The name of the type of the attribute.
63: * @param reqTime Whether this attribute holds a request-time Attribute.
64: * @param fragment Whether this attribute is of type JspFragment
65: *
66: * @since JSP 2.0
67: */
68: public TagAttributeInfo(String name, boolean required, String type, boolean reqTime, boolean fragment) {
69: this(name, required, type, reqTime);
70: this.fragment = fragment;
71: }
72:
73: /**
74: * JSP 2.1 Constructor for TagAttributeInfo. This class is to be instantiated only from the TagLibrary code under
75: * request from some JSP code that is parsing a TLD (Tag Library Descriptor).
76: *
77: * @param name The name of the attribute.
78: * @param required If this attribute is required in tag instances.
79: * @param type The name of the type of the attribute.
80: * @param reqTime Whether this attribute holds a request-time Attribute.
81: * @param fragment Whether this attribute is of type JspFragment
82: * @param description The description of the attribute.
83: * @param deferredValue Whether this attribute is a deferred value.
84: * @param deferredMethod Whether this attribute is a deferred method. rtexpr or deferred value.
85: * @param expectedTypeName The name of the expected type of this deferred value (or <code>null</code> if this is not
86: * a deferred value).
87: * @param methodSignature The expected method signature of this deferred method (or <code>null</code> if this is
88: * not a deferred method).
89: *
90: * @since JSP 2.1
91: */
92: public TagAttributeInfo(String name, boolean required, String type, boolean reqTime, boolean fragment,
93: String description, boolean deferredValue, boolean deferredMethod, String expectedTypeName,
94: String methodSignature) {
95: this(name, required, type, reqTime, fragment);
96: this.description = description;
97: this.deferredValue = deferredValue;
98: this.deferredMethod = deferredMethod;
99: this.expectedTypeName = expectedTypeName;
100: this.methodSignature = methodSignature;
101: }
102:
103: /**
104: * The name of this attribute.
105: *
106: * @return the name of the attribute
107: */
108: public String getName() {
109: return name;
110: }
111:
112: /**
113: * The type (as a String) of this attribute.
114: *
115: * <p>
116: * This method must return <code>"jakarta.el.ValueExpression"</code> if <code>isDeferredValue()</code> returns
117: * <code>true</code> and <code>canBeRequestTime()</code> returns <code>false</code>. It must return
118: * <code>"jakarta.el.MethodExpression"</code> if <code>isDeferredMethod()</code> returns <code>true</code>. It must
119: * return <code>"java.lang.Object"</code> if <code>isDeferredValue()</code> returns <code>true</code> and
120: * <code>canBeRequestTime()</code> returns <code>true</code>.
121: * </p>
122: *
123: * @return the type of the attribute
124: */
125: public String getTypeName() {
126: return type;
127: }
128:
129: /**
130: * Whether this attribute has been specified in the TLD as rtexprvalue. If <code>true</code>, this means the
131: * attribute can hold a request-time value.
132: *
133: * @return true if the attribute has been specified in the TLD as rtexprvalue
134: */
135: public boolean canBeRequestTime() {
136: return reqTime;
137: }
138:
139: /**
140: * Whether this attribute is required.
141: *
142: * @return if the attribute is required.
143: */
144: public boolean isRequired() {
145: return required;
146: }
147:
148: /**
149: * Convenience static method that goes through an array of TagAttributeInfo objects and looks for "id".
150: *
151: * @param a An array of TagAttributeInfo
152: * @return The TagAttributeInfo reference with name "id"
153: */
154: public static TagAttributeInfo getIdAttribute(TagAttributeInfo a[]) {
155: for (int i = 0; i < a.length; i++) {
156: if (a[i].getName().equals(ID)) {
157: return a[i];
158: }
159: }
160: return null; // no such attribute
161: }
162:
163: /**
164: * Whether this attribute is of type JspFragment.
165: *
166: * @return if the attribute is of type JspFragment
167: *
168: * @since JSP 2.0
169: */
170: public boolean isFragment() {
171: return fragment;
172: }
173:
174: /**
175: * Gets the description string of this tag attribute.
176: *
177: * @return the description string of this tag attribute
178: */
179: public String getDescription() {
180: return description;
181: }
182:
183: /**
184: * Returns <code>true</code> if this attribute is to be passed a <code>ValueExpression</code> so that expression
185: * evaluation can be deferred.
186: *
187: * <p>
188: * If this method returns <code>true</code>, then <code>getTypeName()</code> must return
189: * <code>"jakarta.el.ValueExpression"</code>.
190: * </p>
191: *
192: * <p>
193: * The <code>getExpectedType()</code> method can be used to retrieve the expected type this value expression will be
194: * constructed with.
195: * </p>
196: *
197: * @return <code>true</code> if this attribute accepts a deferred value; <code>false</code> otherwise.
198: *
199: * @since JSP 2.1
200: */
201: public boolean isDeferredValue() {
202: return deferredValue;
203: }
204:
205: /**
206: * Returns <code>true</code> if this attribute is to be passed a <code>MethodExpression</code> so that expression
207: * evaluation can be deferred.
208: *
209: * <p>
210: * If this method returns <code>true</code>, then <code>getTypeName()</code> must return
211: * <code>"jakarta.el.MethodExpression"</code>.
212: * </p>
213: *
214: * <p>
215: * The <code>getMethodSignature()</code> method can be used to retrieve the expected method signature this method
216: * expression will be constructed with.
217: * </p>
218: *
219: * @return <code>true</code> if this attribute accepts a deferred method; <code>false</code> otherwise.
220: *
221: * @since JSP 2.1
222: */
223: public boolean isDeferredMethod() {
224: return deferredMethod;
225: }
226:
227: /**
228: * Returns the name of the expected type (as a String) of this deferred value attribute.
229: *
230: * <p>
231: * This method returns <code>null</code> if <code>isDeferredValue()</code> returns <code>false</code>.
232: * </p>
233: *
234: * @return the name of the expected type
235: * @since JSP 2.1
236: */
237: public String getExpectedTypeName() {
238: return expectedTypeName;
239: }
240:
241: /**
242: * Returns the expected method signature of this deferred method attribute.
243: *
244: * <p>
245: * This method returns <code>null</code> if <code>isDeferredMethod()</code> returns <code>false</code>.
246: * </p>
247: *
248: * @return the method signature
249: * @since JSP 2.1
250: */
251: public String getMethodSignature() {
252: return methodSignature;
253: }
254:
255: /**
256: * Returns a String representation of this TagAttributeInfo, suitable for debugging purposes.
257: *
258: * @return a String representation of this TagAttributeInfo
259: */
260: @Override
261: public String toString() {
262: StringBuffer b = new StringBuffer();
263: b.append("name = " + name + " ");
264: b.append("type = " + type + " ");
265: b.append("reqTime = " + reqTime + " ");
266: b.append("required = " + required + " ");
267: b.append("fragment = " + fragment + " ");
268: b.append("deferredValue = " + deferredValue + " ");
269: b.append("deferredMethod = " + deferredMethod + " ");
270: b.append("expectedTypeName = " + expectedTypeName + " ");
271: b.append("methodSignature = " + methodSignature + " ");
272: return b.toString();
273: }
274:
275: /*
276: * private fields
277: */
278: private String name;
279: private String type;
280: private boolean reqTime;
281: private boolean required;
282:
283: /*
284: * private fields for JSP 2.0
285: */
286: private boolean fragment;
287:
288: /*
289: * private fields for JSP 2.1
290: */
291: private boolean deferredValue;
292: private boolean deferredMethod;
293: private String expectedTypeName;
294: private String methodSignature;
295: private String description;
296: }