1. /*
  2. * @(#)ReferralException.java 1.8 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.Hashtable;
  9. /**
  10. * This abstract class is used to represent a referral exception,
  11. * which is generated in response to a <em>referral</em>
  12. * such as that returned by LDAP v3 servers.
  13. * <p>
  14. * A service provider provides
  15. * a subclass of <tt>ReferralException</tt> by providing implementations
  16. * for <tt>getReferralInfo()</tt> and <tt>getReferralContext()</tt> (and appropriate
  17. * constructors and/or corresponding "set" methods).
  18. * <p>
  19. * The following code sample shows how <tt>ReferralException</tt> can be used.
  20. * <p><blockquote><pre>
  21. * while (true) {
  22. * try {
  23. * bindings = ctx.listBindings(name);
  24. * while (bindings.hasMore()) {
  25. * b = bindings.next();
  26. * ...
  27. * }
  28. * break;
  29. * } catch (ReferralException e) {
  30. * ctx = e.getReferralContext();
  31. * }
  32. * }
  33. * </pre></blockquote></p>
  34. *<p>
  35. * <tt>ReferralException</tt> is an abstract class. Concrete implementations
  36. * determine its synchronization and serialization properties.
  37. *<p>
  38. * An environment parameter passed to the <tt>getReferralContext()</tt>
  39. * method is owned by the caller.
  40. * The service provider will not modify the object or keep a reference to it,
  41. * but may keep a reference to a clone of it.
  42. *
  43. * @author Rosanna Lee
  44. * @author Scott Seligman
  45. * @version 1.8 03/01/23
  46. *
  47. * @since 1.3
  48. *
  49. */
  50. public abstract class ReferralException extends NamingException {
  51. /**
  52. * Constructs a new instance of ReferralException using the
  53. * explanation supplied. All other fields are set to null.
  54. *
  55. * @param explanation Additional detail about this exception. Can be null.
  56. * @see java.lang.Throwable#getMessage
  57. */
  58. protected ReferralException(String explanation) {
  59. super(explanation);
  60. }
  61. /**
  62. * Constructs a new instance of ReferralException.
  63. * All fields are set to null.
  64. */
  65. protected ReferralException() {
  66. super();
  67. }
  68. /**
  69. * Retrieves information (such as URLs) related to this referral.
  70. * The program may examine or display this information
  71. * to the user to determine whether to continue with the referral,
  72. * or to determine additional information needs to be supplied in order
  73. * to continue with the referral.
  74. *
  75. * @return Non-null referral information related to this referral.
  76. */
  77. public abstract Object getReferralInfo();
  78. /**
  79. * Retrieves the context at which to continue the method.
  80. * Regardless of whether a referral is encountered directly during a
  81. * context operation, or indirectly, for example, during a search
  82. * enumeration, the referral exception should provide a context
  83. * at which to continue the operation. The referral context is
  84. * created using the environment properties of the context
  85. * that threw the ReferralException.
  86. *
  87. *<p>
  88. * To continue the operation, the client program should re-invoke
  89. * the method using the same arguments as the original invocation.
  90. *
  91. * @return The non-null context at which to continue the method.
  92. * @exception NamingException If a naming exception was encountered.
  93. * Call either <tt>retryReferral()</tt> or <tt>skipReferral()</tt>
  94. * to continue processing referrals.
  95. */
  96. public abstract Context getReferralContext() throws NamingException;
  97. /**
  98. * Retrieves the context at which to continue the method using
  99. * environment properties.
  100. * Regardless of whether a referral is encountered directly during a
  101. * context operation, or indirectly, for example, during a search
  102. * enumeration, the referral exception should provide a context
  103. * at which to continue the operation.
  104. *<p>
  105. * The referral context is created using <tt>env</tt> as its environment
  106. * properties.
  107. * This method should be used instead of the no-arg overloaded form
  108. * when the caller needs to use different environment properties for
  109. * the referral context. It might need to do this, for example, when
  110. * it needs to supply different authentication information to the referred
  111. * server in order to create the referral context.
  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. * @param env The possibly null environment to use when retrieving the
  117. * referral context. If null, no environment properties will be used.
  118. *
  119. * @return The non-null context at which to continue the method.
  120. * @exception NamingException If a naming exception was encountered.
  121. * Call either <tt>retryReferral()</tt> or <tt>skipReferral()</tt>
  122. * to continue processing referrals.
  123. */
  124. public abstract Context getReferralContext(Hashtable env) throws NamingException;
  125. /**
  126. * Discards the referral about to be processed.
  127. * A call to this method should be followed by a call to
  128. * <code>getReferralContext</code> to allow the processing of
  129. * other referrals to continue.
  130. * The following code fragment shows a typical usage pattern.
  131. * <p><blockquote><pre>
  132. * } catch (ReferralException e) {
  133. * if (!shallIFollow(e.getReferralInfo())) {
  134. * if (!e.skipReferral()) {
  135. * return;
  136. * }
  137. * }
  138. * ctx = e.getReferralContext();
  139. * }
  140. * </pre></blockquote>
  141. *
  142. * @return true If more referral processing is pending; false otherwise.
  143. */
  144. public abstract boolean skipReferral();
  145. /**
  146. * Retries the referral currently being processed.
  147. * A call to this method should be followed by a call to
  148. * <code>getReferralContext</code> to allow the current
  149. * referral to be retried.
  150. * The following code fragment shows a typical usage pattern.
  151. * <p><blockquote><pre>
  152. * } catch (ReferralException e) {
  153. * while (true) {
  154. * try {
  155. * ctx = e.getReferralContext(env);
  156. * break;
  157. * } catch (NamingException ne) {
  158. * if (! shallIRetry()) {
  159. * return;
  160. * }
  161. * // modify environment properties (env), if necessary
  162. * e.retryReferral();
  163. * }
  164. * }
  165. * }
  166. * </pre></blockquote>
  167. *
  168. */
  169. public abstract void retryReferral();
  170. /**
  171. * Use serialVersionUID from JNDI 1.1.1 for interoperability
  172. */
  173. private static final long serialVersionUID = -2881363844695698876L;
  174. }