01: package uk.org.ponder.saxalizer;
02:
03: import java.util.Collections;
04: import java.util.Enumeration;
05: import java.util.TreeMap;
06:
07: import org.xml.sax.AttributeList;
08:
09: //import uk.org.ponder.util11.TreeMap;
10:
11: // NB - this is similar the DOM NamedNodeMap, only we do not allow indexing by integer.
12: // An oddly restrictive DOM thing....
13:
14: /** The class SAXAttributeHash is used within the class GenericSAXImpl in order to
15: * allow quick access to the XML attribute values stored within it by lookup
16: * on attribute name.
17: */
18:
19: public class SAXAttributeHash {
20:
21: // this is a hashtable of Strings (attribute names) to SAXAttributes
22: private TreeMap attributes = new TreeMap();
23:
24: /** Puts the supplied attribute into this hash.
25: * @param name The name of the attribute to be added.
26: * @param type The type of the attribute to be added. This parameter is effectively disused,
27: * but should really be set to <code>CDATA</code>. Isn't XML boring.
28: * @param value The value of the attribute to be added.
29: */
30: public void put(String name, String type, String value) {
31: // System.out.println("Putting attribute "+name+" with value "+value);
32: attributes.put(name, new SAXAttribute(type, value));
33: }
34:
35: /** Returns the attribute with the specified name.
36: * @param The name of the required attribute.
37: * @return The required attribute.
38: */
39: public SAXAttribute get(String name) {
40: return (SAXAttribute) attributes.get(name);
41: }
42:
43: // Ultimately this will have to fabricate an AttributeList once we have serialization.
44: // This will need a new concrete implementation of AttributeList that actually allows
45: // random set access (silly people)
46: Enumeration keys() {
47: return Collections.enumeration(attributes.keySet());
48: }
49:
50: SAXAttributeHash(AttributeList attrs) {
51: for (int i = 0; i < attrs.getLength(); ++i) {
52: put(attrs.getName(i), attrs.getType(i), attrs.getValue(i));
53: }
54: }
55:
56: public SAXAttributeHash() {
57: }
58: }
|