1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 //
19 // This source code implements specifications defined by the Java
20 // Community Process. In order to remain compliant with the specification
21 // DO NOT add / change / or delete method signatures!
22 //
23
24 package javax.servlet.jsp.tagext;
25
26 /**
27 * Information on the attributes of a Tag, available at translation time.
28 * This class is instantiated from the Tag Library Descriptor file (TLD).
29 *
30 * <p>
31 * Only the information needed to generate code is included here. Other information
32 * like SCHEMA for validation belongs elsewhere.
33 */
34
35 public class TagAttributeInfo {
36 /**
37 * "id" is wired in to be ID. There is no real benefit in having it be something else
38 * IDREFs are not handled any differently.
39 */
40
41 public static final String ID = "id";
42
43 /**
44 * Constructor for TagAttributeInfo.
45 * This class is to be instantiated only from the
46 * TagLibrary code under request from some JSP code that is parsing a
47 * TLD (Tag Library Descriptor).
48 *
49 * @param name The name of the attribute.
50 * @param required If this attribute is required in tag instances.
51 * @param type The name of the type of the attribute.
52 * @param reqTime Whether this attribute holds a request-time Attribute.
53 */
54
55 public TagAttributeInfo(String name, boolean required,
56 String type, boolean reqTime)
57 {
58 this.name = name;
59 this.required = required;
60 this.type = type;
61 this.reqTime = reqTime;
62 }
63
64 /**
65 * JSP 2.0 Constructor for TagAttributeInfo.
66 * This class is to be instantiated only from the
67 * TagLibrary code under request from some JSP code that is parsing a
68 * TLD (Tag Library Descriptor).
69 *
70 * @param name The name of the attribute.
71 * @param required If this attribute is required in tag instances.
72 * @param type The name of the type of the attribute.
73 * @param reqTime Whether this attribute holds a request-time Attribute.
74 * @param fragment Whether this attribute is of type JspFragment
75 *
76 * @since 2.0
77 */
78
79 public TagAttributeInfo(String name, boolean required,
80 String type, boolean reqTime,
81 boolean fragment)
82 {
83 this( name, required, type, reqTime );
84 this.fragment = fragment;
85 }
86
87 /**
88 * The name of this attribute.
89 *
90 * @return the name of the attribute
91 */
92
93 public String getName() {
94 return name;
95 }
96
97 /**
98 * The type (as a String) of this attribute.
99 *
100 * @return the type of the attribute
101 */
102
103 public String getTypeName() {
104 return type;
105 }
106
107 /**
108 * Whether this attribute can hold a request-time value.
109 *
110 * @return if the attribute can hold a request-time value.
111 */
112
113 public boolean canBeRequestTime() {
114 return reqTime;
115 }
116
117 /**
118 * Whether this attribute is required.
119 *
120 * @return if the attribute is required.
121 */
122 public boolean isRequired() {
123 return required;
124 }
125
126 /**
127 * Convenience static method that goes through an array of TagAttributeInfo
128 * objects and looks for "id".
129 *
130 * @param a An array of TagAttributeInfo
131 * @return The TagAttributeInfo reference with name "id"
132 */
133 public static TagAttributeInfo getIdAttribute(TagAttributeInfo a[]) {
134 for (int i=0; i<a.length; i++) {
135 if (a[i].getName().equals(ID)) {
136 return a[i];
137 }
138 }
139 return null; // no such attribute
140 }
141
142 /**
143 * Whether this attribute is of type JspFragment.
144 *
145 * @return if the attribute is of type JspFragment
146 *
147 * @since 2.0
148 */
149 public boolean isFragment() {
150 return fragment;
151 }
152
153
154
155 /**
156 * Returns a String representation of this TagAttributeInfo, suitable
157 * for debugging purposes.
158 *
159 * @return a String representation of this TagAttributeInfo
160 */
161 public String toString() {
162 StringBuffer b = new StringBuffer();
163 b.append("name = "+name+" ");
164 b.append("type = "+type+" ");
165 b.append("reqTime = "+reqTime+" ");
166 b.append("required = "+required+" ");
167 b.append("fragment = "+fragment+" ");
168 return b.toString();
169 }
170
171 /*
172 * private fields
173 */
174 private String name;
175 private String type;
176 private boolean reqTime;
177 private boolean required;
178
179 /*
180 * private fields for JSP 2.0
181 */
182 private boolean fragment;
183 }