src/share/classes/com/sun/jndi/ldap/LdapReferralException.java

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.jndi.ldap;
  27 
  28 import javax.naming.*;
  29 import javax.naming.spi.*;
  30 import javax.naming.ldap.Control;
  31 
  32 import java.util.Hashtable;
  33 import java.util.Vector;
  34 
  35 /**
  36   * This exception is raised when a referral to an alternative context
  37   * is encountered.
  38   * <p>
  39   * An <tt>LdapReferralException</tt> object contains one or more referrals.
  40   * Each referral is an alternative location for the same target entry.
  41   * For example, a referral may be an LDAP URL.
  42   * The referrals are attempted in sequence until one is successful or
  43   * all have failed. In the case of the latter then the exception generated
  44   * by the final referral is recorded and presented later.
  45   * <p>
  46   * A referral may be skipped or may be retried. For example, in the case
  47   * of an authentication error, a referral may be retried with different
  48   * environment properties.
  49   * <p>
  50   * An <tt>LdapReferralException</tt> object may also contain a reference
  51   * to a chain of unprocessed <tt>LdapReferralException</tt> objects.
  52   * Once the current set of referrals have been exhausted and unprocessed
  53   * <tt>LdapReferralException</tt> objects remain, then the
  54   * <tt>LdapReferralException</tt> object referenced by the current
  55   * object is thrown and the cycle continues.
  56   * <p>
  57   * If new <tt>LdapReferralException</tt> objects are generated while
  58   * following an existing referral then these new objects are appended
  59   * to the end of the chain of unprocessed <tt>LdapReferralException</tt>
  60   * objects.
  61   * <p>
  62   * If an exception was recorded while processing a chain of
  63   * <tt>LdapReferralException</tt> objects then is is throw once
  64   * processing has completed.
  65   *
  66   * @author Vincent Ryan
  67   */
  68 final public class LdapReferralException extends
  69     javax.naming.ldap.LdapReferralException {

  70 
  71         // ----------- fields initialized in constructor ---------------
  72     private int handleReferrals;
  73     private Hashtable envprops;
  74     private String nextName;
  75     private Control[] reqCtls;
  76 
  77         // ----------- fields that have defaults -----------------------
  78     private Vector referrals = null;    // alternatives,set by setReferralInfo()
  79     private int referralIndex = 0;      // index into referrals
  80     private int referralCount = 0;      // count of referrals
  81     private boolean foundEntry = false; // will stop when entry is found
  82     private boolean skipThisReferral = false;
  83     private int hopCount = 1;
  84     private NamingException errorEx = null;
  85     private String newRdn = null;
  86     private boolean debug = false;
  87             LdapReferralException nextReferralEx = null; // referral ex. chain
  88 
  89     /**
  90      * Constructs a new instance of LdapReferralException.
  91      * @param   resolvedName    The part of the name that has been successfully
  92      *                          resolved.
  93      * @param   resolvedObj     The object to which resolution was successful.
  94      * @param   remainingName   The remaining unresolved portion of the name.
  95      * @param   explanation     Additional detail about this exception.
  96      */
  97     LdapReferralException(Name resolvedName,
  98         Object resolvedObj,
  99         Name remainingName,
 100         String explanation,
 101         Hashtable envprops,
 102         String nextName,
 103         int handleReferrals,
 104         Control[] reqCtls) {
 105 
 106         super(explanation);
 107 
 108         if (debug)
 109             System.out.println("LdapReferralException constructor");
 110 
 111         setResolvedName(resolvedName);
 112         setResolvedObj(resolvedObj);
 113         setRemainingName(remainingName);
 114         this.envprops = envprops;
 115         this.nextName = nextName;
 116         this.handleReferrals = handleReferrals;
 117 
 118         // If following referral, request controls are passed to referral ctx
 119         this.reqCtls =
 120             (handleReferrals == LdapClient.LDAP_REF_FOLLOW ? reqCtls : null);
 121     }


 193     public boolean skipReferral() {
 194         if (debug)
 195             System.out.println("LdapReferralException.skipReferral");
 196 
 197         skipThisReferral = true;
 198 
 199         // advance to next referral
 200         try {
 201             getNextReferral();
 202         } catch (ReferralException e) {
 203             // mask the referral exception
 204         }
 205 
 206         return (hasMoreReferrals() || hasMoreReferralExceptions());
 207     }
 208 
 209 
 210     /**
 211      * Sets referral information.
 212      */
 213     void setReferralInfo(Vector referrals, boolean continuationRef) {
 214         // %%% continuationRef is currently ignored
 215 
 216         if (debug)
 217             System.out.println("LdapReferralException.setReferralInfo");
 218 
 219         this.referrals = referrals;
 220         if (referrals != null) {
 221             referralCount = referrals.size();
 222         }
 223 
 224         if (debug) {
 225             for (int i = 0; i < referralCount; i++) {
 226                 System.out.println("  [" + i + "] " + referrals.elementAt(i));
 227             }
 228         }
 229     }
 230 
 231     /**
 232      * Gets the next referral. When the current set of referrals have
 233      * been exhausted then the next referral exception is thrown, if available.




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.jndi.ldap;
  27 
  28 import javax.naming.*;

  29 import javax.naming.ldap.Control;
  30 
  31 import java.util.Hashtable;
  32 import java.util.Vector;
  33 
  34 /**
  35   * This exception is raised when a referral to an alternative context
  36   * is encountered.
  37   * <p>
  38   * An <tt>LdapReferralException</tt> object contains one or more referrals.
  39   * Each referral is an alternative location for the same target entry.
  40   * For example, a referral may be an LDAP URL.
  41   * The referrals are attempted in sequence until one is successful or
  42   * all have failed. In the case of the latter then the exception generated
  43   * by the final referral is recorded and presented later.
  44   * <p>
  45   * A referral may be skipped or may be retried. For example, in the case
  46   * of an authentication error, a referral may be retried with different
  47   * environment properties.
  48   * <p>
  49   * An <tt>LdapReferralException</tt> object may also contain a reference
  50   * to a chain of unprocessed <tt>LdapReferralException</tt> objects.
  51   * Once the current set of referrals have been exhausted and unprocessed
  52   * <tt>LdapReferralException</tt> objects remain, then the
  53   * <tt>LdapReferralException</tt> object referenced by the current
  54   * object is thrown and the cycle continues.
  55   * <p>
  56   * If new <tt>LdapReferralException</tt> objects are generated while
  57   * following an existing referral then these new objects are appended
  58   * to the end of the chain of unprocessed <tt>LdapReferralException</tt>
  59   * objects.
  60   * <p>
  61   * If an exception was recorded while processing a chain of
  62   * <tt>LdapReferralException</tt> objects then is is throw once
  63   * processing has completed.
  64   *
  65   * @author Vincent Ryan
  66   */
  67 final public class LdapReferralException extends
  68     javax.naming.ldap.LdapReferralException {
  69     private static final long serialVersionUID = 627059076356906399L;
  70 
  71         // ----------- fields initialized in constructor ---------------
  72     private int handleReferrals;
  73     private Hashtable<?,?> envprops;
  74     private String nextName;
  75     private Control[] reqCtls;
  76 
  77         // ----------- fields that have defaults -----------------------
  78     private Vector<?> referrals = null; // alternatives,set by setReferralInfo()
  79     private int referralIndex = 0;      // index into referrals
  80     private int referralCount = 0;      // count of referrals
  81     private boolean foundEntry = false; // will stop when entry is found
  82     private boolean skipThisReferral = false;
  83     private int hopCount = 1;
  84     private NamingException errorEx = null;
  85     private String newRdn = null;
  86     private boolean debug = false;
  87             LdapReferralException nextReferralEx = null; // referral ex. chain
  88 
  89     /**
  90      * Constructs a new instance of LdapReferralException.
  91      * @param   resolvedName    The part of the name that has been successfully
  92      *                          resolved.
  93      * @param   resolvedObj     The object to which resolution was successful.
  94      * @param   remainingName   The remaining unresolved portion of the name.
  95      * @param   explanation     Additional detail about this exception.
  96      */
  97     LdapReferralException(Name resolvedName,
  98         Object resolvedObj,
  99         Name remainingName,
 100         String explanation,
 101         Hashtable<?,?> envprops,
 102         String nextName,
 103         int handleReferrals,
 104         Control[] reqCtls) {
 105 
 106         super(explanation);
 107 
 108         if (debug)
 109             System.out.println("LdapReferralException constructor");
 110 
 111         setResolvedName(resolvedName);
 112         setResolvedObj(resolvedObj);
 113         setRemainingName(remainingName);
 114         this.envprops = envprops;
 115         this.nextName = nextName;
 116         this.handleReferrals = handleReferrals;
 117 
 118         // If following referral, request controls are passed to referral ctx
 119         this.reqCtls =
 120             (handleReferrals == LdapClient.LDAP_REF_FOLLOW ? reqCtls : null);
 121     }


 193     public boolean skipReferral() {
 194         if (debug)
 195             System.out.println("LdapReferralException.skipReferral");
 196 
 197         skipThisReferral = true;
 198 
 199         // advance to next referral
 200         try {
 201             getNextReferral();
 202         } catch (ReferralException e) {
 203             // mask the referral exception
 204         }
 205 
 206         return (hasMoreReferrals() || hasMoreReferralExceptions());
 207     }
 208 
 209 
 210     /**
 211      * Sets referral information.
 212      */
 213     void setReferralInfo(Vector<?> referrals, boolean continuationRef) {
 214         // %%% continuationRef is currently ignored
 215 
 216         if (debug)
 217             System.out.println("LdapReferralException.setReferralInfo");
 218 
 219         this.referrals = referrals;
 220         if (referrals != null) {
 221             referralCount = referrals.size();
 222         }
 223 
 224         if (debug) {
 225             for (int i = 0; i < referralCount; i++) {
 226                 System.out.println("  [" + i + "] " + referrals.elementAt(i));
 227             }
 228         }
 229     }
 230 
 231     /**
 232      * Gets the next referral. When the current set of referrals have
 233      * been exhausted then the next referral exception is thrown, if available.