1. /*
  2. * @(#)TransientBindingIterator.java 1.43 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. package com.sun.corba.se.internal.CosNaming;
  8. // Import general CORBA classes
  9. import org.omg.CORBA.SystemException;
  10. import org.omg.CORBA.ORB;
  11. import org.omg.PortableServer.POA;
  12. // Get org.omg.CosNaming Types
  13. import org.omg.CosNaming.Binding;
  14. import org.omg.CosNaming.BindingType;
  15. import org.omg.CosNaming.BindingTypeHolder;
  16. import org.omg.CosNaming.NameComponent;
  17. // Get base implementation
  18. import com.sun.corba.se.internal.CosNaming.NamingContextImpl;
  19. import com.sun.corba.se.internal.CosNaming.InternalBindingValue;
  20. // Get a hash table
  21. import java.util.Hashtable;
  22. import java.util.Enumeration;
  23. /**
  24. * Class TransientBindingIterator implements the abstract methods
  25. * defined by BindingIteratorImpl, to use with the TransientNamingContext
  26. * implementation of the NamingContextImpl. The TransientBindingIterator
  27. * implementation receives a hash table of InternalBindingValues, and uses
  28. * an Enumeration to iterate over the contents of the hash table.
  29. * @see BindingIteratorImpl
  30. * @see TransientNamingContext
  31. */
  32. public class TransientBindingIterator extends BindingIteratorImpl
  33. {
  34. // There is only one POA used for both TransientNamingContext and
  35. // TransientBindingIteraor servants.
  36. private POA nsPOA;
  37. /**
  38. * Constructs a new TransientBindingIterator object.
  39. * @param orb a org.omg.CORBA.ORB object.
  40. * @param aTable A hashtable containing InternalBindingValues which is
  41. * the content of the TransientNamingContext.
  42. * @param java.lang.Exception a Java exception.
  43. * @exception Exception a Java exception thrown of the base class cannot
  44. * initialize.
  45. */
  46. public TransientBindingIterator(org.omg.CORBA.ORB orb, Hashtable aTable,
  47. POA thePOA )
  48. throws java.lang.Exception
  49. {
  50. super(orb);
  51. this.orb = orb;
  52. theHashtable = aTable;
  53. theEnumeration = this.theHashtable.elements();
  54. currentSize = this.theHashtable.size();
  55. this.nsPOA = thePOA;
  56. }
  57. /**
  58. * Returns the next binding in the NamingContext. Uses the enumeration
  59. * object to determine if there are more bindings and if so, returns
  60. * the next binding from the InternalBindingValue.
  61. * @param b The Binding as an out parameter.
  62. * @return true if there were more bindings.
  63. */
  64. final public boolean NextOne(org.omg.CosNaming.BindingHolder b)
  65. {
  66. // If there are more elements get the next element
  67. boolean hasMore = theEnumeration.hasMoreElements();
  68. if (hasMore) {
  69. b.value =
  70. ((InternalBindingValue)theEnumeration.nextElement()).theBinding;
  71. currentSize--;
  72. } else {
  73. // Return empty but marshalable binding
  74. b.value = new Binding(new NameComponent[0],BindingType.nobject);
  75. }
  76. return hasMore;
  77. }
  78. /**
  79. * Destroys this BindingIterator by disconnecting from the ORB
  80. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
  81. * system exceptions.
  82. */
  83. final public void Destroy()
  84. {
  85. // Remove the object from the Active Object Map.
  86. try {
  87. byte[] objectId = nsPOA.servant_to_id( this );
  88. if( objectId != null ) {
  89. nsPOA.deactivate_object( objectId );
  90. }
  91. }
  92. catch( Exception e ) {
  93. NamingUtils.errprint("BindingIterator.Destroy():caught exception:");
  94. NamingUtils.printException(e);
  95. }
  96. }
  97. /**
  98. * Returns the remaining number of elements in the iterator.
  99. * @return the remaining number of elements in the iterator.
  100. */
  101. public final int RemainingElements() {
  102. return currentSize;
  103. }
  104. private int currentSize;
  105. private Hashtable theHashtable;
  106. private Enumeration theEnumeration;
  107. private org.omg.CORBA.ORB orb;
  108. }