1. /*
  2. * @(#)BindingIteratorImpl.java 1.39 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.ORB;
  10. import org.omg.CORBA.Object;
  11. // Import org.omg.CosNaming classes
  12. import org.omg.CosNaming.Binding;
  13. import org.omg.CosNaming.BindingType;
  14. import org.omg.CosNaming.BindingHolder;
  15. import org.omg.CosNaming.BindingListHolder;
  16. import org.omg.CosNaming.BindingIteratorHolder;
  17. import org.omg.CosNaming.BindingIteratorPOA;
  18. import org.omg.CORBA.BAD_PARAM;
  19. /**
  20. * Class BindingIteratorImpl implements the org.omg.CosNaming::BindingIterator
  21. * interface, but does not implement the method to retrieve the next
  22. * binding in the NamingContext for which it was created. This is left
  23. * to a subclass, which is why this class is abstract; BindingIteratorImpl
  24. * provides an implementation of the interface operations on top of two
  25. * subclass methods, allowing multiple implementations of iterators that
  26. * differ in storage and access to the contents of a NamingContext
  27. * implementation.
  28. * <p>
  29. * The operation next_one() is implemented by the subclass, whereas
  30. * next_n() is implemented on top of the next_one() implementation.
  31. * Destroy must also be implemented by the subclass.
  32. * <p>
  33. * A subclass must implement NextOne() and Destroy(); these
  34. * methods are invoked from synchronized methods and need therefore
  35. * not be synchronized themselves.
  36. */
  37. public abstract class BindingIteratorImpl extends BindingIteratorPOA
  38. {
  39. /**
  40. * Create a binding iterator servant.
  41. * runs the super constructor.
  42. * @param orb an ORB object.
  43. * @exception java.lang.Exception a Java exception.
  44. */
  45. public BindingIteratorImpl(org.omg.CORBA.ORB orb)
  46. throws java.lang.Exception
  47. {
  48. super();
  49. }
  50. /**
  51. * Return the next binding. It also returns true or false, indicating
  52. * whether there were more bindings.
  53. * @param b The Binding as an out parameter.
  54. * @return true if there were more bindings.
  55. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
  56. * system exceptions.
  57. * @see NextOne
  58. */
  59. public synchronized boolean next_one(org.omg.CosNaming.BindingHolder b)
  60. {
  61. // NextOne actually returns the next one
  62. return NextOne(b);
  63. }
  64. /**
  65. * Return the next n bindings. It also returns true or false, indicating
  66. * whether there were more bindings.
  67. * @param how_many The number of requested bindings in the BindingList.
  68. * @param bl The BindingList as an out parameter.
  69. * @return true if there were more bindings.
  70. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
  71. * system exceptions.
  72. * @see NextOne
  73. */
  74. public synchronized boolean next_n(int how_many,
  75. org.omg.CosNaming.BindingListHolder blh)
  76. {
  77. if( how_many == 0 ) {
  78. throw new BAD_PARAM( " 'how_many' parameter is set to 0 which is" +
  79. " invalid" );
  80. }
  81. return list( how_many, blh );
  82. }
  83. /**
  84. * lists next n bindings. It returns true or false, indicating
  85. * whether there were more bindings. This method has the package private
  86. * scope, It will be called from NamingContext.list() operation or
  87. * this.next_n().
  88. * @param how_many The number of requested bindings in the BindingList.
  89. * @param bl The BindingList as an out parameter.
  90. * @return true if there were more bindings.
  91. */
  92. public boolean list( int how_many, org.omg.CosNaming.BindingListHolder blh)
  93. {
  94. // Take the smallest of what's left and what's being asked for
  95. int numberToGet = Math.min(RemainingElements(),how_many);
  96. // Create a resulting BindingList
  97. Binding[] bl = new Binding[numberToGet];
  98. BindingHolder bh = new BindingHolder();
  99. int i = 0;
  100. // Keep iterating as long as there are entries
  101. while (i < numberToGet && this.NextOne(bh) == true) {
  102. bl[i] = bh.value;
  103. i++;
  104. }
  105. // Found any at all?
  106. if (i == 0) {
  107. // No
  108. blh.value = new Binding[0];
  109. return false;
  110. }
  111. // Set into holder
  112. blh.value = bl;
  113. return true;
  114. }
  115. /**
  116. * Destroy this BindingIterator object. The object corresponding to this
  117. * object reference is destroyed.
  118. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
  119. * system exceptions.
  120. * @see Destroy
  121. */
  122. public synchronized void destroy()
  123. {
  124. // Destroy actually destroys
  125. this.Destroy();
  126. }
  127. /**
  128. * Abstract method for returning the next binding in the NamingContext
  129. * for which this BindingIterator was created.
  130. * @param b The Binding as an out parameter.
  131. * @return true if there were more bindings.
  132. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
  133. * system exceptions.
  134. */
  135. protected abstract boolean NextOne(org.omg.CosNaming.BindingHolder b);
  136. /**
  137. * Abstract method for destroying this BindingIterator.
  138. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
  139. * system exceptions.
  140. */
  141. protected abstract void Destroy();
  142. /**
  143. * Abstract method for returning the remaining number of elements.
  144. * @return the remaining number of elements in the iterator.
  145. */
  146. protected abstract int RemainingElements();
  147. }