1. /*
  2. * @(#)PersistentBindingIterator.java 1.10 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. /*
  8. * @(#)TransientBindingIterator.java 1.36 99/07/16
  9. *
  10. * Copyright 1993-1997 Sun Microsystems, Inc. 901 San Antonio Road,
  11. * Palo Alto, California, 94303, U.S.A. All Rights Reserved.
  12. *
  13. * This software is the confidential and proprietary information of Sun
  14. * Microsystems, Inc. ("Confidential Information"). You shall not
  15. * disclose such Confidential Information and shall use it only in
  16. * accordance with the terms of the license agreement you entered into
  17. * with Sun.
  18. *
  19. * CopyrightVersion 1.2
  20. *
  21. */
  22. package com.sun.corba.se.impl.naming.pcosnaming;
  23. // Import general CORBA classes
  24. import org.omg.CORBA.SystemException;
  25. import org.omg.CORBA.ORB;
  26. import org.omg.CORBA.INTERNAL;
  27. // Get org.omg.CosNaming Types
  28. import org.omg.CosNaming.Binding;
  29. import org.omg.CosNaming.BindingType;
  30. import org.omg.CosNaming.BindingTypeHolder;
  31. import org.omg.CosNaming.NameComponent;
  32. import org.omg.PortableServer.POA;
  33. // Get base implementation
  34. import com.sun.corba.se.impl.naming.pcosnaming.NamingContextImpl;
  35. import com.sun.corba.se.impl.naming.pcosnaming.InternalBindingValue;
  36. import com.sun.corba.se.impl.naming.cosnaming.BindingIteratorImpl;
  37. // Get a hash table
  38. import java.util.Hashtable;
  39. import java.util.Enumeration;
  40. /**
  41. * Class TransientBindingIterator implements the abstract methods
  42. * defined by BindingIteratorImpl, to use with the TransientNamingContext
  43. * implementation of the NamingContextImpl. The TransientBindingIterator
  44. * implementation receives a hash table of InternalBindingValues, and uses
  45. * an Enumeration to iterate over the contents of the hash table.
  46. * @see BindingIteratorImpl
  47. * @see TransientNamingContext
  48. */
  49. public class PersistentBindingIterator extends BindingIteratorImpl
  50. {
  51. private POA biPOA;
  52. /**
  53. * Constructs a new PersistentBindingIterator object.
  54. * @param orb a org.omg.CORBA.ORB object.
  55. * @param aTable A hashtable containing InternalBindingValues which is
  56. * the content of the PersistentNamingContext.
  57. * @param java.lang.Exception a Java exception.
  58. * @exception Exception a Java exception thrown of the base class cannot
  59. * initialize.
  60. */
  61. public PersistentBindingIterator(org.omg.CORBA.ORB orb, Hashtable aTable,
  62. POA thePOA ) throws java.lang.Exception
  63. {
  64. super(orb);
  65. this.orb = orb;
  66. theHashtable = aTable;
  67. theEnumeration = this.theHashtable.keys();
  68. currentSize = this.theHashtable.size();
  69. biPOA = thePOA;
  70. }
  71. /**
  72. * Returns the next binding in the NamingContext. Uses the enumeration
  73. * object to determine if there are more bindings and if so, returns
  74. * the next binding from the InternalBindingValue.
  75. * @param b The Binding as an out parameter.
  76. * @return true if there were more bindings.
  77. */
  78. final public boolean NextOne(org.omg.CosNaming.BindingHolder b)
  79. {
  80. // If there are more elements get the next element
  81. boolean hasMore = theEnumeration.hasMoreElements();
  82. if (hasMore) {
  83. InternalBindingKey theBindingKey =
  84. ((InternalBindingKey)theEnumeration.nextElement());
  85. InternalBindingValue theElement =
  86. (InternalBindingValue)theHashtable.get( theBindingKey );
  87. NameComponent n = new NameComponent( theBindingKey.id, theBindingKey.kind );
  88. NameComponent[] nlist = new NameComponent[1];
  89. nlist[0] = n;
  90. BindingType theType = theElement.theBindingType;
  91. b.value =
  92. new Binding( nlist, theType );
  93. } else {
  94. // Return empty but marshalable binding
  95. b.value = new Binding(new NameComponent[0],BindingType.nobject);
  96. }
  97. return hasMore;
  98. }
  99. /**
  100. * Destroys this BindingIterator by disconnecting from the ORB
  101. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  102. */
  103. final public void Destroy()
  104. {
  105. // Remove the object from the Active Object Map.
  106. try {
  107. byte[] objectId = biPOA.servant_to_id( this );
  108. if( objectId != null ) {
  109. biPOA.deactivate_object( objectId );
  110. }
  111. }
  112. catch( Exception e ) {
  113. throw new INTERNAL( "Exception in BindingIterator.Destroy " + e );
  114. }
  115. }
  116. /**
  117. * Returns the remaining number of elements in the iterator.
  118. * @return the remaining number of elements in the iterator.
  119. */
  120. public final int RemainingElements() {
  121. return currentSize;
  122. }
  123. private int currentSize;
  124. private Hashtable theHashtable;
  125. private Enumeration theEnumeration;
  126. private org.omg.CORBA.ORB orb;
  127. }