001 /*
002 * Copyright 1999-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.naming;
027
028 import java.util.Hashtable;
029
030 /**
031 * This abstract class is used to represent a referral exception,
032 * which is generated in response to a <em>referral</em>
033 * such as that returned by LDAP v3 servers.
034 * <p>
035 * A service provider provides
036 * a subclass of <tt>ReferralException</tt> by providing implementations
037 * for <tt>getReferralInfo()</tt> and <tt>getReferralContext()</tt> (and appropriate
038 * constructors and/or corresponding "set" methods).
039 * <p>
040 * The following code sample shows how <tt>ReferralException</tt> can be used.
041 * <p><blockquote><pre>
042 * while (true) {
043 * try {
044 * bindings = ctx.listBindings(name);
045 * while (bindings.hasMore()) {
046 * b = bindings.next();
047 * ...
048 * }
049 * break;
050 * } catch (ReferralException e) {
051 * ctx = e.getReferralContext();
052 * }
053 * }
054 * </pre></blockquote></p>
055 *<p>
056 * <tt>ReferralException</tt> is an abstract class. Concrete implementations
057 * determine its synchronization and serialization properties.
058 *<p>
059 * An environment parameter passed to the <tt>getReferralContext()</tt>
060 * method is owned by the caller.
061 * The service provider will not modify the object or keep a reference to it,
062 * but may keep a reference to a clone of it.
063 *
064 * @author Rosanna Lee
065 * @author Scott Seligman
066 * @version 1.18 07/05/05
067 *
068 * @since 1.3
069 *
070 */
071
072 public abstract class ReferralException extends NamingException {
073 /**
074 * Constructs a new instance of ReferralException using the
075 * explanation supplied. All other fields are set to null.
076 *
077 * @param explanation Additional detail about this exception. Can be null.
078 * @see java.lang.Throwable#getMessage
079 */
080 protected ReferralException(String explanation) {
081 super (explanation);
082 }
083
084 /**
085 * Constructs a new instance of ReferralException.
086 * All fields are set to null.
087 */
088 protected ReferralException() {
089 super ();
090 }
091
092 /**
093 * Retrieves information (such as URLs) related to this referral.
094 * The program may examine or display this information
095 * to the user to determine whether to continue with the referral,
096 * or to determine additional information needs to be supplied in order
097 * to continue with the referral.
098 *
099 * @return Non-null referral information related to this referral.
100 */
101 public abstract Object getReferralInfo();
102
103 /**
104 * Retrieves the context at which to continue the method.
105 * Regardless of whether a referral is encountered directly during a
106 * context operation, or indirectly, for example, during a search
107 * enumeration, the referral exception should provide a context
108 * at which to continue the operation. The referral context is
109 * created using the environment properties of the context
110 * that threw the ReferralException.
111 *
112 *<p>
113 * To continue the operation, the client program should re-invoke
114 * the method using the same arguments as the original invocation.
115 *
116 * @return The non-null context at which to continue the method.
117 * @exception NamingException If a naming exception was encountered.
118 * Call either <tt>retryReferral()</tt> or <tt>skipReferral()</tt>
119 * to continue processing referrals.
120 */
121 public abstract Context getReferralContext() throws NamingException;
122
123 /**
124 * Retrieves the context at which to continue the method using
125 * environment properties.
126 * Regardless of whether a referral is encountered directly during a
127 * context operation, or indirectly, for example, during a search
128 * enumeration, the referral exception should provide a context
129 * at which to continue the operation.
130 *<p>
131 * The referral context is created using <tt>env</tt> as its environment
132 * properties.
133 * This method should be used instead of the no-arg overloaded form
134 * when the caller needs to use different environment properties for
135 * the referral context. It might need to do this, for example, when
136 * it needs to supply different authentication information to the referred
137 * server in order to create the referral context.
138 *<p>
139 * To continue the operation, the client program should re-invoke
140 * the method using the same arguments as the original invocation.
141 *
142 * @param env The possibly null environment to use when retrieving the
143 * referral context. If null, no environment properties will be used.
144 *
145 * @return The non-null context at which to continue the method.
146 * @exception NamingException If a naming exception was encountered.
147 * Call either <tt>retryReferral()</tt> or <tt>skipReferral()</tt>
148 * to continue processing referrals.
149 */
150 public abstract Context getReferralContext(Hashtable<?, ?> env)
151 throws NamingException;
152
153 /**
154 * Discards the referral about to be processed.
155 * A call to this method should be followed by a call to
156 * <code>getReferralContext</code> to allow the processing of
157 * other referrals to continue.
158 * The following code fragment shows a typical usage pattern.
159 * <p><blockquote><pre>
160 * } catch (ReferralException e) {
161 * if (!shallIFollow(e.getReferralInfo())) {
162 * if (!e.skipReferral()) {
163 * return;
164 * }
165 * }
166 * ctx = e.getReferralContext();
167 * }
168 * </pre></blockquote>
169 *
170 * @return true If more referral processing is pending; false otherwise.
171 */
172 public abstract boolean skipReferral();
173
174 /**
175 * Retries the referral currently being processed.
176 * A call to this method should be followed by a call to
177 * <code>getReferralContext</code> to allow the current
178 * referral to be retried.
179 * The following code fragment shows a typical usage pattern.
180 * <p><blockquote><pre>
181 * } catch (ReferralException e) {
182 * while (true) {
183 * try {
184 * ctx = e.getReferralContext(env);
185 * break;
186 * } catch (NamingException ne) {
187 * if (! shallIRetry()) {
188 * return;
189 * }
190 * // modify environment properties (env), if necessary
191 * e.retryReferral();
192 * }
193 * }
194 * }
195 * </pre></blockquote>
196 *
197 */
198 public abstract void retryReferral();
199
200 /**
201 * Use serialVersionUID from JNDI 1.1.1 for interoperability
202 */
203 private static final long serialVersionUID = -2881363844695698876L;
204 }
|