1 package javolution.xml.sax; 2 3 import j2me.lang.CharSequence; 4 import javolution.lang.Reusable; 5 import javolution.util.FastComparator; 6 import javolution.util.FastTable; 7 import javolution.xml.sax.Attributes; 8 9 19 public final class AttributesImpl implements Attributes, Reusable { 20 21 26 private static final int INCR = 6; 27 28 31 private int _length; 32 33 36 private FastTable _entries = new FastTable(); 37 38 42 45 public AttributesImpl() { 46 } 47 48 52 57 public int getLength() { 58 return _length; 59 } 60 61 68 public CharSequence getURI(int index) { 69 if (index >= 0 && index < _length) 70 return (CharSequence) _entries.get(index * INCR + URI_OFFSET); 71 return null; 72 } 73 74 81 public CharSequence getLocalName(int index) { 82 if (index >= 0 && index < _length) 83 return (CharSequence) _entries 84 .get(index * INCR + LOCAL_NAME_OFFSET); 85 return null; 86 } 87 88 95 public CharSequence getPrefix(int index) { 96 if (index >= 0 && index < _length) 97 return (CharSequence) _entries.get(index * INCR + PREFIX_OFFSET); 98 return null; 99 } 100 101 108 public CharSequence getQName(int index) { 109 if (index >= 0 && index < _length) 110 return (CharSequence) _entries.get(index * INCR + QNAME_OFFSET); 111 return null; 112 } 113 114 121 public String getType(int index) { 122 if (index >= 0 && index < _length) 123 return (String) _entries.get(index * INCR + TYPE_OFFSET); 124 return null; 125 126 } 127 128 134 public CharSequence getValue(int index) { 135 if (index >= 0 && index < _length) 136 return (CharSequence) _entries.get(index * INCR + VALUE_OFFSET); 137 return null; 138 } 139 140 151 public int getIndex(CharSequence uri, CharSequence localName) { 152 for (int i = 0; i < _length; i++) { 153 if (FastComparator.LEXICAL.areEqual(_entries.get(i * INCR 154 + URI_OFFSET), uri) 155 && FastComparator.LEXICAL.areEqual(_entries.get(i * INCR 156 + LOCAL_NAME_OFFSET), localName)) 157 return i; 158 } 159 return -1; 160 } 161 162 166 public int getIndex(String uri, String localName) { 167 for (int i = 0; i < _length; i++) { 168 if (FastComparator.LEXICAL.areEqual(_entries.get(i * INCR 169 + URI_OFFSET), uri) 170 && FastComparator.LEXICAL.areEqual(_entries.get(i * INCR 171 + LOCAL_NAME_OFFSET), localName)) 172 return i; 173 } 174 return -1; 175 } 176 177 183 public int getIndex(CharSequence qName) { 184 for (int i = 0; i < _length; i++) { 185 if (FastComparator.LEXICAL.areEqual(_entries.get(i * INCR 186 + QNAME_OFFSET), qName)) 187 return i; 188 } 189 return -1; 190 } 191 192 195 public int getIndex(String qName) { 196 for (int i = 0; i < _length; i++) { 197 if (FastComparator.LEXICAL.areEqual(_entries.get(i * INCR 198 + QNAME_OFFSET), qName)) 199 return i; 200 } 201 return -1; 202 } 203 204 212 public String getType(CharSequence uri, CharSequence localName) { 213 final int index = getIndex(uri, localName); 214 if (index >= 0) 215 return (String) _entries.get(index * INCR + TYPE_OFFSET); 216 return null; 217 } 218 219 223 public String getType(String uri, String localName) { 224 final int index = getIndex(uri, localName); 225 if (index >= 0) 226 return (String) _entries.get(index * INCR + TYPE_OFFSET); 227 return null; 228 } 229 230 236 public String getType(CharSequence qName) { 237 final int index = getIndex(qName); 238 if (index >= 0) 239 return (String) _entries.get(index * INCR + TYPE_OFFSET); 240 return null; 241 } 242 243 246 public String getType(String qName) { 247 final int index = getIndex(qName); 248 if (index >= 0) 249 return (String) _entries.get(index * INCR + TYPE_OFFSET); 250 return null; 251 } 252 253 261 public CharSequence getValue(CharSequence uri, CharSequence localName) { 262 final int index = getIndex(uri, localName); 263 if (index >= 0) 264 return (CharSequence) _entries.get(index * INCR + VALUE_OFFSET); 265 return null; 266 } 267 268 272 public CharSequence getValue(String uri, String localName) { 273 final int index = getIndex(uri, localName); 274 if (index >= 0) 275 return (CharSequence) _entries.get(index * INCR + VALUE_OFFSET); 276 return null; 277 } 278 279 285 public CharSequence getValue(CharSequence qName) { 286 final int index = getIndex(qName); 287 if (index >= 0) 288 return (CharSequence) _entries.get(index * INCR + VALUE_OFFSET); 289 return null; 290 } 291 292 295 public CharSequence getValue(String qName) { 296 final int index = getIndex(qName); 297 if (index >= 0) 298 return (CharSequence) _entries.get(index * INCR + VALUE_OFFSET); 299 return null; 300 } 301 302 306 309 public void reset() { 310 _entries.clear(); 311 _length = 0; 312 } 313 314 325 public int addAttribute(CharSequence uri, CharSequence localName, 326 CharSequence prefix, CharSequence qName, String type, 327 CharSequence value) { 328 _entries.addLast(uri); 329 _entries.addLast(localName); 330 _entries.addLast(prefix); 331 _entries.addLast(qName); 332 _entries.addLast(type); 333 _entries.addLast(value); 334 return _length++; 335 } 336 337 private static final int URI_OFFSET = 0; 338 339 private static final int LOCAL_NAME_OFFSET = 1; 340 341 private static final int PREFIX_OFFSET = 2; 342 343 private static final int QNAME_OFFSET = 3; 344 345 private static final int TYPE_OFFSET = 4; 346 347 private static final int VALUE_OFFSET = 5; 348 349 356 public void removeAttribute(int index) { 357 final int i = index * INCR; 358 _entries.removeRange(i, i + INCR); 359 _length--; 360 } 361 362 370 public void setURI(int index, CharSequence uri) { 371 _entries.set(index * INCR + URI_OFFSET, uri); 372 } 373 374 382 public void setLocalName(int index, CharSequence localName) { 383 _entries.set(index * INCR + LOCAL_NAME_OFFSET, localName); 384 } 385 386 394 public void setPrefix(int index, CharSequence prefix) { 395 _entries.set(index * INCR + PREFIX_OFFSET, prefix); 396 } 397 398 407 public void setQName(int index, CharSequence qName) { 408 _entries.set(index * INCR + QNAME_OFFSET, qName); 409 } 410 411 419 public void setType(int index, String type) { 420 _entries.set(index * INCR + TYPE_OFFSET, type); 421 } 422 423 431 public void setValue(int index, CharSequence value) { 432 _entries.set(index * INCR + VALUE_OFFSET, value); 433 } 434 435 } | Popular Tags |