1 /*
2 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
400 }
401
402
403 /**
404 * Set an attribute in the list.
405 *
406 * <p>For the sake of speed, this method does no checking
407 * for name conflicts or well-formedness: such checks are the
408 * responsibility of the application.</p>
409 *
410 * @param index The index of the attribute (zero-based).
411 * @param uri The Namespace URI, or the empty string if
412 * none is available or Namespace processing is not
413 * being performed.
414 * @param localName The local name, or the empty string if
415 * Namespace processing is not being performed.
416 * @param qName The qualified name, or the empty string
417 * if qualified names are not available.
418 * @param type The attribute type as a string.
419 * @param value The attribute value.
420 * @exception java.lang.ArrayIndexOutOfBoundsException When the
421 * supplied index does not point to an attribute
422 * in the list.
423 */
424 public void setAttribute (int index, String uri, String localName,
425 String qName, String type, String value)
426 {
427 if (index >= 0 && index < length) {
428 data[index*5] = uri;
429 data[index*5+1] = localName;
430 data[index*5+2] = qName;
431 data[index*5+3] = type;
432 data[index*5+4] = value;
433 } else {
434 badIndex(index);
435 }
436 }
437
438
439 /**
440 * Remove an attribute from the list.
441 *
442 * @param index The index of the attribute (zero-based).
443 * @exception java.lang.ArrayIndexOutOfBoundsException When the
444 * supplied index does not point to an attribute
445 * in the list.
446 */
447 public void removeAttribute (int index)
448 {
449 if (index >= 0 && index < length) {
450 if (index < length - 1) {
451 System.arraycopy(data, (index+1)*5, data, index*5,
452 (length-index-1)*5);
453 }
454 index = (length - 1) * 5;
455 data [index++] = null;
456 data [index++] = null;
457 data [index++] = null;
458 data [index++] = null;
459 data [index] = null;
460 length--;
461 } else {
462 badIndex(index);
463 }
464 }
465
466
467 /**
468 * Set the Namespace URI of a specific attribute.
469 *
470 * @param index The index of the attribute (zero-based).
471 * @param uri The attribute's Namespace URI, or the empty
472 * string for none.
473 * @exception java.lang.ArrayIndexOutOfBoundsException When the
474 * supplied index does not point to an attribute
475 * in the list.
476 */
477 public void setURI (int index, String uri)
478 {
479 if (index >= 0 && index < length) {
480 data[index*5] = uri;
481 } else {
482 badIndex(index);
483 }
484 }
485
486
487 /**
488 * Set the local name of a specific attribute.
489 *
490 * @param index The index of the attribute (zero-based).
491 * @param localName The attribute's local name, or the empty
492 * string for none.
493 * @exception java.lang.ArrayIndexOutOfBoundsException When the
494 * supplied index does not point to an attribute
495 * in the list.
496 */
497 public void setLocalName (int index, String localName)
498 {
499 if (index >= 0 && index < length) {
500 data[index*5+1] = localName;
501 } else {
502 badIndex(index);
503 }
504 }
505
506
507 /**
508 * Set the qualified name of a specific attribute.
509 *
510 * @param index The index of the attribute (zero-based).
511 * @param qName The attribute's qualified name, or the empty
512 * string for none.
513 * @exception java.lang.ArrayIndexOutOfBoundsException When the
514 * supplied index does not point to an attribute
515 * in the list.
516 */
517 public void setQName (int index, String qName)
518 {
519 if (index >= 0 && index < length) {
520 data[index*5+2] = qName;
521 } else {
522 badIndex(index);
523 }
524 }
525
526
527 /**
528 * Set the type of a specific attribute.
529 *
530 * @param index The index of the attribute (zero-based).
531 * @param type The attribute's type.
532 * @exception java.lang.ArrayIndexOutOfBoundsException When the
533 * supplied index does not point to an attribute
534 * in the list.
535 */
536 public void setType (int index, String type)
537 {
538 if (index >= 0 && index < length) {
539 data[index*5+3] = type;
540 } else {
541 badIndex(index);
542 }
543 }
544
545
546 /**
547 * Set the value of a specific attribute.
548 *
549 * @param index The index of the attribute (zero-based).
550 * @param value The attribute's value.
551 * @exception java.lang.ArrayIndexOutOfBoundsException When the
552 * supplied index does not point to an attribute
553 * in the list.
554 */
555 public void setValue (int index, String value)
556 {
557 if (index >= 0 && index < length) {
558 data[index*5+4] = value;
559 } else {
560 badIndex(index);
561 }
562 }
563
564
565
566 ////////////////////////////////////////////////////////////////////
567 // Internal methods.
568 ////////////////////////////////////////////////////////////////////
569
570
571 /**
587 }
588 else {
589 max = data.length;
590 }
591 while (max < n * 5) {
592 max *= 2;
593 }
594
595 String newData[] = new String[max];
596 if (length > 0) {
597 System.arraycopy(data, 0, newData, 0, length*5);
598 }
599 data = newData;
600 }
601
602
603 /**
604 * Report a bad array index in a manipulator.
605 *
606 * @param index The index to report.
607 * @exception java.lang.ArrayIndexOutOfBoundsException Always.
608 */
609 private void badIndex (int index)
610 throws ArrayIndexOutOfBoundsException
611 {
612 String msg =
613 "Attempt to modify attribute at illegal index: " + index;
614 throw new ArrayIndexOutOfBoundsException(msg);
615 }
616
617
618
619 ////////////////////////////////////////////////////////////////////
620 // Internal state.
621 ////////////////////////////////////////////////////////////////////
622
623 int length;
624 String data [];
625
626 }
627
|
1 /*
2 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
400 }
401
402
403 /**
404 * Set an attribute in the list.
405 *
406 * <p>For the sake of speed, this method does no checking
407 * for name conflicts or well-formedness: such checks are the
408 * responsibility of the application.</p>
409 *
410 * @param index The index of the attribute (zero-based).
411 * @param uri The Namespace URI, or the empty string if
412 * none is available or Namespace processing is not
413 * being performed.
414 * @param localName The local name, or the empty string if
415 * Namespace processing is not being performed.
416 * @param qName The qualified name, or the empty string
417 * if qualified names are not available.
418 * @param type The attribute type as a string.
419 * @param value The attribute value.
420 * @throws java.lang.ArrayIndexOutOfBoundsException When the
421 * supplied index does not point to an attribute
422 * in the list.
423 */
424 public void setAttribute (int index, String uri, String localName,
425 String qName, String type, String value)
426 {
427 if (index >= 0 && index < length) {
428 data[index*5] = uri;
429 data[index*5+1] = localName;
430 data[index*5+2] = qName;
431 data[index*5+3] = type;
432 data[index*5+4] = value;
433 } else {
434 badIndex(index);
435 }
436 }
437
438
439 /**
440 * Remove an attribute from the list.
441 *
442 * @param index The index of the attribute (zero-based).
443 * @throws java.lang.ArrayIndexOutOfBoundsException When the
444 * supplied index does not point to an attribute
445 * in the list.
446 */
447 public void removeAttribute (int index)
448 {
449 if (index >= 0 && index < length) {
450 if (index < length - 1) {
451 System.arraycopy(data, (index+1)*5, data, index*5,
452 (length-index-1)*5);
453 }
454 index = (length - 1) * 5;
455 data [index++] = null;
456 data [index++] = null;
457 data [index++] = null;
458 data [index++] = null;
459 data [index] = null;
460 length--;
461 } else {
462 badIndex(index);
463 }
464 }
465
466
467 /**
468 * Set the Namespace URI of a specific attribute.
469 *
470 * @param index The index of the attribute (zero-based).
471 * @param uri The attribute's Namespace URI, or the empty
472 * string for none.
473 * @throws java.lang.ArrayIndexOutOfBoundsException When the
474 * supplied index does not point to an attribute
475 * in the list.
476 */
477 public void setURI (int index, String uri)
478 {
479 if (index >= 0 && index < length) {
480 data[index*5] = uri;
481 } else {
482 badIndex(index);
483 }
484 }
485
486
487 /**
488 * Set the local name of a specific attribute.
489 *
490 * @param index The index of the attribute (zero-based).
491 * @param localName The attribute's local name, or the empty
492 * string for none.
493 * @throws java.lang.ArrayIndexOutOfBoundsException When the
494 * supplied index does not point to an attribute
495 * in the list.
496 */
497 public void setLocalName (int index, String localName)
498 {
499 if (index >= 0 && index < length) {
500 data[index*5+1] = localName;
501 } else {
502 badIndex(index);
503 }
504 }
505
506
507 /**
508 * Set the qualified name of a specific attribute.
509 *
510 * @param index The index of the attribute (zero-based).
511 * @param qName The attribute's qualified name, or the empty
512 * string for none.
513 * @throws java.lang.ArrayIndexOutOfBoundsException When the
514 * supplied index does not point to an attribute
515 * in the list.
516 */
517 public void setQName (int index, String qName)
518 {
519 if (index >= 0 && index < length) {
520 data[index*5+2] = qName;
521 } else {
522 badIndex(index);
523 }
524 }
525
526
527 /**
528 * Set the type of a specific attribute.
529 *
530 * @param index The index of the attribute (zero-based).
531 * @param type The attribute's type.
532 * @throws java.lang.ArrayIndexOutOfBoundsException When the
533 * supplied index does not point to an attribute
534 * in the list.
535 */
536 public void setType (int index, String type)
537 {
538 if (index >= 0 && index < length) {
539 data[index*5+3] = type;
540 } else {
541 badIndex(index);
542 }
543 }
544
545
546 /**
547 * Set the value of a specific attribute.
548 *
549 * @param index The index of the attribute (zero-based).
550 * @param value The attribute's value.
551 * @throws java.lang.ArrayIndexOutOfBoundsException When the
552 * supplied index does not point to an attribute
553 * in the list.
554 */
555 public void setValue (int index, String value)
556 {
557 if (index >= 0 && index < length) {
558 data[index*5+4] = value;
559 } else {
560 badIndex(index);
561 }
562 }
563
564
565
566 ////////////////////////////////////////////////////////////////////
567 // Internal methods.
568 ////////////////////////////////////////////////////////////////////
569
570
571 /**
587 }
588 else {
589 max = data.length;
590 }
591 while (max < n * 5) {
592 max *= 2;
593 }
594
595 String newData[] = new String[max];
596 if (length > 0) {
597 System.arraycopy(data, 0, newData, 0, length*5);
598 }
599 data = newData;
600 }
601
602
603 /**
604 * Report a bad array index in a manipulator.
605 *
606 * @param index The index to report.
607 * @throws java.lang.ArrayIndexOutOfBoundsException Always.
608 */
609 private void badIndex (int index)
610 throws ArrayIndexOutOfBoundsException
611 {
612 String msg =
613 "Attempt to modify attribute at illegal index: " + index;
614 throw new ArrayIndexOutOfBoundsException(msg);
615 }
616
617
618
619 ////////////////////////////////////////////////////////////////////
620 // Internal state.
621 ////////////////////////////////////////////////////////////////////
622
623 int length;
624 String data [];
625
626 }
627
|