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