001: /*
002: * Copyright (c) 1998-2003 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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: *
028: * $Id: TagData.java,v 1.2 2004/09/29 00:12:48 cvs Exp $
029: */
030:
031: package javax.servlet.jsp.tagext;
032:
033: import java.util.Enumeration;
034: import java.util.Hashtable;
035:
036: /**
037: * Tag instance attributes and values. This information is used by
038: * TagExtraInfo to prepare VariableInfo.
039: */
040: public class TagData implements Cloneable {
041: /**
042: * Constant object used as a key for request time attributes.
043: */
044: public static final Object REQUEST_TIME_VALUE = new RequestTimeValue();
045:
046: private Hashtable attributes;
047:
048: /**
049: * Create a new TagData object based on an attribute key/value hash table.
050: */
051: public TagData(Hashtable attrs) {
052: this .attributes = new Hashtable(attrs);
053: if (attrs == null)
054: throw new NullPointerException();
055: }
056:
057: /**
058: * Create a new TagData object based on and array of attribute key/values.
059: */
060: public TagData(Object[][] attrs) {
061: attributes = new Hashtable();
062:
063: for (int i = 0; attrs != null && i < attrs.length; i++) {
064: attributes.put(attrs[i][0], attrs[i][1]);
065: }
066: }
067:
068: /**
069: * Returns the attribute with the given name.
070: */
071: public Object getAttribute(String attribute) {
072: return this .attributes.get(attribute);
073: }
074:
075: /**
076: * Sets the attribute with the given name.
077: */
078: public void setAttribute(String attribute, Object value) {
079: this .attributes.put(attribute, value);
080: }
081:
082: /**
083: * Enumerates the attribute names.
084: */
085: public Enumeration getAttributes() {
086: return this .attributes.keys();
087: }
088:
089: /**
090: * Return the attribute as a string.
091: */
092: public String getAttributeString(String name) {
093: Object value = this .attributes.get(name);
094:
095: if (value != null)
096: return value.toString();
097: else
098: return null;
099: }
100:
101: /**
102: * Return the id of the attribute as a string.
103: */
104: public String getId() {
105: return getAttributeString(TagAttributeInfo.ID);
106: }
107:
108: /**
109: * Clone the tag data.
110: */
111: public Object clone() {
112: return new TagData((Hashtable) attributes.clone());
113: }
114:
115: static class RequestTimeValue {
116: public String toString() {
117: return "RequestTimeValue[]";
118: }
119: }
120: }
|