jdk/src/java.naming/share/classes/javax/naming/NamingEnumeration.java
author lana
Thu, 31 Mar 2016 01:13:19 -0700
changeset 36728 9bc1d0332a48
parent 32029 a5538163e144
permissions -rw-r--r--
Added tag jdk-9+112 for changeset 5531985950c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.naming;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  * This interface is for enumerating lists returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  * methods in the javax.naming and javax.naming.directory packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  * It extends Enumeration to allow as exceptions to be thrown during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  * the enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  * When a method such as list(), listBindings(), or search() returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  * a NamingEnumeration, any exceptions encountered are reserved until
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  * all results have been returned. At the end of the enumeration, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  * exception is thrown (by hasMore());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  * For example, if the list() is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  * returning only a partial answer, the corresponding exception would
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  * be PartialResultException. list() would first return a NamingEnumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  * When the last of the results has been returned by the NamingEnumeration's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  * next(), invoking hasMore() would result in PartialResultException being thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  * In another example, if a search() method was invoked with a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  * size limit of 'n'. If the answer consists of more than 'n' results,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  * search() would first return a NamingEnumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  * When the n'th result has been returned by invoking next() on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  * NamingEnumeration, a SizeLimitExceedException would then thrown when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  * hasMore() is invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  * Note that if the program uses hasMoreElements() and nextElement() instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  * to iterate through the NamingEnumeration, because these methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  * cannot throw exceptions, no exception will be thrown. Instead,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  * in the previous example, after the n'th result has been returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  * nextElement(), invoking hasMoreElements() would return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  * Note also that NoSuchElementException is thrown if the program invokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  * next() or nextElement() when there are no elements left in the enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  * The program can always avoid this exception by using hasMore() and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  * hasMoreElements() to check whether the end of the enumeration has been reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  * If an exception is thrown during an enumeration,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  * the enumeration becomes invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  * Subsequent invocation of any method on that enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  * will yield undefined results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  * @see Context#list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  * @see Context#listBindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  * @see javax.naming.directory.DirContext#search
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  * @see javax.naming.directory.Attributes#getAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  * @see javax.naming.directory.Attributes#getIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  * @see javax.naming.directory.Attribute#getAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
public interface NamingEnumeration<T> extends Enumeration<T> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
      * Retrieves the next element in the enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
      * This method allows naming exceptions encountered while
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
      * retrieving the next element to be caught and handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
      * by the application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
      * <p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    88
      * Note that {@code next()} can also throw the runtime exception
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      * NoSuchElementException to indicate that the caller is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      * attempting to enumerate beyond the end of the enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      * This is different from a NamingException, which indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
      * that there was a problem in obtaining the next element,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      * for example, due to a referral or server unavailability, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
      * @return         The possibly null element in the enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
      *     null is only valid for enumerations that can return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
      *     null (e.g. Attribute.getAll() returns an enumeration of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
      *     attribute values, and an attribute value can be null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      * @exception NamingException If a naming exception is encountered while attempting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
      *                 to retrieve the next element. See NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
      *                 and its subclasses for the possible naming exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
      * @exception java.util.NoSuchElementException If attempting to get the next element when none is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
      * @see java.util.Enumeration#nextElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public T next() throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      * Determines whether there are any more elements in the enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
      * This method allows naming exceptions encountered while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
      * determining whether there are more elements to be caught and handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      * by the application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      * @return         true if there is more in the enumeration ; false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      * @exception NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      *                 If a naming exception is encountered while attempting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
      *                 to determine whether there is another element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      *                 in the enumeration. See NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      *                 and its subclasses for the possible naming exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
      * @see java.util.Enumeration#hasMoreElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public boolean hasMore() throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Closes this enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * After this method has been invoked on this enumeration, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * enumeration becomes invalid and subsequent invocation of any of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * its methods will yield undefined results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * This method is intended for aborting an enumeration to free up resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * If an enumeration proceeds to the end--that is, until
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   131
     * {@code hasMoreElements()} or {@code hasMore()} returns {@code false}--
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * resources will be freed up automatically and there is no need to
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   133
     * explicitly call {@code close()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * This method indicates to the service provider that it is free
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * to release resources associated with the enumeration, and can
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   137
     * notify servers to cancel any outstanding requests. The {@code close()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * method is a hint to implementations for managing their resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Implementations are encouraged to use appropriate algorithms to
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   140
     * manage their resources when client omits the {@code close()} calls.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @exception NamingException If a naming exception is encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * while closing the enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public void close() throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}