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 import java.util.Hashtable; 029 030 /** 031 * The (translation-time only) attribute/value information for a tag instance. 032 * 033 * <p> 034 * TagData is only used as an argument to the isValid, validate, and 035 * getVariableInfo methods of TagExtraInfo, which are invoked at 036 * translation time. 037 */ 038 039 public class TagData implements Cloneable { 040 041 /** 042 * Distinguished value for an attribute to indicate its value 043 * is a request-time expression (which is not yet available because 044 * TagData instances are used at translation-time). 045 */ 046 047 public static final Object REQUEST_TIME_VALUE = new Object(); 048 049 050 /** 051 * Constructor for TagData. 052 * 053 * <p> 054 * A typical constructor may be 055 * <pre> 056 * static final Object[][] att = {{"connection", "conn0"}, {"id", "query0"}}; 057 * static final TagData td = new TagData(att); 058 * </pre> 059 * 060 * All values must be Strings except for those holding the 061 * distinguished object REQUEST_TIME_VALUE. 062 063 * @param atts the static attribute and values. May be null. 064 */ 065 public TagData(Object[] atts[]) { 066 if (atts == null) { 067 attributes = new Hashtable(); 068 } else { 069 attributes = new Hashtable(atts.length); 070 } 071 072 if (atts != null) { 073 for (int i = 0; i < atts.length; i++) { 074 attributes.put(atts[i][0], atts[i][1]); 075 } 076 } 077 } 078 079 /** 080 * Constructor for a TagData. 081 * 082 * If you already have the attributes in a hashtable, use this 083 * constructor. 084 * 085 * @param attrs A hashtable to get the values from. 086 */ 087 public TagData(Hashtable attrs) { 088 this.attributes = attrs; 089 } 090 091 /** 092 * The value of the tag's id attribute. 093 * 094 * @return the value of the tag's id attribute, or null if no such 095 * attribute was specified. 096 */ 097 098 public String getId() { 099 return getAttributeString(TagAttributeInfo.ID); 100 } 101 102 /** 103 * The value of the attribute. 104 * If a static value is specified for an attribute that accepts a 105 * request-time attribute expression then that static value is returned, 106 * even if the value is provided in the body of a <jsp:attribute> action. 107 * The distinguished object REQUEST_TIME_VALUE is only returned if 108 * the value is specified as a request-time attribute expression 109 * or via the <jsp:attribute> action with a body that contains 110 * dynamic content (scriptlets, scripting expressions, EL expressions, 111 * standard actions, or custom actions). Returns null if the attribute 112 * is not set. 113 * 114 * @param attName the name of the attribute 115 * @return the attribute's value 116 */ 117 118 public Object getAttribute(String attName) { 119 return attributes.get(attName); 120 } 121 122 /** 123 * Set the value of an attribute. 124 * 125 * @param attName the name of the attribute 126 * @param value the value. 127 */ 128 public void setAttribute(String attName, 129 Object value) { 130 attributes.put(attName, value); 131 } 132 133 /** 134 * Get the value for a given attribute. 135 * 136 * @param attName the name of the attribute 137 * @return the attribute value string 138 * @throws ClassCastException if attribute value is not a String 139 */ 140 141 public String getAttributeString(String attName) { 142 Object o = attributes.get(attName); 143 if (o == null) { 144 return null; 145 } else { 146 return (String) o; 147 } 148 } 149 150 /** 151 * Enumerates the attributes. 152 * 153 *@return An enumeration of the attributes in a TagData 154 */ 155 public java.util.Enumeration getAttributes() { 156 return attributes.keys(); 157 }; 158 159 // private data 160 161 private Hashtable attributes; // the tagname/value map 162 }