001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.servlet.jsp.tagext;
019:
020: /**
021: * Information on the attributes of a Tag, available at translation time. This
022: * class is instantiated from the Tag Library Descriptor file (TLD).
023: *
024: * <p>
025: * Only the information needed to generate code is included here. Other
026: * information like SCHEMA for validation belongs elsewhere.
027: */
028:
029: public class TagAttributeInfo {
030: /**
031: * "id" is wired in to be ID. There is no real benefit in having it be
032: * something else IDREFs are not handled any differently.
033: */
034:
035: public static final String ID = "id";
036:
037: /**
038: * Constructor for TagAttributeInfo. This class is to be instantiated only
039: * from the TagLibrary code under request from some JSP code that is parsing
040: * a TLD (Tag Library Descriptor).
041: *
042: * @param name
043: * The name of the attribute.
044: * @param required
045: * If this attribute is required in tag instances.
046: * @param type
047: * The name of the type of the attribute.
048: * @param reqTime
049: * Whether this attribute holds a request-time Attribute.
050: */
051:
052: public TagAttributeInfo(String name, boolean required, String type,
053: boolean reqTime) {
054: this .name = name;
055: this .required = required;
056: this .type = type;
057: this .reqTime = reqTime;
058: }
059:
060: /**
061: * JSP 2.0 Constructor for TagAttributeInfo. This class is to be
062: * instantiated only from the TagLibrary code under request from some JSP
063: * code that is parsing a TLD (Tag Library Descriptor).
064: *
065: * @param name
066: * The name of the attribute.
067: * @param required
068: * If this attribute is required in tag instances.
069: * @param type
070: * The name of the type of the attribute.
071: * @param reqTime
072: * Whether this attribute holds a request-time Attribute.
073: * @param fragment
074: * Whether this attribute is of type JspFragment
075: *
076: * @since 2.0
077: */
078:
079: public TagAttributeInfo(String name, boolean required, String type,
080: boolean reqTime, boolean fragment) {
081: this (name, required, type, reqTime);
082: this .fragment = fragment;
083: }
084:
085: /**
086: * @since JSP 2.1
087: */
088: public TagAttributeInfo(String name, boolean required, String type,
089: boolean reqTime, boolean fragment, String description,
090: boolean deferredValue, boolean deferredMethod,
091: String expectedTypeName, String methodSignature) {
092: this (name, required, type, reqTime, fragment);
093: this .description = description;
094: this .deferredValue = deferredValue;
095: this .deferredMethod = deferredMethod;
096: this .expectedTypeName = expectedTypeName;
097: this .methodSignature = methodSignature;
098: }
099:
100: /**
101: * The name of this attribute.
102: *
103: * @return the name of the attribute
104: */
105:
106: public String getName() {
107: return name;
108: }
109:
110: /**
111: * The type (as a String) of this attribute.
112: *
113: * @return the type of the attribute
114: */
115:
116: public String getTypeName() {
117: return type;
118: }
119:
120: /**
121: * Whether this attribute can hold a request-time value.
122: *
123: * @return if the attribute can hold a request-time value.
124: */
125:
126: public boolean canBeRequestTime() {
127: return reqTime;
128: }
129:
130: /**
131: * Whether this attribute is required.
132: *
133: * @return if the attribute is required.
134: */
135: public boolean isRequired() {
136: return required;
137: }
138:
139: /**
140: * Convenience static method that goes through an array of TagAttributeInfo
141: * objects and looks for "id".
142: *
143: * @param a
144: * An array of TagAttributeInfo
145: * @return The TagAttributeInfo reference with name "id"
146: */
147: public static TagAttributeInfo getIdAttribute(TagAttributeInfo a[]) {
148: for (int i = 0; i < a.length; i++) {
149: if (a[i].getName().equals(ID)) {
150: return a[i];
151: }
152: }
153: return null; // no such attribute
154: }
155:
156: /**
157: * Whether this attribute is of type JspFragment.
158: *
159: * @return if the attribute is of type JspFragment
160: *
161: * @since 2.0
162: */
163: public boolean isFragment() {
164: return fragment;
165: }
166:
167: /**
168: * Returns a String representation of this TagAttributeInfo, suitable for
169: * debugging purposes.
170: *
171: * @return a String representation of this TagAttributeInfo
172: */
173: public String toString() {
174: StringBuffer b = new StringBuffer(64);
175: b.append("name = " + name + " ");
176: b.append("type = " + type + " ");
177: b.append("reqTime = " + reqTime + " ");
178: b.append("required = " + required + " ");
179: b.append("fragment = " + fragment + " ");
180: b.append("deferredValue = " + deferredValue + " ");
181: b.append("expectedTypeName = " + expectedTypeName + " ");
182: b.append("deferredMethod = " + deferredMethod + " ");
183: b.append("methodSignature = " + methodSignature);
184: return b.toString();
185: }
186:
187: /*
188: * private fields
189: */
190: private String name;
191:
192: private String type;
193:
194: private boolean reqTime;
195:
196: private boolean required;
197:
198: /*
199: * private fields for JSP 2.0
200: */
201: private boolean fragment;
202:
203: /*
204: * private fields for JSP 2.1
205: */
206: private String description;
207:
208: private boolean deferredValue;
209:
210: private boolean deferredMethod;
211:
212: private String expectedTypeName;
213:
214: private String methodSignature;
215:
216: public boolean isDeferredMethod() {
217: return deferredMethod;
218: }
219:
220: public boolean isDeferredValue() {
221: return deferredValue;
222: }
223:
224: public String getDescription() {
225: return description;
226: }
227:
228: public String getExpectedTypeName() {
229: return expectedTypeName;
230: }
231:
232: public String getMethodSignature() {
233: return methodSignature;
234: }
235: }
|