KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > servlet > jsp > tagext > TagAttributeInfo


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 package javax.servlet.jsp.tagext;
19
20 /**
21  * Information on the attributes of a Tag, available at translation time. This
22  * class is instantiated from the Tag Library Descriptor file (TLD).
23  *
24  * <p>
25  * Only the information needed to generate code is included here. Other
26  * information like SCHEMA for validation belongs elsewhere.
27  */

28
29 public class TagAttributeInfo {
30     /**
31      * "id" is wired in to be ID. There is no real benefit in having it be
32      * something else IDREFs are not handled any differently.
33      */

34
35     public static final String JavaDoc ID = "id";
36
37     /**
38      * Constructor for TagAttributeInfo. This class is to be instantiated only
39      * from the TagLibrary code under request from some JSP code that is parsing
40      * a TLD (Tag Library Descriptor).
41      *
42      * @param name
43      * The name of the attribute.
44      * @param required
45      * If this attribute is required in tag instances.
46      * @param type
47      * The name of the type of the attribute.
48      * @param reqTime
49      * Whether this attribute holds a request-time Attribute.
50      */

51
52     public TagAttributeInfo(String JavaDoc name, boolean required, String JavaDoc type,
53             boolean reqTime) {
54         this.name = name;
55         this.required = required;
56         this.type = type;
57         this.reqTime = reqTime;
58     }
59
60     /**
61      * JSP 2.0 Constructor for TagAttributeInfo. This class is to be
62      * instantiated only from the TagLibrary code under request from some JSP
63      * code that is parsing a TLD (Tag Library Descriptor).
64      *
65      * @param name
66      * The name of the attribute.
67      * @param required
68      * If this attribute is required in tag instances.
69      * @param type
70      * The name of the type of the attribute.
71      * @param reqTime
72      * Whether this attribute holds a request-time Attribute.
73      * @param fragment
74      * Whether this attribute is of type JspFragment
75      *
76      * @since 2.0
77      */

78
79     public TagAttributeInfo(String JavaDoc name, boolean required, String JavaDoc type,
80             boolean reqTime, boolean fragment) {
81         this(name, required, type, reqTime);
82         this.fragment = fragment;
83     }
84
85     /**
86      * @since JSP 2.1
87      */

88     public TagAttributeInfo(String JavaDoc name, boolean required, String JavaDoc type,
89             boolean reqTime, boolean fragment, String JavaDoc description,
90             boolean deferredValue, boolean deferredMethod,
91             String JavaDoc expectedTypeName, String JavaDoc methodSignature) {
92         this(name, required, type, reqTime, fragment);
93         this.description = description;
94         this.deferredValue = deferredValue;
95         this.deferredMethod = deferredMethod;
96         this.expectedTypeName = expectedTypeName;
97         this.methodSignature = methodSignature;
98     }
99
100     /**
101      * The name of this attribute.
102      *
103      * @return the name of the attribute
104      */

105
106     public String JavaDoc 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 JavaDoc 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 JavaDoc getIdAttribute(TagAttributeInfo JavaDoc 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 JavaDoc toString() {
174         StringBuffer JavaDoc b = new StringBuffer JavaDoc(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 JavaDoc name;
191
192     private String JavaDoc 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 JavaDoc description;
207
208     private boolean deferredValue;
209
210     private boolean deferredMethod;
211
212     private String JavaDoc expectedTypeName;
213
214     private String JavaDoc methodSignature;
215
216     public boolean isDeferredMethod() {
217         return deferredMethod;
218     }
219
220     public boolean isDeferredValue() {
221         return deferredValue;
222     }
223
224     public String JavaDoc getDescription() {
225         return description;
226     }
227
228     public String JavaDoc getExpectedTypeName() {
229         return expectedTypeName;
230     }
231
232     public String JavaDoc getMethodSignature() {
233         return methodSignature;
234     }
235 }
236
Popular Tags