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