Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | // AttributesImpl.java - default implementation of Attributes. |
ohair@286 | 27 | // Written by David Megginson, sax@megginson.com |
ohair@286 | 28 | // NO WARRANTY! This class is in the public domain. |
ohair@286 | 29 | |
ohair@286 | 30 | // $Id: AttributesImpl.java,v 1.4 2002/09/29 02:55:48 okajima Exp $ |
ohair@286 | 31 | |
ohair@286 | 32 | //fixed bug at removeAttribute!! by Daisuke OKAJIMA 2002.4.21 |
ohair@286 | 33 | |
ohair@286 | 34 | package com.sun.tools.internal.jxc.gen.config; |
ohair@286 | 35 | |
ohair@286 | 36 | import org.xml.sax.Attributes; |
ohair@286 | 37 | |
ohair@286 | 38 | |
ohair@286 | 39 | /** |
ohair@286 | 40 | * Default implementation of the Attributes interface. |
ohair@286 | 41 | * |
ohair@286 | 42 | * <blockquote> |
ohair@286 | 43 | * <em>This module, both source code and documentation, is in the |
ohair@286 | 44 | * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> |
ohair@286 | 45 | * </blockquote> |
ohair@286 | 46 | * |
ohair@286 | 47 | * <p>This class provides a default implementation of the SAX2 |
ohair@286 | 48 | * {@link org.xml.sax.Attributes Attributes} interface, with the |
ohair@286 | 49 | * addition of manipulators so that the list can be modified or |
ohair@286 | 50 | * reused.</p> |
ohair@286 | 51 | * |
ohair@286 | 52 | * <p>There are two typical uses of this class:</p> |
ohair@286 | 53 | * |
ohair@286 | 54 | * <ol> |
ohair@286 | 55 | * <li>to take a persistent snapshot of an Attributes object |
ohair@286 | 56 | * in a {@link org.xml.sax.ContentHandler#startElement startElement} event; or</li> |
ohair@286 | 57 | * <li>to construct or modify an Attributes object in a SAX2 driver or filter.</li> |
ohair@286 | 58 | * </ol> |
ohair@286 | 59 | * |
ohair@286 | 60 | * <p>This class replaces the now-deprecated SAX1 {@link |
ohair@286 | 61 | * org.xml.sax.helpers.AttributeListImpl AttributeListImpl} |
ohair@286 | 62 | * class; in addition to supporting the updated Attributes |
ohair@286 | 63 | * interface rather than the deprecated {@link org.xml.sax.AttributeList |
ohair@286 | 64 | * AttributeList} interface, it also includes a much more efficient |
ohair@286 | 65 | * implementation using a single array rather than a set of Vectors.</p> |
ohair@286 | 66 | * |
ohair@286 | 67 | * @since SAX 2.0 |
ohair@286 | 68 | * @author David Megginson, |
ohair@286 | 69 | * <a href="mailto:sax@megginson.com">sax@megginson.com</a> |
ohair@286 | 70 | * @version 2.0 |
ohair@286 | 71 | */ |
ohair@286 | 72 | public class AttributesImpl implements Attributes |
ohair@286 | 73 | { |
ohair@286 | 74 | |
ohair@286 | 75 | |
ohair@286 | 76 | //////////////////////////////////////////////////////////////////// |
ohair@286 | 77 | // Constructors. |
ohair@286 | 78 | //////////////////////////////////////////////////////////////////// |
ohair@286 | 79 | |
ohair@286 | 80 | |
ohair@286 | 81 | /** |
ohair@286 | 82 | * Construct a new, empty AttributesImpl object. |
ohair@286 | 83 | */ |
ohair@286 | 84 | public AttributesImpl () |
ohair@286 | 85 | { |
ohair@286 | 86 | length = 0; |
ohair@286 | 87 | data = null; |
ohair@286 | 88 | } |
ohair@286 | 89 | |
ohair@286 | 90 | |
ohair@286 | 91 | /** |
ohair@286 | 92 | * Copy an existing Attributes object. |
ohair@286 | 93 | * |
ohair@286 | 94 | * <p>This constructor is especially useful inside a |
ohair@286 | 95 | * {@link org.xml.sax.ContentHandler#startElement startElement} event.</p> |
ohair@286 | 96 | * |
ohair@286 | 97 | * @param atts The existing Attributes object. |
ohair@286 | 98 | */ |
ohair@286 | 99 | public AttributesImpl (Attributes atts) |
ohair@286 | 100 | { |
ohair@286 | 101 | setAttributes(atts); |
ohair@286 | 102 | } |
ohair@286 | 103 | |
ohair@286 | 104 | |
ohair@286 | 105 | |
ohair@286 | 106 | //////////////////////////////////////////////////////////////////// |
ohair@286 | 107 | // Implementation of org.xml.sax.Attributes. |
ohair@286 | 108 | //////////////////////////////////////////////////////////////////// |
ohair@286 | 109 | |
ohair@286 | 110 | |
ohair@286 | 111 | /** |
ohair@286 | 112 | * Return the number of attributes in the list. |
ohair@286 | 113 | * |
ohair@286 | 114 | * @return The number of attributes in the list. |
ohair@286 | 115 | * @see org.xml.sax.Attributes#getLength |
ohair@286 | 116 | */ |
ohair@286 | 117 | public int getLength () |
ohair@286 | 118 | { |
ohair@286 | 119 | return length; |
ohair@286 | 120 | } |
ohair@286 | 121 | |
ohair@286 | 122 | |
ohair@286 | 123 | /** |
ohair@286 | 124 | * Return an attribute's Namespace URI. |
ohair@286 | 125 | * |
ohair@286 | 126 | * @param index The attribute's index (zero-based). |
ohair@286 | 127 | * @return The Namespace URI, the empty string if none is |
ohair@286 | 128 | * available, or null if the index is out of range. |
ohair@286 | 129 | * @see org.xml.sax.Attributes#getURI |
ohair@286 | 130 | */ |
ohair@286 | 131 | public String getURI (int index) |
ohair@286 | 132 | { |
ohair@286 | 133 | if (index >= 0 && index < length) { |
ohair@286 | 134 | return data[index*5]; |
ohair@286 | 135 | } else { |
ohair@286 | 136 | return null; |
ohair@286 | 137 | } |
ohair@286 | 138 | } |
ohair@286 | 139 | |
ohair@286 | 140 | |
ohair@286 | 141 | /** |
ohair@286 | 142 | * Return an attribute's local name. |
ohair@286 | 143 | * |
ohair@286 | 144 | * @param index The attribute's index (zero-based). |
ohair@286 | 145 | * @return The attribute's local name, the empty string if |
ohair@286 | 146 | * none is available, or null if the index if out of range. |
ohair@286 | 147 | * @see org.xml.sax.Attributes#getLocalName |
ohair@286 | 148 | */ |
ohair@286 | 149 | public String getLocalName (int index) |
ohair@286 | 150 | { |
ohair@286 | 151 | if (index >= 0 && index < length) { |
ohair@286 | 152 | return data[index*5+1]; |
ohair@286 | 153 | } else { |
ohair@286 | 154 | return null; |
ohair@286 | 155 | } |
ohair@286 | 156 | } |
ohair@286 | 157 | |
ohair@286 | 158 | |
ohair@286 | 159 | /** |
ohair@286 | 160 | * Return an attribute's qualified (prefixed) name. |
ohair@286 | 161 | * |
ohair@286 | 162 | * @param index The attribute's index (zero-based). |
ohair@286 | 163 | * @return The attribute's qualified name, the empty string if |
ohair@286 | 164 | * none is available, or null if the index is out of bounds. |
ohair@286 | 165 | * @see org.xml.sax.Attributes#getQName |
ohair@286 | 166 | */ |
ohair@286 | 167 | public String getQName (int index) |
ohair@286 | 168 | { |
ohair@286 | 169 | if (index >= 0 && index < length) { |
ohair@286 | 170 | return data[index*5+2]; |
ohair@286 | 171 | } else { |
ohair@286 | 172 | return null; |
ohair@286 | 173 | } |
ohair@286 | 174 | } |
ohair@286 | 175 | |
ohair@286 | 176 | |
ohair@286 | 177 | /** |
ohair@286 | 178 | * Return an attribute's type by index. |
ohair@286 | 179 | * |
ohair@286 | 180 | * @param index The attribute's index (zero-based). |
ohair@286 | 181 | * @return The attribute's type, "CDATA" if the type is unknown, or null |
ohair@286 | 182 | * if the index is out of bounds. |
ohair@286 | 183 | * @see org.xml.sax.Attributes#getType(int) |
ohair@286 | 184 | */ |
ohair@286 | 185 | public String getType (int index) |
ohair@286 | 186 | { |
ohair@286 | 187 | if (index >= 0 && index < length) { |
ohair@286 | 188 | return data[index*5+3]; |
ohair@286 | 189 | } else { |
ohair@286 | 190 | return null; |
ohair@286 | 191 | } |
ohair@286 | 192 | } |
ohair@286 | 193 | |
ohair@286 | 194 | |
ohair@286 | 195 | /** |
ohair@286 | 196 | * Return an attribute's value by index. |
ohair@286 | 197 | * |
ohair@286 | 198 | * @param index The attribute's index (zero-based). |
ohair@286 | 199 | * @return The attribute's value or null if the index is out of bounds. |
ohair@286 | 200 | * @see org.xml.sax.Attributes#getValue(int) |
ohair@286 | 201 | */ |
ohair@286 | 202 | public String getValue (int index) |
ohair@286 | 203 | { |
ohair@286 | 204 | if (index >= 0 && index < length) { |
ohair@286 | 205 | return data[index*5+4]; |
ohair@286 | 206 | } else { |
ohair@286 | 207 | return null; |
ohair@286 | 208 | } |
ohair@286 | 209 | } |
ohair@286 | 210 | |
ohair@286 | 211 | |
ohair@286 | 212 | /** |
ohair@286 | 213 | * Look up an attribute's index by Namespace name. |
ohair@286 | 214 | * |
ohair@286 | 215 | * <p>In many cases, it will be more efficient to look up the name once and |
ohair@286 | 216 | * use the index query methods rather than using the name query methods |
ohair@286 | 217 | * repeatedly.</p> |
ohair@286 | 218 | * |
ohair@286 | 219 | * @param uri The attribute's Namespace URI, or the empty |
ohair@286 | 220 | * string if none is available. |
ohair@286 | 221 | * @param localName The attribute's local name. |
ohair@286 | 222 | * @return The attribute's index, or -1 if none matches. |
ohair@286 | 223 | * @see org.xml.sax.Attributes#getIndex(java.lang.String,java.lang.String) |
ohair@286 | 224 | */ |
ohair@286 | 225 | public int getIndex (String uri, String localName) |
ohair@286 | 226 | { |
ohair@286 | 227 | int max = length * 5; |
ohair@286 | 228 | for (int i = 0; i < max; i += 5) { |
ohair@286 | 229 | if (data[i].equals(uri) && data[i+1].equals(localName)) { |
ohair@286 | 230 | return i / 5; |
ohair@286 | 231 | } |
ohair@286 | 232 | } |
ohair@286 | 233 | return -1; |
ohair@286 | 234 | } |
ohair@286 | 235 | |
ohair@286 | 236 | |
ohair@286 | 237 | /** |
ohair@286 | 238 | * Look up an attribute's index by qualified (prefixed) name. |
ohair@286 | 239 | * |
ohair@286 | 240 | * @param qName The qualified name. |
ohair@286 | 241 | * @return The attribute's index, or -1 if none matches. |
ohair@286 | 242 | * @see org.xml.sax.Attributes#getIndex(java.lang.String) |
ohair@286 | 243 | */ |
ohair@286 | 244 | public int getIndex (String qName) |
ohair@286 | 245 | { |
ohair@286 | 246 | int max = length * 5; |
ohair@286 | 247 | for (int i = 0; i < max; i += 5) { |
ohair@286 | 248 | if (data[i+2].equals(qName)) { |
ohair@286 | 249 | return i / 5; |
ohair@286 | 250 | } |
ohair@286 | 251 | } |
ohair@286 | 252 | return -1; |
ohair@286 | 253 | } |
ohair@286 | 254 | |
ohair@286 | 255 | |
ohair@286 | 256 | /** |
ohair@286 | 257 | * Look up an attribute's type by Namespace-qualified name. |
ohair@286 | 258 | * |
ohair@286 | 259 | * @param uri The Namespace URI, or the empty string for a name |
ohair@286 | 260 | * with no explicit Namespace URI. |
ohair@286 | 261 | * @param localName The local name. |
ohair@286 | 262 | * @return The attribute's type, or null if there is no |
ohair@286 | 263 | * matching attribute. |
ohair@286 | 264 | * @see org.xml.sax.Attributes#getType(java.lang.String,java.lang.String) |
ohair@286 | 265 | */ |
ohair@286 | 266 | public String getType (String uri, String localName) |
ohair@286 | 267 | { |
ohair@286 | 268 | int max = length * 5; |
ohair@286 | 269 | for (int i = 0; i < max; i += 5) { |
ohair@286 | 270 | if (data[i].equals(uri) && data[i+1].equals(localName)) { |
ohair@286 | 271 | return data[i+3]; |
ohair@286 | 272 | } |
ohair@286 | 273 | } |
ohair@286 | 274 | return null; |
ohair@286 | 275 | } |
ohair@286 | 276 | |
ohair@286 | 277 | |
ohair@286 | 278 | /** |
ohair@286 | 279 | * Look up an attribute's type by qualified (prefixed) name. |
ohair@286 | 280 | * |
ohair@286 | 281 | * @param qName The qualified name. |
ohair@286 | 282 | * @return The attribute's type, or null if there is no |
ohair@286 | 283 | * matching attribute. |
ohair@286 | 284 | * @see org.xml.sax.Attributes#getType(java.lang.String) |
ohair@286 | 285 | */ |
ohair@286 | 286 | public String getType (String qName) |
ohair@286 | 287 | { |
ohair@286 | 288 | int max = length * 5; |
ohair@286 | 289 | for (int i = 0; i < max; i += 5) { |
ohair@286 | 290 | if (data[i+2].equals(qName)) { |
ohair@286 | 291 | return data[i+3]; |
ohair@286 | 292 | } |
ohair@286 | 293 | } |
ohair@286 | 294 | return null; |
ohair@286 | 295 | } |
ohair@286 | 296 | |
ohair@286 | 297 | |
ohair@286 | 298 | /** |
ohair@286 | 299 | * Look up an attribute's value by Namespace-qualified name. |
ohair@286 | 300 | * |
ohair@286 | 301 | * @param uri The Namespace URI, or the empty string for a name |
ohair@286 | 302 | * with no explicit Namespace URI. |
ohair@286 | 303 | * @param localName The local name. |
ohair@286 | 304 | * @return The attribute's value, or null if there is no |
ohair@286 | 305 | * matching attribute. |
ohair@286 | 306 | * @see org.xml.sax.Attributes#getValue(java.lang.String,java.lang.String) |
ohair@286 | 307 | */ |
ohair@286 | 308 | public String getValue (String uri, String localName) |
ohair@286 | 309 | { |
ohair@286 | 310 | int max = length * 5; |
ohair@286 | 311 | for (int i = 0; i < max; i += 5) { |
ohair@286 | 312 | if (data[i].equals(uri) && data[i+1].equals(localName)) { |
ohair@286 | 313 | return data[i+4]; |
ohair@286 | 314 | } |
ohair@286 | 315 | } |
ohair@286 | 316 | return null; |
ohair@286 | 317 | } |
ohair@286 | 318 | |
ohair@286 | 319 | |
ohair@286 | 320 | /** |
ohair@286 | 321 | * Look up an attribute's value by qualified (prefixed) name. |
ohair@286 | 322 | * |
ohair@286 | 323 | * @param qName The qualified name. |
ohair@286 | 324 | * @return The attribute's value, or null if there is no |
ohair@286 | 325 | * matching attribute. |
ohair@286 | 326 | * @see org.xml.sax.Attributes#getValue(java.lang.String) |
ohair@286 | 327 | */ |
ohair@286 | 328 | public String getValue (String qName) |
ohair@286 | 329 | { |
ohair@286 | 330 | int max = length * 5; |
ohair@286 | 331 | for (int i = 0; i < max; i += 5) { |
ohair@286 | 332 | if (data[i+2].equals(qName)) { |
ohair@286 | 333 | return data[i+4]; |
ohair@286 | 334 | } |
ohair@286 | 335 | } |
ohair@286 | 336 | return null; |
ohair@286 | 337 | } |
ohair@286 | 338 | |
ohair@286 | 339 | |
ohair@286 | 340 | |
ohair@286 | 341 | //////////////////////////////////////////////////////////////////// |
ohair@286 | 342 | // Manipulators. |
ohair@286 | 343 | //////////////////////////////////////////////////////////////////// |
ohair@286 | 344 | |
ohair@286 | 345 | |
ohair@286 | 346 | /** |
ohair@286 | 347 | * Clear the attribute list for reuse. |
ohair@286 | 348 | * |
ohair@286 | 349 | * <p>Note that no memory is actually freed by this call: |
ohair@286 | 350 | * the current arrays are kept so that they can be |
ohair@286 | 351 | * reused.</p> |
ohair@286 | 352 | */ |
ohair@286 | 353 | public void clear () |
ohair@286 | 354 | { |
ohair@286 | 355 | length = 0; |
ohair@286 | 356 | } |
ohair@286 | 357 | |
ohair@286 | 358 | |
ohair@286 | 359 | /** |
ohair@286 | 360 | * Copy an entire Attributes object. |
ohair@286 | 361 | * |
ohair@286 | 362 | * <p>It may be more efficient to reuse an existing object |
ohair@286 | 363 | * rather than constantly allocating new ones.</p> |
ohair@286 | 364 | * |
ohair@286 | 365 | * @param atts The attributes to copy. |
ohair@286 | 366 | */ |
ohair@286 | 367 | public void setAttributes (Attributes atts) |
ohair@286 | 368 | { |
ohair@286 | 369 | clear(); |
ohair@286 | 370 | length = atts.getLength(); |
ohair@286 | 371 | data = new String[length*5]; |
ohair@286 | 372 | for (int i = 0; i < length; i++) { |
ohair@286 | 373 | data[i*5] = atts.getURI(i); |
ohair@286 | 374 | data[i*5+1] = atts.getLocalName(i); |
ohair@286 | 375 | data[i*5+2] = atts.getQName(i); |
ohair@286 | 376 | data[i*5+3] = atts.getType(i); |
ohair@286 | 377 | data[i*5+4] = atts.getValue(i); |
ohair@286 | 378 | } |
ohair@286 | 379 | } |
ohair@286 | 380 | |
ohair@286 | 381 | |
ohair@286 | 382 | /** |
ohair@286 | 383 | * Add an attribute to the end of the list. |
ohair@286 | 384 | * |
ohair@286 | 385 | * <p>For the sake of speed, this method does no checking |
ohair@286 | 386 | * to see if the attribute is already in the list: that is |
ohair@286 | 387 | * the responsibility of the application.</p> |
ohair@286 | 388 | * |
ohair@286 | 389 | * @param uri The Namespace URI, or the empty string if |
ohair@286 | 390 | * none is available or Namespace processing is not |
ohair@286 | 391 | * being performed. |
ohair@286 | 392 | * @param localName The local name, or the empty string if |
ohair@286 | 393 | * Namespace processing is not being performed. |
ohair@286 | 394 | * @param qName The qualified (prefixed) name, or the empty string |
ohair@286 | 395 | * if qualified names are not available. |
ohair@286 | 396 | * @param type The attribute type as a string. |
ohair@286 | 397 | * @param value The attribute value. |
ohair@286 | 398 | */ |
ohair@286 | 399 | public void addAttribute (String uri, String localName, String qName, |
ohair@286 | 400 | String type, String value) |
ohair@286 | 401 | { |
ohair@286 | 402 | ensureCapacity(length+1); |
ohair@286 | 403 | data[length*5] = uri; |
ohair@286 | 404 | data[length*5+1] = localName; |
ohair@286 | 405 | data[length*5+2] = qName; |
ohair@286 | 406 | data[length*5+3] = type; |
ohair@286 | 407 | data[length*5+4] = value; |
ohair@286 | 408 | length++; |
ohair@286 | 409 | } |
ohair@286 | 410 | |
ohair@286 | 411 | |
ohair@286 | 412 | /** |
ohair@286 | 413 | * Set an attribute in the list. |
ohair@286 | 414 | * |
ohair@286 | 415 | * <p>For the sake of speed, this method does no checking |
ohair@286 | 416 | * for name conflicts or well-formedness: such checks are the |
ohair@286 | 417 | * responsibility of the application.</p> |
ohair@286 | 418 | * |
ohair@286 | 419 | * @param index The index of the attribute (zero-based). |
ohair@286 | 420 | * @param uri The Namespace URI, or the empty string if |
ohair@286 | 421 | * none is available or Namespace processing is not |
ohair@286 | 422 | * being performed. |
ohair@286 | 423 | * @param localName The local name, or the empty string if |
ohair@286 | 424 | * Namespace processing is not being performed. |
ohair@286 | 425 | * @param qName The qualified name, or the empty string |
ohair@286 | 426 | * if qualified names are not available. |
ohair@286 | 427 | * @param type The attribute type as a string. |
ohair@286 | 428 | * @param value The attribute value. |
ohair@286 | 429 | * @exception java.lang.ArrayIndexOutOfBoundsException When the |
ohair@286 | 430 | * supplied index does not point to an attribute |
ohair@286 | 431 | * in the list. |
ohair@286 | 432 | */ |
ohair@286 | 433 | public void setAttribute (int index, String uri, String localName, |
ohair@286 | 434 | String qName, String type, String value) |
ohair@286 | 435 | { |
ohair@286 | 436 | if (index >= 0 && index < length) { |
ohair@286 | 437 | data[index*5] = uri; |
ohair@286 | 438 | data[index*5+1] = localName; |
ohair@286 | 439 | data[index*5+2] = qName; |
ohair@286 | 440 | data[index*5+3] = type; |
ohair@286 | 441 | data[index*5+4] = value; |
ohair@286 | 442 | } else { |
ohair@286 | 443 | badIndex(index); |
ohair@286 | 444 | } |
ohair@286 | 445 | } |
ohair@286 | 446 | |
ohair@286 | 447 | |
ohair@286 | 448 | /** |
ohair@286 | 449 | * Remove an attribute from the list. |
ohair@286 | 450 | * |
ohair@286 | 451 | * @param index The index of the attribute (zero-based). |
ohair@286 | 452 | * @exception java.lang.ArrayIndexOutOfBoundsException When the |
ohair@286 | 453 | * supplied index does not point to an attribute |
ohair@286 | 454 | * in the list. |
ohair@286 | 455 | */ |
ohair@286 | 456 | public void removeAttribute (int index) |
ohair@286 | 457 | { |
ohair@286 | 458 | if (index >= 0 && index < length) { |
ohair@286 | 459 | if (index < length - 1) { |
ohair@286 | 460 | System.arraycopy(data, (index+1)*5, data, index*5, |
ohair@286 | 461 | (length-index-1)*5); |
ohair@286 | 462 | } |
ohair@286 | 463 | length--; |
ohair@286 | 464 | } else { |
ohair@286 | 465 | badIndex(index); |
ohair@286 | 466 | } |
ohair@286 | 467 | } |
ohair@286 | 468 | |
ohair@286 | 469 | |
ohair@286 | 470 | /** |
ohair@286 | 471 | * Set the Namespace URI of a specific attribute. |
ohair@286 | 472 | * |
ohair@286 | 473 | * @param index The index of the attribute (zero-based). |
ohair@286 | 474 | * @param uri The attribute's Namespace URI, or the empty |
ohair@286 | 475 | * string for none. |
ohair@286 | 476 | * @exception java.lang.ArrayIndexOutOfBoundsException When the |
ohair@286 | 477 | * supplied index does not point to an attribute |
ohair@286 | 478 | * in the list. |
ohair@286 | 479 | */ |
ohair@286 | 480 | public void setURI (int index, String uri) |
ohair@286 | 481 | { |
ohair@286 | 482 | if (index >= 0 && index < length) { |
ohair@286 | 483 | data[index*5] = uri; |
ohair@286 | 484 | } else { |
ohair@286 | 485 | badIndex(index); |
ohair@286 | 486 | } |
ohair@286 | 487 | } |
ohair@286 | 488 | |
ohair@286 | 489 | |
ohair@286 | 490 | /** |
ohair@286 | 491 | * Set the local name of a specific attribute. |
ohair@286 | 492 | * |
ohair@286 | 493 | * @param index The index of the attribute (zero-based). |
ohair@286 | 494 | * @param localName The attribute's local name, or the empty |
ohair@286 | 495 | * string for none. |
ohair@286 | 496 | * @exception java.lang.ArrayIndexOutOfBoundsException When the |
ohair@286 | 497 | * supplied index does not point to an attribute |
ohair@286 | 498 | * in the list. |
ohair@286 | 499 | */ |
ohair@286 | 500 | public void setLocalName (int index, String localName) |
ohair@286 | 501 | { |
ohair@286 | 502 | if (index >= 0 && index < length) { |
ohair@286 | 503 | data[index*5+1] = localName; |
ohair@286 | 504 | } else { |
ohair@286 | 505 | badIndex(index); |
ohair@286 | 506 | } |
ohair@286 | 507 | } |
ohair@286 | 508 | |
ohair@286 | 509 | |
ohair@286 | 510 | /** |
ohair@286 | 511 | * Set the qualified name of a specific attribute. |
ohair@286 | 512 | * |
ohair@286 | 513 | * @param index The index of the attribute (zero-based). |
ohair@286 | 514 | * @param qName The attribute's qualified name, or the empty |
ohair@286 | 515 | * string for none. |
ohair@286 | 516 | * @exception java.lang.ArrayIndexOutOfBoundsException When the |
ohair@286 | 517 | * supplied index does not point to an attribute |
ohair@286 | 518 | * in the list. |
ohair@286 | 519 | */ |
ohair@286 | 520 | public void setQName (int index, String qName) |
ohair@286 | 521 | { |
ohair@286 | 522 | if (index >= 0 && index < length) { |
ohair@286 | 523 | data[index*5+2] = qName; |
ohair@286 | 524 | } else { |
ohair@286 | 525 | badIndex(index); |
ohair@286 | 526 | } |
ohair@286 | 527 | } |
ohair@286 | 528 | |
ohair@286 | 529 | |
ohair@286 | 530 | /** |
ohair@286 | 531 | * Set the type of a specific attribute. |
ohair@286 | 532 | * |
ohair@286 | 533 | * @param index The index of the attribute (zero-based). |
ohair@286 | 534 | * @param type The attribute's type. |
ohair@286 | 535 | * @exception java.lang.ArrayIndexOutOfBoundsException When the |
ohair@286 | 536 | * supplied index does not point to an attribute |
ohair@286 | 537 | * in the list. |
ohair@286 | 538 | */ |
ohair@286 | 539 | public void setType (int index, String type) |
ohair@286 | 540 | { |
ohair@286 | 541 | if (index >= 0 && index < length) { |
ohair@286 | 542 | data[index*5+3] = type; |
ohair@286 | 543 | } else { |
ohair@286 | 544 | badIndex(index); |
ohair@286 | 545 | } |
ohair@286 | 546 | } |
ohair@286 | 547 | |
ohair@286 | 548 | |
ohair@286 | 549 | /** |
ohair@286 | 550 | * Set the value of a specific attribute. |
ohair@286 | 551 | * |
ohair@286 | 552 | * @param index The index of the attribute (zero-based). |
ohair@286 | 553 | * @param value The attribute's value. |
ohair@286 | 554 | * @exception java.lang.ArrayIndexOutOfBoundsException When the |
ohair@286 | 555 | * supplied index does not point to an attribute |
ohair@286 | 556 | * in the list. |
ohair@286 | 557 | */ |
ohair@286 | 558 | public void setValue (int index, String value) |
ohair@286 | 559 | { |
ohair@286 | 560 | if (index >= 0 && index < length) { |
ohair@286 | 561 | data[index*5+4] = value; |
ohair@286 | 562 | } else { |
ohair@286 | 563 | badIndex(index); |
ohair@286 | 564 | } |
ohair@286 | 565 | } |
ohair@286 | 566 | |
ohair@286 | 567 | |
ohair@286 | 568 | |
ohair@286 | 569 | //////////////////////////////////////////////////////////////////// |
ohair@286 | 570 | // Internal methods. |
ohair@286 | 571 | //////////////////////////////////////////////////////////////////// |
ohair@286 | 572 | |
ohair@286 | 573 | |
ohair@286 | 574 | /** |
ohair@286 | 575 | * Ensure the internal array's capacity. |
ohair@286 | 576 | * |
ohair@286 | 577 | * @param n The minimum number of attributes that the array must |
ohair@286 | 578 | * be able to hold. |
ohair@286 | 579 | */ |
ohair@286 | 580 | private void ensureCapacity (int n) |
ohair@286 | 581 | { |
ohair@286 | 582 | if (n > 0 && (data == null || data.length==0)) { |
ohair@286 | 583 | data = new String[25]; |
ohair@286 | 584 | } |
ohair@286 | 585 | |
ohair@286 | 586 | int max = data.length; |
ohair@286 | 587 | if (max >= n * 5) { |
ohair@286 | 588 | return; |
ohair@286 | 589 | } |
ohair@286 | 590 | |
ohair@286 | 591 | |
ohair@286 | 592 | while (max < n * 5) { |
ohair@286 | 593 | max *= 2; |
ohair@286 | 594 | } |
ohair@286 | 595 | String newData[] = new String[max]; |
ohair@286 | 596 | System.arraycopy(data, 0, newData, 0, length*5); |
ohair@286 | 597 | data = newData; |
ohair@286 | 598 | } |
ohair@286 | 599 | |
ohair@286 | 600 | |
ohair@286 | 601 | /** |
ohair@286 | 602 | * Report a bad array index in a manipulator. |
ohair@286 | 603 | * |
ohair@286 | 604 | * @param index The index to report. |
ohair@286 | 605 | * @exception java.lang.ArrayIndexOutOfBoundsException Always. |
ohair@286 | 606 | */ |
ohair@286 | 607 | private void badIndex (int index) |
ohair@286 | 608 | throws ArrayIndexOutOfBoundsException |
ohair@286 | 609 | { |
ohair@286 | 610 | String msg = |
ohair@286 | 611 | "Attempt to modify attribute at illegal index: " + index; |
ohair@286 | 612 | throw new ArrayIndexOutOfBoundsException(msg); |
ohair@286 | 613 | } |
ohair@286 | 614 | |
ohair@286 | 615 | |
ohair@286 | 616 | |
ohair@286 | 617 | //////////////////////////////////////////////////////////////////// |
ohair@286 | 618 | // Internal state. |
ohair@286 | 619 | //////////////////////////////////////////////////////////////////// |
ohair@286 | 620 | |
ohair@286 | 621 | int length; |
ohair@286 | 622 | String data []; |
ohair@286 | 623 | |
ohair@286 | 624 | } |
ohair@286 | 625 | |
ohair@286 | 626 | // end of AttributesImpl.java |