1. /*
  2. * @(#)TransientBindingIterator.java 1.45 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.naming.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.impl.naming.cosnaming.NamingContextImpl;
  19. import com.sun.corba.se.impl.naming.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(ORB orb, Hashtable aTable,
  47. POA thePOA )
  48. throws java.lang.Exception
  49. {
  50. super(orb);
  51. theHashtable = aTable;
  52. theEnumeration = this.theHashtable.elements();
  53. currentSize = this.theHashtable.size();
  54. this.nsPOA = thePOA;
  55. }
  56. /**
  57. * Returns the next binding in the NamingContext. Uses the enumeration
  58. * object to determine if there are more bindings and if so, returns
  59. * the next binding from the InternalBindingValue.
  60. * @param b The Binding as an out parameter.
  61. * @return true if there were more bindings.
  62. */
  63. final public boolean NextOne(org.omg.CosNaming.BindingHolder b)
  64. {
  65. // If there are more elements get the next element
  66. boolean hasMore = theEnumeration.hasMoreElements();
  67. if (hasMore) {
  68. b.value =
  69. ((InternalBindingValue)theEnumeration.nextElement()).theBinding;
  70. currentSize--;
  71. } else {
  72. // Return empty but marshalable binding
  73. b.value = new Binding(new NameComponent[0],BindingType.nobject);
  74. }
  75. return hasMore;
  76. }
  77. /**
  78. * Destroys this BindingIterator by disconnecting from the ORB
  79. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
  80. * system exceptions.
  81. */
  82. final public void Destroy()
  83. {
  84. // Remove the object from the Active Object Map.
  85. try {
  86. byte[] objectId = nsPOA.servant_to_id( this );
  87. if( objectId != null ) {
  88. nsPOA.deactivate_object( objectId );
  89. }
  90. }
  91. catch( Exception e ) {
  92. NamingUtils.errprint("BindingIterator.Destroy():caught exception:");
  93. NamingUtils.printException(e);
  94. }
  95. }
  96. /**
  97. * Returns the remaining number of elements in the iterator.
  98. * @return the remaining number of elements in the iterator.
  99. */
  100. public final int RemainingElements() {
  101. return currentSize;
  102. }
  103. private int currentSize;
  104. private Hashtable theHashtable;
  105. private Enumeration theEnumeration;
  106. }