Path: blob/master/src/java.naming/share/classes/javax/naming/NamingEnumeration.java
41152 views
/*1* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming;2627import java.util.Enumeration;2829/**30* This interface is for enumerating lists returned by31* methods in the javax.naming and javax.naming.directory packages.32* It extends Enumeration to allow as exceptions to be thrown during33* the enumeration.34*<p>35* When a method such as list(), listBindings(), or search() returns36* a NamingEnumeration, any exceptions encountered are reserved until37* all results have been returned. At the end of the enumeration, the38* exception is thrown (by hasMore());39* <p>40* For example, if the list() is41* returning only a partial answer, the corresponding exception would42* be PartialResultException. list() would first return a NamingEnumeration.43* When the last of the results has been returned by the NamingEnumeration's44* next(), invoking hasMore() would result in PartialResultException being thrown.45*<p>46* In another example, if a search() method was invoked with a specified47* size limit of 'n'. If the answer consists of more than 'n' results,48* search() would first return a NamingEnumeration.49* When the n'th result has been returned by invoking next() on the50* NamingEnumeration, a SizeLimitExceedException would then thrown when51* hasMore() is invoked.52*<p>53* Note that if the program uses hasMoreElements() and nextElement() instead54* to iterate through the NamingEnumeration, because these methods55* cannot throw exceptions, no exception will be thrown. Instead,56* in the previous example, after the n'th result has been returned by57* nextElement(), invoking hasMoreElements() would return false.58*<p>59* Note also that NoSuchElementException is thrown if the program invokes60* next() or nextElement() when there are no elements left in the enumeration.61* The program can always avoid this exception by using hasMore() and62* hasMoreElements() to check whether the end of the enumeration has been reached.63*<p>64* If an exception is thrown during an enumeration,65* the enumeration becomes invalid.66* Subsequent invocation of any method on that enumeration67* will yield undefined results.68*69* @author Rosanna Lee70* @author Scott Seligman71*72* @see Context#list73* @see Context#listBindings74* @see javax.naming.directory.DirContext#search75* @see javax.naming.directory.Attributes#getAll76* @see javax.naming.directory.Attributes#getIDs77* @see javax.naming.directory.Attribute#getAll78* @since 1.379*/80public interface NamingEnumeration<T> extends Enumeration<T> {81/**82* Retrieves the next element in the enumeration.83* This method allows naming exceptions encountered while84* retrieving the next element to be caught and handled85* by the application.86* <p>87* Note that {@code next()} can also throw the runtime exception88* NoSuchElementException to indicate that the caller is89* attempting to enumerate beyond the end of the enumeration.90* This is different from a NamingException, which indicates91* that there was a problem in obtaining the next element,92* for example, due to a referral or server unavailability, etc.93*94* @return The possibly null element in the enumeration.95* null is only valid for enumerations that can return96* null (e.g. Attribute.getAll() returns an enumeration of97* attribute values, and an attribute value can be null).98* @throws NamingException If a naming exception is encountered while attempting99* to retrieve the next element. See NamingException100* and its subclasses for the possible naming exceptions.101* @throws java.util.NoSuchElementException If attempting to get the next element when none is available.102* @see java.util.Enumeration#nextElement103*/104public T next() throws NamingException;105106/**107* Determines whether there are any more elements in the enumeration.108* This method allows naming exceptions encountered while109* determining whether there are more elements to be caught and handled110* by the application.111*112* @return true if there is more in the enumeration ; false otherwise.113* @throws NamingException114* If a naming exception is encountered while attempting115* to determine whether there is another element116* in the enumeration. See NamingException117* and its subclasses for the possible naming exceptions.118* @see java.util.Enumeration#hasMoreElements119*/120public boolean hasMore() throws NamingException;121122/**123* Closes this enumeration.124*125* After this method has been invoked on this enumeration, the126* enumeration becomes invalid and subsequent invocation of any of127* its methods will yield undefined results.128* This method is intended for aborting an enumeration to free up resources.129* If an enumeration proceeds to the end--that is, until130* {@code hasMoreElements()} or {@code hasMore()} returns {@code false}--131* resources will be freed up automatically and there is no need to132* explicitly call {@code close()}.133*<p>134* This method indicates to the service provider that it is free135* to release resources associated with the enumeration, and can136* notify servers to cancel any outstanding requests. The {@code close()}137* method is a hint to implementations for managing their resources.138* Implementations are encouraged to use appropriate algorithms to139* manage their resources when client omits the {@code close()} calls.140*141* @throws NamingException If a naming exception is encountered142* while closing the enumeration.143* @since 1.3144*/145public void close() throws NamingException;146}147148149