1 6 package org.xml.sax.helpers; 7 8 import org.xml.sax.AttributeList ; 9 10 import java.util.Vector ; 11 12 13 66 public class AttributeListImpl implements AttributeList 67 { 68 69 79 public AttributeListImpl () 80 { 81 } 82 83 84 94 public AttributeListImpl (AttributeList atts) 95 { 96 setAttributeList(atts); 97 } 98 99 100 101 105 106 114 public void setAttributeList (AttributeList atts) 115 { 116 int count = atts.getLength(); 117 118 clear(); 119 120 for (int i = 0; i < count; i++) { 121 addAttribute(atts.getName(i), atts.getType(i), atts.getValue(i)); 122 } 123 } 124 125 126 139 public void addAttribute (String name, String type, String value) 140 { 141 names.addElement(name); 142 types.addElement(type); 143 values.addElement(value); 144 } 145 146 147 161 public void removeAttribute (String name) 162 { 163 int i = names.indexOf(name); 164 165 if (i >= 0) { 166 names.removeElementAt(i); 167 types.removeElementAt(i); 168 values.removeElementAt(i); 169 } 170 } 171 172 173 183 public void clear () 184 { 185 names.removeAllElements(); 186 types.removeAllElements(); 187 values.removeAllElements(); 188 } 189 190 191 192 196 197 203 public int getLength () 204 { 205 return names.size(); 206 } 207 208 209 217 public String getName (int i) 218 { 219 if (i < 0) { 220 return null; 221 } 222 try { 223 return (String )names.elementAt(i); 224 } catch (ArrayIndexOutOfBoundsException e) { 225 return null; 226 } 227 } 228 229 230 240 public String getType (int i) 241 { 242 if (i < 0) { 243 return null; 244 } 245 try { 246 return (String )types.elementAt(i); 247 } catch (ArrayIndexOutOfBoundsException e) { 248 return null; 249 } 250 } 251 252 253 261 public String getValue (int i) 262 { 263 if (i < 0) { 264 return null; 265 } 266 try { 267 return (String )values.elementAt(i); 268 } catch (ArrayIndexOutOfBoundsException e) { 269 return null; 270 } 271 } 272 273 274 283 public String getType (String name) 284 { 285 return getType(names.indexOf(name)); 286 } 287 288 289 295 public String getValue (String name) 296 { 297 return getValue(names.indexOf(name)); 298 } 299 300 301 302 306 Vector names = new Vector (); 307 Vector types = new Vector (); 308 Vector values = new Vector (); 309 310 } 311 312 | Popular Tags |