Path: blob/master/src/java.naming/share/classes/javax/naming/ReferralException.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.Hashtable;2829/**30* This abstract class is used to represent a referral exception,31* which is generated in response to a <em>referral</em>32* such as that returned by LDAP v3 servers.33* <p>34* A service provider provides35* a subclass of {@code ReferralException} by providing implementations36* for {@code getReferralInfo()} and {@code getReferralContext()} (and appropriate37* constructors and/or corresponding "set" methods).38* <p>39* The following code sample shows how {@code ReferralException} can be used.40* <blockquote><pre>{@code41* while (true) {42* try {43* bindings = ctx.listBindings(name);44* while (bindings.hasMore()) {45* b = bindings.next();46* ...47* }48* break;49* } catch (ReferralException e) {50* ctx = e.getReferralContext();51* }52* }53* }</pre></blockquote>54*<p>55* {@code ReferralException} is an abstract class. Concrete implementations56* determine its synchronization and serialization properties.57*<p>58* An environment parameter passed to the {@code getReferralContext()}59* method is owned by the caller.60* The service provider will not modify the object or keep a reference to it,61* but may keep a reference to a clone of it.62*63* @author Rosanna Lee64* @author Scott Seligman65*66* @since 1.367*68*/6970public abstract class ReferralException extends NamingException {71/**72* Constructs a new instance of ReferralException using the73* explanation supplied. All other fields are set to null.74*75* @param explanation Additional detail about this exception. Can be null.76* @see java.lang.Throwable#getMessage77*/78protected ReferralException(String explanation) {79super(explanation);80}8182/**83* Constructs a new instance of ReferralException.84* All fields are set to null.85*/86protected ReferralException() {87super();88}8990/**91* Retrieves information (such as URLs) related to this referral.92* The program may examine or display this information93* to the user to determine whether to continue with the referral,94* or to determine additional information needs to be supplied in order95* to continue with the referral.96*97* @return Non-null referral information related to this referral.98*/99public abstract Object getReferralInfo();100101/**102* Retrieves the context at which to continue the method.103* Regardless of whether a referral is encountered directly during a104* context operation, or indirectly, for example, during a search105* enumeration, the referral exception should provide a context106* at which to continue the operation. The referral context is107* created using the environment properties of the context108* that threw the ReferralException.109*110*<p>111* To continue the operation, the client program should re-invoke112* the method using the same arguments as the original invocation.113*114* @return The non-null context at which to continue the method.115* @throws NamingException If a naming exception was encountered.116* Call either {@code retryReferral()} or {@code skipReferral()}117* to continue processing referrals.118*/119public abstract Context getReferralContext() throws NamingException;120121/**122* Retrieves the context at which to continue the method using123* environment properties.124* Regardless of whether a referral is encountered directly during a125* context operation, or indirectly, for example, during a search126* enumeration, the referral exception should provide a context127* at which to continue the operation.128*<p>129* The referral context is created using {@code env} as its environment130* properties.131* This method should be used instead of the no-arg overloaded form132* when the caller needs to use different environment properties for133* the referral context. It might need to do this, for example, when134* it needs to supply different authentication information to the referred135* server in order to create the referral context.136*<p>137* To continue the operation, the client program should re-invoke138* the method using the same arguments as the original invocation.139*140* @param env The possibly null environment to use when retrieving the141* referral context. If null, no environment properties will be used.142*143* @return The non-null context at which to continue the method.144* @throws NamingException If a naming exception was encountered.145* Call either {@code retryReferral()} or {@code skipReferral()}146* to continue processing referrals.147*/148public abstract Context149getReferralContext(Hashtable<?,?> env)150throws NamingException;151152/**153* Discards the referral about to be processed.154* A call to this method should be followed by a call to155* {@code getReferralContext} to allow the processing of156* other referrals to continue.157* The following code fragment shows a typical usage pattern.158* <blockquote><pre>159* } catch (ReferralException e) {160* if (!shallIFollow(e.getReferralInfo())) {161* if (!e.skipReferral()) {162* return;163* }164* }165* ctx = e.getReferralContext();166* }167* </pre></blockquote>168*169* @return true If more referral processing is pending; false otherwise.170*/171public abstract boolean skipReferral();172173/**174* Retries the referral currently being processed.175* A call to this method should be followed by a call to176* {@code getReferralContext} to allow the current177* referral to be retried.178* The following code fragment shows a typical usage pattern.179* <blockquote><pre>180* } catch (ReferralException e) {181* while (true) {182* try {183* ctx = e.getReferralContext(env);184* break;185* } catch (NamingException ne) {186* if (! shallIRetry()) {187* return;188* }189* // modify environment properties (env), if necessary190* e.retryReferral();191* }192* }193* }194* </pre></blockquote>195*196*/197public abstract void retryReferral();198199/**200* Use serialVersionUID from JNDI 1.1.1 for interoperability201*/202private static final long serialVersionUID = -2881363844695698876L;203}204205206