1. /*
  2. * @(#)NVListImpl.java 1.28 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * Licensed Materials - Property of IBM
  9. * RMI-IIOP v1.0
  10. * Copyright IBM Corp. 1998 1999 All Rights Reserved
  11. *
  12. * US Government Users Restricted Rights - Use, duplication or
  13. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  14. */
  15. package com.sun.corba.se.internal.corba;
  16. import java.util.Vector;
  17. import org.omg.CORBA.Any;
  18. import org.omg.CORBA.Bounds;
  19. import org.omg.CORBA.NVList;
  20. import org.omg.CORBA.NamedValue;
  21. import org.omg.CORBA.ORB;
  22. public class NVListImpl extends NVList
  23. {
  24. private final int INITIAL_CAPACITY = 4;
  25. private final int CAPACITY_INCREMENT = 2;
  26. private Vector _namedValues;
  27. private org.omg.CORBA.ORB orb;
  28. NVListImpl(org.omg.CORBA.ORB orb)
  29. {
  30. // Note: This orb could be an instanceof ORBSingleton or ORB
  31. this.orb = orb;
  32. _namedValues = new Vector(INITIAL_CAPACITY, CAPACITY_INCREMENT);
  33. }
  34. NVListImpl(org.omg.CORBA.ORB orb, int size)
  35. {
  36. this.orb = orb;
  37. // Note: the size arg is only a hint of the size of the NVList.
  38. _namedValues = new Vector(size);
  39. }
  40. public int count()
  41. {
  42. return _namedValues.size();
  43. }
  44. public NamedValue add(int flags)
  45. {
  46. NamedValue tmpVal = new NamedValueImpl(orb, "", new AnyImpl(orb), flags);
  47. _namedValues.addElement(tmpVal);
  48. return tmpVal;
  49. }
  50. public NamedValue add_item(String itemName, int flags)
  51. {
  52. NamedValue tmpVal = new NamedValueImpl(orb, itemName, new AnyImpl(orb),
  53. flags);
  54. _namedValues.addElement(tmpVal);
  55. return tmpVal;
  56. }
  57. public NamedValue add_value(String itemName, Any val, int flags)
  58. {
  59. NamedValue tmpVal = new NamedValueImpl(orb, itemName, val, flags);
  60. _namedValues.addElement(tmpVal);
  61. return tmpVal;
  62. }
  63. public NamedValue item(int index)
  64. throws Bounds
  65. {
  66. try {
  67. return (NamedValue) _namedValues.elementAt(index);
  68. } catch (ArrayIndexOutOfBoundsException e) {
  69. throw new Bounds();
  70. }
  71. }
  72. public void remove(int index)
  73. throws Bounds
  74. {
  75. try {
  76. _namedValues.removeElementAt(index);
  77. } catch (ArrayIndexOutOfBoundsException e) {
  78. throw new Bounds();
  79. }
  80. }
  81. }