src/share/jaxws_classes/com/sun/tools/internal/jxc/gen/config/AttributesImpl.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 397
b99d7e355d4b
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

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

mercurial