1. /*
  2. * @(#)NamingEnumeration.java 1.6 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 javax.naming;
  8. import java.util.Enumeration;
  9. /**
  10. * This interface is for enumerating lists returned by
  11. * methods in the javax.naming and javax.naming.directory packages.
  12. * It extends Enumeration to allow as exceptions to be thrown during
  13. * the enumeration.
  14. *<p>
  15. * When a method such as list(), listBindings(), or search() returns
  16. * a NamingEnumeration, any exceptions encountered are reserved until
  17. * all results have been returned. At the end of the enumeration, the
  18. * exception is thrown (by hasMore());
  19. * <p>
  20. * For example, if the list() is
  21. * returning only a partial answer, the corresponding exception would
  22. * be PartialResultException. list() would first return a NamingEnumeration.
  23. * When the last of the results has been returned by the NamingEnumeration's
  24. * next(), invoking hasMore() would result in PartialResultException being thrown.
  25. *<p>
  26. * In another example, if a search() method was invoked with a specified
  27. * size limit of 'n'. If the answer consists of more than 'n' results,
  28. * search() would first return a NamingEnumeration.
  29. * When the n'th result has been returned by invoking next() on the
  30. * NamingEnumeration, a SizeLimitExceedException would then thrown when
  31. * hasMore() is invoked.
  32. *<p>
  33. * Note that if the program uses hasMoreElements() and nextElement() instead
  34. * to iterate through the NamingEnumeration, because these methods
  35. * cannot throw exceptions, no exception will be thrown. Instead,
  36. * in the previous example, after the n'th result has been returned by
  37. * nextElement(), invoking hasMoreElements() would return false.
  38. *<p>
  39. * Note also that NoSuchElementException is thrown if the program invokes
  40. * next() or nextElement() when there are no elements left in the enumeration.
  41. * The program can always avoid this exception by using hasMore() and
  42. * hasMoreElements() to check whether the end of the enumeration has been reached.
  43. *<p>
  44. * If an exception is thrown during an enumeration,
  45. * the enumeration becomes invalid.
  46. * Subsequent invocation of any method on that enumeration
  47. * will yield undefined results.
  48. *
  49. * @author Rosanna Lee
  50. * @author Scott Seligman
  51. * @version 1.6 03/01/23
  52. *
  53. * @see Context#list
  54. * @see Context#listBindings
  55. * @see javax.naming.directory.DirContext#search
  56. * @see javax.naming.directory.Attributes#getAll
  57. * @see javax.naming.directory.Attributes#getIDs
  58. * @see javax.naming.directory.Attribute#getAll
  59. * @since 1.3
  60. */
  61. public interface NamingEnumeration extends Enumeration {
  62. /**
  63. * Retrieves the next element in the enumeration.
  64. * This method allows naming exceptions encountered while
  65. * retrieving the next element to be caught and handled
  66. * by the application.
  67. * <p>
  68. * Note that <tt>next()</tt> can also throw the runtime exception
  69. * NoSuchElementException to indicate that the caller is
  70. * attempting to enumerate beyond the end of the enumeration.
  71. * This is different from a NamingException, which indicates
  72. * that there was a problem in obtaining the next element,
  73. * for example, due to a referral or server unavailability, etc.
  74. *
  75. * @return The possibly null element in the enumeration.
  76. * null is only valid for enumerations that can return
  77. * null (e.g. Attribute.getAll() returns an enumeration of
  78. * attribute values, and an attribute value can be null).
  79. * @exception NamingException If a naming exception is encountered while attempting
  80. * to retrieve the next element. See NamingException
  81. * and its subclasses for the possible naming exceptions.
  82. * @exception java.util.NoSuchElementException If attempting to get the next element when none is available.
  83. * @see java.util.Enumeration#nextElement
  84. */
  85. public Object next() throws NamingException;
  86. /**
  87. * Determines whether there are any more elements in the enumeration.
  88. * This method allows naming exceptions encountered while
  89. * determining whether there are more elements to be caught and handled
  90. * by the application.
  91. *
  92. * @return true if there is more in the enumeration ; false otherwise.
  93. * @exception NamingException
  94. * If a naming exception is encountered while attempting
  95. * to determine whether there is another element
  96. * in the enumeration. See NamingException
  97. * and its subclasses for the possible naming exceptions.
  98. * @see java.util.Enumeration#hasMoreElements
  99. */
  100. public boolean hasMore() throws NamingException;
  101. /**
  102. * Closes this enumeration.
  103. *
  104. * After this method has been invoked on this enumeration, the
  105. * enumeration becomes invalid and subsequent invocation of any of
  106. * its methods will yield undefined results.
  107. * This method is intended for aborting an enumeration to free up resources.
  108. * If an enumeration proceeds to the end--that is, until
  109. * <tt>hasMoreElements()</tt> or <tt>hasMore()</tt> returns <tt>false</tt>--
  110. * resources will be freed up automatically and there is no need to
  111. * explicitly call <tt>close()</tt>.
  112. *<p>
  113. * This method indicates to the service provider that it is free
  114. * to release resources associated with the enumeration, and can
  115. * notify servers to cancel any outstanding requests. The <tt>close()</tt>
  116. * method is a hint to implementations for managing their resources.
  117. * Implementations are encouraged to use appropriate algorithms to
  118. * manage their resources when client omits the <tt>close()</tt> calls.
  119. *
  120. * @exception NamingException If a naming exception is encountered
  121. * while closing the enumeration.
  122. * @since 1.3
  123. */
  124. public void close() throws NamingException;
  125. }