001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package javax.servlet.jsp.tagext;
031:
032: /**
033: * Information about tag attributes. This information comes from the
034: * Tag Library Descriptor (TLD). Generally, a TagExtraInfo class will
035: * grab this information from the TagLibraryInfo class.
036: *
037: * <code><pre>
038: * <tag>
039: * <name>foo</name>
040: * <tagclass>com.caucho.tags.FooTag</tagclass>
041: *
042: * <attribute>
043: * <name>bar</name>
044: * <required>true</required>
045: * <rtexprvalue>false</rtexprvalue>
046: * </tag>
047: * </pre></code>
048: */
049: public class TagAttributeInfo {
050: /**
051: * ID is "id"
052: */
053: public static final String ID = "id";
054:
055: private String _name;
056: private boolean _reqTime;
057: private boolean _required;
058: private String _type;
059:
060: private boolean _fragment;
061:
062: private String _description;
063:
064: private boolean _isDeferredValue;
065: private boolean _isDeferredMethod;
066:
067: private String _expectedTypeName;
068: private String _methodSignature;
069:
070: /**
071: * Creates a new TagAttributeInfo object. Only the JSP engine will
072: * call this. It's not intended to be a public constructor.
073: *
074: * @param name the name of the attribute
075: * @param required true if the attribute must be present in the tag
076: * @param reqTime true if the attribute can be a request time attribute
077: * @param type the Java type of the attribute
078: */
079: public TagAttributeInfo(String name, boolean required, String type,
080: boolean reqTime) {
081: _name = name;
082: _required = required;
083: _type = type;
084: _reqTime = reqTime;
085: }
086:
087: /**
088: * Creates a new TagAttributeInfo object. Only the JSP engine will
089: * call this. It's not intended to be a public constructor.
090: *
091: * @param name the name of the attribute
092: * @param required true if the attribute must be present in the tag
093: * @param reqTime true if the attribute can be a request time attribute
094: * @param type the Java type of the attribute
095: */
096: public TagAttributeInfo(String name, boolean required, String type,
097: boolean reqTime, boolean fragment) {
098: this (name, required, type, reqTime);
099:
100: _fragment = fragment;
101: }
102:
103: /**
104: * Creates a new TagAttributeInfo object. Only the JSP engine will
105: * call this. It's not intended to be a public constructor.
106: *
107: * @param name the name of the attribute
108: * @param required true if the attribute must be present in the tag
109: * @param reqTime true if the attribute can be a request time attribute
110: * @param type the Java type of the attribute
111: */
112: public TagAttributeInfo(String name, boolean required, String type,
113: boolean reqTime, boolean fragment, String description,
114: boolean deferredValue, boolean deferredMethod,
115: String expectedTypeName, String methodSignature) {
116: this (name, required, type, reqTime, fragment);
117:
118: _description = description;
119: _isDeferredValue = deferredValue;
120: _isDeferredMethod = deferredMethod;
121: _expectedTypeName = expectedTypeName;
122: _methodSignature = methodSignature;
123: }
124:
125: /**
126: * Returns the attribute name
127: */
128: public String getName() {
129: return _name;
130: }
131:
132: /**
133: * Returns the type name of the attribute.
134: */
135: public String getTypeName() {
136: return _type;
137: }
138:
139: /**
140: * Returns true if the attribute can be a request time attribute (<%= ... %>).
141: */
142: public boolean canBeRequestTime() {
143: return _reqTime;
144: }
145:
146: /**
147: * True if the attribute must exist in the tag.
148: */
149: public boolean isRequired() {
150: return _required;
151: }
152:
153: /**
154: * True if the attribute is of type fragment
155: */
156: public boolean isFragment() {
157: return _fragment;
158: }
159:
160: /**
161: * Returns the tag's description.
162: *
163: * @since JSP 2.1
164: */
165: public String getDescription() {
166: return _description;
167: }
168:
169: /**
170: * Returns the expected type of the attribute.
171: *
172: * @since JSP 2.1
173: */
174: public String getExpectedTypeName() {
175: return _expectedTypeName;
176: }
177:
178: /**
179: * Returns the expected method signature.
180: *
181: * @since JSP 2.1
182: */
183: public String getMethodSignature() {
184: return _methodSignature;
185: }
186:
187: /**
188: * Returns true if the attribute is deferred.
189: *
190: * @since JSP 2.1
191: */
192: public boolean isDeferredMethod() {
193: return _isDeferredMethod;
194: }
195:
196: /**
197: * Returns true if the attribute is deferred.
198: *
199: * @since JSP 2.1
200: */
201: public boolean isDeferredValue() {
202: return _isDeferredValue;
203: }
204:
205: /**
206: * Convenience for finding a TagAttributeInfo in a TagAttributeInfo
207: * array.
208: */
209: public static TagAttributeInfo getIdAttribute(TagAttributeInfo[] a) {
210: for (int i = 0; i < a.length; i++)
211: if (a[i].getName().equals(ID))
212: return a[i];
213:
214: return null;
215: }
216: }
|