1 16 19 20 package com.sun.org.apache.xml.internal.serializer; 21 22 import java.util.Hashtable ; 23 24 import org.xml.sax.Attributes ; 25 import org.xml.sax.helpers.AttributesImpl ; 26 27 35 public class AttributesImplSerializer extends AttributesImpl 36 { 37 42 private Hashtable m_indexFromQName = new Hashtable (); 43 44 48 public static final int MAX = 12; 49 50 54 private static final int MAXMinus1 = MAX - 1; 55 56 62 public int getIndex(String qname) 63 { 64 int index; 65 66 if (super.getLength() < MAX) 67 { 68 index = super.getIndex(qname); 71 return index; 72 } 73 Integer i = (Integer )m_indexFromQName.get(qname); 76 if (i == null) 77 index = -1; 78 else 79 index = i.intValue(); 80 return index; 81 } 82 94 public void addAttribute( 95 String uri, 96 String local, 97 String qname, 98 String type, 99 String val) 100 { 101 int index = super.getLength(); 102 super.addAttribute(uri, local, qname, type, val); 103 106 if (index < MAXMinus1) 107 { 108 return; 109 } 110 else if (index == MAXMinus1) 111 { 112 switchOverToHash(MAX); 113 } 114 else 115 { 116 117 Integer i = new Integer (index); 118 m_indexFromQName.put(qname, i); 119 } 120 return; 121 } 122 123 131 private void switchOverToHash(int numAtts) 132 { 133 for (int index = 0; index < numAtts; index++) 134 { 135 String qName = super.getQName(index); 136 Integer i = new Integer (index); 137 m_indexFromQName.put(qName, i); 138 } 139 } 140 141 146 public void clear() 147 { 148 149 int len = super.getLength(); 150 super.clear(); 151 if (MAX <= len) 152 { 153 m_indexFromQName.clear(); 156 } 157 158 } 159 160 168 public void setAttributes(Attributes atts) 169 { 170 171 super.setAttributes(atts); 172 173 int numAtts = atts.getLength(); 177 if (MAX <= numAtts) 178 switchOverToHash(numAtts); 179 180 } 181 } 182 | Popular Tags |