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