| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 2 | * |
| 3 | * ***** BEGIN LICENSE BLOCK ***** |
| 4 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 5 | * |
| 6 | * The contents of this file are subject to the Mozilla Public License Version |
| 7 | * 1.1 (the "License"); you may not use this file except in compliance with |
| 8 | * the License. You may obtain a copy of the License at |
| 9 | * http://www.mozilla.org/MPL/ |
| 10 | * |
| 11 | * Software distributed under the License is distributed on an "AS IS" basis, |
| 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 | * for the specific language governing rights and limitations under the |
| 14 | * License. |
| 15 | * |
| 16 | * The Original Code is mozilla.org code. |
| 17 | * |
| 18 | * The Initial Developer of the Original Code is |
| 19 | * Netscape Communications Corporation. |
| 20 | * Portions created by the Initial Developer are Copyright (C) 1999 |
| 21 | * the Initial Developer. All Rights Reserved. |
| 22 | * |
| 23 | * Contributor(s): |
| 24 | * |
| 25 | * Alternatively, the contents of this file may be used under the terms of |
| 26 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
| 27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 28 | * in which case the provisions of the GPL or the LGPL are applicable instead |
| 29 | * of those above. If you wish to allow use of your version of this file only |
| 30 | * under the terms of either the GPL or the LGPL, and not to allow others to |
| 31 | * use your version of this file under the terms of the MPL, indicate your |
| 32 | * decision by deleting the provisions above and replace them with the notice |
| 33 | * and other provisions required by the GPL or the LGPL. If you do not delete |
| 34 | * the provisions above, a recipient may use your version of this file under |
| 35 | * the terms of any one of the MPL, the GPL or the LGPL. |
| 36 | * |
| 37 | * ***** END LICENSE BLOCK ***** */ |
| 38 | package org.ietf.ldap; |
| 39 | |
| 40 | import java.io.IOException; |
| 41 | import java.io.Serializable; |
| 42 | import java.util.Hashtable; |
| 43 | import java.util.Locale; |
| 44 | import java.util.PropertyResourceBundle; |
| 45 | |
| 46 | /** |
| 47 | * Indicates that an error has occurred. An <CODE>LDAPException</CODE> |
| 48 | * can result from physical problems (such as network errors) as well as |
| 49 | * problems with LDAP operations (for example, if the LDAP add operation |
| 50 | * fails because of duplicate entry). |
| 51 | * <P> |
| 52 | * |
| 53 | * Most errors that occur throw this type of exception. In order to determine |
| 54 | * the cause of the error, you can call the <CODE>getResultCode()</CODE> |
| 55 | * method to get the specific result code and compare this code against |
| 56 | * the result codes defined as fields in this class. (For example, if |
| 57 | * the result code matches the value of the field |
| 58 | * <CODE>LDAPException.TIME_LIMIT_EXCEEDED</CODE>, the time limit passed |
| 59 | * before the search operation could be completed.) |
| 60 | * <P> |
| 61 | * |
| 62 | * This exception includes methods for getting an error message that |
| 63 | * corresponds to the LDAP result code (for example, "Timelimit exceeded" |
| 64 | * for <CODE>LDAPException.TIME_LIMIT_EXCEEDED</CODE>). These error |
| 65 | * messages are specified in the following files: |
| 66 | * <PRE>netscape/ldap/errors/ErrorCodes_<I>locale_string</I>.props</PRE> |
| 67 | * where <I>locale_string</I> is the name of the locale that includes |
| 68 | * the language and country, but not the variant. |
| 69 | * <P> |
| 70 | * |
| 71 | * For example: |
| 72 | * <PRE>netscape/ldap/errors/ErrorCodes_en_US.props</PRE> |
| 73 | * |
| 74 | * The LDAP Java classes get this locale name by calling the |
| 75 | * <CODE>java.util.Locale.toString</CODE> method for the specified |
| 76 | * locale and ignoring the variant. If no locale is specified, the |
| 77 | * LDAP Java classes use the <CODE>java.util.Locale.getDefault</CODE> |
| 78 | * method to get the locale of the local host system. |
| 79 | * <P> |
| 80 | * |
| 81 | * In order to get error messages for different locales, you need to |
| 82 | * provide files containing the error messages for those locales. |
| 83 | * The files should be located in the <CODE>netscape/ldap/errors</CODE> |
| 84 | * directory and should use the naming convention specified above. |
| 85 | * <P> |
| 86 | * |
| 87 | * The following is a list of LDAP result codes: |
| 88 | * <PRE> |
| 89 | * Result |
| 90 | * Code Defined Value |
| 91 | * ====== ============= |
| 92 | * 0 <A HREF="#SUCCESS">SUCCESS</A> |
| 93 | * 1 <A HREF="#OPERATION_ERROR">OPERATION_ERROR</A> |
| 94 | * 2 <A HREF="#PROTOCOL_ERROR">PROTOCOL_ERROR</A> |
| 95 | * 3 <A HREF="#TIME_LIMIT_EXCEEDED">TIME_LIMIT_EXCEEDED</A> |
| 96 | * 4 <A HREF="#SIZE_LIMIT_EXCEEDED">SIZE_LIMIT_EXCEEDED</A> |
| 97 | * 5 <A HREF="#COMPARE_FALSE">COMPARE_FALSE</A> |
| 98 | * 6 <A HREF="#COMPARE_TRUE">COMPARE_TRUE</A> |
| 99 | * 7 <A HREF="#AUTH_METHOD_NOT_SUPPORTED">AUTH_METHOD_NOT_SUPPORTED</A> |
| 100 | * 8 <A HREF="#STRONG_AUTH_REQUIRED">STRONG_AUTH_REQUIRED</A> |
| 101 | * 9 <A HREF="#LDAP_PARTIAL_RESULTS">LDAP_PARTIAL_RESULTS</A> |
| 102 | * 10 <A HREF="#REFERRAL">REFERRAL</A> (LDAP v3) |
| 103 | * 11 <A HREF="#ADMIN_LIMIT_EXCEEDED">ADMIN_LIMIT_EXCEEDED</A> (LDAP v3) |
| 104 | * 12 <A HREF="#UNAVAILABLE_CRITICAL_EXTENSION">UNAVAILABLE_CRITICAL_EXTENSION</A> (LDAP v3) |
| 105 | * 13 <A HREF="#CONFIDENTIALITY_REQUIRED">CONFIDENTIALITY_REQUIRED</A> (LDAP v3) |
| 106 | * 14 <A HREF="#SASL_BIND_IN_PROGRESS">SASL_BIND_IN_PROGRESS</A> (LDAP v3) |
| 107 | * 16 <A HREF="#NO_SUCH_ATTRIBUTE">NO_SUCH_ATTRIBUTE</A> |
| 108 | * 17 <A HREF="#UNDEFINED_ATTRIBUTE_TYPE">UNDEFINED_ATTRIBUTE_TYPE</A> |
| 109 | * 18 <A HREF="#INAPPROPRIATE_MATCHING">INAPPROPRIATE_MATCHING</A> |
| 110 | * 19 <A HREF="#CONSTRAINT_VIOLATION">CONSTRAINT_VIOLATION</A> |
| 111 | * 20 <A HREF="#ATTRIBUTE_OR_VALUE_EXISTS">ATTRIBUTE_OR_VALUE_EXISTS</A> |
| 112 | * 21 <A HREF="#INVALID_ATTRIBUTE_SYNTAX">INVALID_ATTRIBUTE_SYNTAX</A> |
| 113 | * 32 <A HREF="#NO_SUCH_OBJECT">NO_SUCH_OBJECT</A> |
| 114 | * 33 <A HREF="#ALIAS_PROBLEM">ALIAS_PROBLEM</A> |
| 115 | * 34 <A HREF="#INVALID_DN_SYNTAX">INVALID_DN_SYNTAX</A> |
| 116 | * 35 <A HREF="#IS_LEAF">IS_LEAF</A> |
| 117 | * 36 <A HREF="#ALIAS_DEREFERENCING_PROBLEM">ALIAS_DEREFERENCING_PROBLEM</A> |
| 118 | * 48 <A HREF="#INAPPROPRIATE_AUTHENTICATION">INAPPROPRIATE_AUTHENTICATION</A> |
| 119 | * 49 <A HREF="#INVALID_CREDENTIALS">INVALID_CREDENTIALS</A> |
| 120 | * 50 <A HREF="#INSUFFICIENT_ACCESS_RIGHTS">INSUFFICIENT_ACCESS_RIGHTS</A> |
| 121 | * 51 <A HREF="#BUSY">BUSY</A> |
| 122 | * 52 <A HREF="#UNAVAILABLE">UNAVAILABLE</A> |
| 123 | * 53 <A HREF="#UNWILLING_TO_PERFORM">UNWILLING_TO_PERFORM</A> |
| 124 | * 54 <A HREF="#LOOP_DETECT">LOOP_DETECT</A> |
| 125 | * 64 <A HREF="#NAMING_VIOLATION">NAMING_VIOLATION</A> |
| 126 | * 65 <A HREF="#OBJECT_CLASS_VIOLATION">OBJECT_CLASS_VIOLATION</A> |
| 127 | * 66 <A HREF="#NOT_ALLOWED_ON_NONLEAF">NOT_ALLOWED_ON_NONLEAF</A> |
| 128 | * 67 <A HREF="#NOT_ALLOWED_ON_RDN">NOT_ALLOWED_ON_RDN</A> |
| 129 | * 68 <A HREF="#ENTRY_ALREADY_EXISTS">ENTRY_ALREADY_EXISTS</A> |
| 130 | * 69 <A HREF="#OBJECT_CLASS_MODS_PROHIBITED">OBJECT_CLASS_MODS_PROHIBITED</A> |
| 131 | * 71 <A HREF="#AFFECTS_MULTIPLE_DSAS">AFFECTS_MULTIPLE_DSAS</A> (LDAP v3) |
| 132 | * 80 <A HREF="#OTHER">OTHER</A> |
| 133 | * 81 <A HREF="#SERVER_DOWN">SERVER_DOWN</A> |
| 134 | * 85 <A HREF="#LDAP_TIMEOUT">LDAP_TIMEOUT</A> |
| 135 | * 89 <A HREF="#PARAM_ERROR">PARAM_ERROR</A> |
| 136 | * 91 <A HREF="#CONNECT_ERROR">CONNECT_ERROR</A> |
| 137 | * 92 <A HREF="#LDAP_NOT_SUPPORTED">LDAP_NOT_SUPPORTED</A> |
| 138 | * 93 <A HREF="#CONTROL_NOT_FOUND">CONTROL_NOT_FOUND</A> |
| 139 | * 94 <A HREF="#NO_RESULTS_RETURNED">NO_RESULTS_RETURNED</A> |
| 140 | * 95 <A HREF="#MORE_RESULTS_TO_RETURN">MORE_RESULTS_TO_RETURN</A> |
| 141 | * 96 <A HREF="#CLIENT_LOOP">CLIENT_LOOP</A> |
| 142 | * 97 <A HREF="#REFERRAL_LIMIT_EXCEEDED">REFERRAL_LIMIT_EXCEEDED</A> |
| 143 | * 100 <A HREF="#INVALID_RESPONSE">INVALID_RESPONSE</A> |
| 144 | * 101 <A HREF="#AMBIGUOUS_RESPONSE">AMBIGUOUS_RESPONSE</A> |
| 145 | * 112 <A HREF="#TLS_NOT_SUPPORTED">TLS_NOT_SUPPORTED</A> |
| 146 | * </PRE> |
| 147 | * <P> |
| 148 | * |
| 149 | * @version 1.0 |
| 150 | * @see org.ietf.ldap.LDAPReferralException |
| 151 | */ |
| 152 | public class LDAPException extends Exception |
| 153 | implements Serializable { |
| 154 | |
| 155 | static final long serialVersionUID = -9215007872184847924L; |
| 156 | |
| 157 | /** |
| 158 | * (0) The operation completed successfully. |
| 159 | */ |
| 160 | public final static int SUCCESS = 0; |
| 161 | |
| 162 | /** |
| 163 | * (1) An internal error occurred in the LDAP server. |
| 164 | */ |
| 165 | public final static int OPERATION_ERROR = 1; |
| 166 | |
| 167 | /** |
| 168 | * (2) A LDAP server could not correctly interpret the request |
| 169 | * sent by your client because the request does not strictly |
| 170 | * comply with the LDAP protocol. (For example, the data |
| 171 | * was not correctly BER-encoded, or a specified value -- such |
| 172 | * as the search scope or modification type -- does not |
| 173 | * comply with the LDAP protocol. If you invent your own |
| 174 | * search scope, for instance, this result code might be returned.<P> |
| 175 | */ |
| 176 | public final static int PROTOCOL_ERROR = 2; |
| 177 | |
| 178 | /** |
| 179 | * (3) The search operation could not be completed within |
| 180 | * the maximum time limit. You can specify the maximum time |
| 181 | * limit by calling the <CODE>LDAPConnection.setOption</CODE> |
| 182 | * method or the <CODE>LDAPSearchConstraints.setServerTimeLimit</CODE> |
| 183 | * method.<P> |
| 184 | * |
| 185 | * @see org.ietf.ldap.LDAPConnection#setOption |
| 186 | * @see org.ietf.ldap.LDAPSearchConstraints#setServerTimeLimit |
| 187 | */ |
| 188 | public final static int TIME_LIMIT_EXCEEDED = 3; |
| 189 | |
| 190 | /** |
| 191 | * (4) The search found more than the maximum number of results. |
| 192 | * You can specify the maximum number of results by calling the |
| 193 | * <CODE>LDAPConnection.setOption</CODE> method or the |
| 194 | * <CODE>LDAPSearchConstraints.setSizeLimit</CODE> method.<P> |
| 195 | * |
| 196 | * @see org.ietf.ldap.LDAPConnection#setOption |
| 197 | * @see org.ietf.ldap.LDAPSearchConstraints#setMaxResults |
| 198 | */ |
| 199 | public final static int SIZE_LIMIT_EXCEEDED = 4; |
| 200 | |
| 201 | /** |
| 202 | * (5) Value returned by an LDAP compare operation if the |
| 203 | * specified attribute and value is not found in the entry |
| 204 | * (no matching value found). |
| 205 | * |
| 206 | * @see org.ietf.ldap.LDAPConnection#compare |
| 207 | */ |
| 208 | public final static int COMPARE_FALSE = 5; |
| 209 | |
| 210 | /** |
| 211 | * (6) Value returned by an LDAP compare operation if the |
| 212 | * specified attribute and value is found in the entry |
| 213 | * (matching value found). |
| 214 | * |
| 215 | * @see org.ietf.ldap.LDAPConnection#compare |
| 216 | */ |
| 217 | public final static int COMPARE_TRUE = 6; |
| 218 | |
| 219 | /** |
| 220 | * (7) The specified authentication method is not supported |
| 221 | * by the LDAP server that you are connecting to. The |
| 222 | * <CODE>LDAPConnection</CODE> class is implemented so that |
| 223 | * <CODE>LDAPConnection.authenticate</CODE> always |
| 224 | * uses the LDAP_AUTH_SIMPLE method of authentication. |
| 225 | * (<CODE>LDAPConnection.authenticate</CODE> does not |
| 226 | * allow you to select the method of authentication.)<P> |
| 227 | */ |
| 228 | public final static int AUTH_METHOD_NOT_SUPPORTED = 7; |
| 229 | |
| 230 | /** |
| 231 | * (8) A stronger authentication method (more than LDAP_AUTH_SIMPLE) |
| 232 | * is required by the LDAP server that you are connecting to. |
| 233 | * The <CODE>LDAPConnection</CODE> class is implemented so that |
| 234 | * <CODE>LDAPConnection.authenticate</CODE> always |
| 235 | * uses the LDAP_AUTH_SIMPLE method of authentication. |
| 236 | * (<CODE>LDAPConnection.authenticate</CODE> does not |
| 237 | * allow you to select the method of authentication.)<P> |
| 238 | */ |
| 239 | public final static int STRONG_AUTH_REQUIRED = 8; |
| 240 | |
| 241 | /** |
| 242 | * (9) The LDAP server is referring your client to another |
| 243 | * LDAP server. If you set up the <CODE>LDAPConnection</CODE> |
| 244 | * options or the <CODE>LDAPConstraints</CODE> options |
| 245 | * for automatic referral, your client will automatically |
| 246 | * connect and authenticate to the other LDAP server. |
| 247 | * (This <CODE>LDAPException</CODE> will not be raised.) |
| 248 | * <P> |
| 249 | * |
| 250 | * (To set up automatic referrals in an <CODE>LDAPConnection</CODE> |
| 251 | * object, set the <CODE>LDAPConnection.REFERRALS</CODE> option |
| 252 | * to <CODE>true</CODE> and the LDAPConnection.REFERRALS_REBIND_PROC</CODE> |
| 253 | * option to the object containing the method for retrieving |
| 254 | * authentication information (in other words, the distinguished |
| 255 | * name and password to use when authenticating to other LDAP servers). |
| 256 | * <P> |
| 257 | * |
| 258 | * If instead you set <CODE>LDAPConnection.REFERRALS</CODE> |
| 259 | * to <CODE>false</CODE> (or if you set |
| 260 | * <CODE>LDAPConstraints.setReferrals</CODE> to <CODE>false</CODE>, |
| 261 | * an <CODE>LDAPReferralException</CODE> is raised. |
| 262 | * <P> |
| 263 | * |
| 264 | * If an error occurs during the referral process, an |
| 265 | * <CODE>LDAPException</CODE> with this result code |
| 266 | * (<CODE>LDAP_PARTIAL_RESULTS</CODE>) is raised. |
| 267 | * <P> |
| 268 | * |
| 269 | * @see org.ietf.ldap.LDAPConnection#setOption |
| 270 | * @see org.ietf.ldap.LDAPConstraints#setReferralFollowing |
| 271 | * @see org.ietf.ldap.LDAPConstraints#setReferralHandler |
| 272 | * @see org.ietf.ldap.LDAPReferralHandler |
| 273 | * @see org.ietf.ldap.LDAPAuthHandler |
| 274 | * @see org.ietf.ldap.LDAPAuthProvider |
| 275 | * @see org.ietf.ldap.LDAPReferralException |
| 276 | */ |
| 277 | public final static int LDAP_PARTIAL_RESULTS = 9; |
| 278 | |
| 279 | /** |
| 280 | * (10) [LDAP v3] The server does not hold the requested entry. |
| 281 | * The referral field of the server's response contains a |
| 282 | * reference to another server (or set of servers), which |
| 283 | * your client can access through LDAP or other protocols. |
| 284 | * Typically, these references are LDAP URLs that identify |
| 285 | * the server that may contain the requested entry. |
| 286 | * <P> |
| 287 | * |
| 288 | * When this occurs, a <CODE>LDAPReferralException</CODE> |
| 289 | * is thrown. You can catch this exception and call the |
| 290 | * <CODE>getURLs</CODE> method to get the list of LDAP |
| 291 | * URLs from the exception. |
| 292 | * <P> |
| 293 | * |
| 294 | * @see org.ietf.ldap.LDAPReferralException |
| 295 | */ |
| 296 | public final static int REFERRAL = 10; |
| 297 | |
| 298 | /** |
| 299 | * (11) [LDAP v3] The adminstrative limit on the |
| 300 | * maximum number of entries to return was exceeded. |
| 301 | * In the Netscape Directory Server 3.0, this |
| 302 | * corresponds to the "look through limit" for |
| 303 | * the server. This is the maximum number of |
| 304 | * entries that the server will check through |
| 305 | * when determining which entries match the |
| 306 | * search filter and scope. |
| 307 | * <P> |
| 308 | */ |
| 309 | public final static int ADMIN_LIMIT_EXCEEDED = 11; |
| 310 | |
| 311 | /** |
| 312 | * (12) [LDAP v3] The server received an LDAP v3 control |
| 313 | * that is marked critical and either (1) is not |
| 314 | * recognized or supported by the server, or |
| 315 | * (2) is inappropriate for the operation requested. |
| 316 | * The Netscape Directory Server 3.0 also returns |
| 317 | * this result code if the client specifies a |
| 318 | * matching rule that is not supported by the server. |
| 319 | * <P> |
| 320 | * |
| 321 | * @see org.ietf.ldap.LDAPControl |
| 322 | */ |
| 323 | public final static int UNAVAILABLE_CRITICAL_EXTENSION = 12; |
| 324 | |
| 325 | /** |
| 326 | * (13) [LDAP v3] A secure connection is required for |
| 327 | * this operation. |
| 328 | */ |
| 329 | public final static int CONFIDENTIALITY_REQUIRED = 13; |
| 330 | |
| 331 | /** |
| 332 | * (14) [LDAP v3] While authenticating your client |
| 333 | * by using a SASL (Simple Authentication Security Layer) |
| 334 | * mechanism, the server requires the client to send |
| 335 | * a new SASL bind request (specifying the same SASL |
| 336 | * mechanism) to continue the authentication process. |
| 337 | */ |
| 338 | public final static int SASL_BIND_IN_PROGRESS = 14; |
| 339 | |
| 340 | /** |
| 341 | * (16) The specified attribute could not be found. |
| 342 | */ |
| 343 | public final static int NO_SUCH_ATTRIBUTE = 16; |
| 344 | |
| 345 | /** |
| 346 | * (17) The specified attribute is not defined. |
| 347 | */ |
| 348 | public final static int UNDEFINED_ATTRIBUTE_TYPE = 17; |
| 349 | |
| 350 | /** |
| 351 | * (18) An inappropriate type of matching was used. |
| 352 | */ |
| 353 | public final static int INAPPROPRIATE_MATCHING = 18; |
| 354 | |
| 355 | /** |
| 356 | * (19) An internal error occurred in the LDAP server. |
| 357 | */ |
| 358 | public final static int CONSTRAINT_VIOLATION = 19; |
| 359 | |
| 360 | /** |
| 361 | * (20) The value that you are adding to an attribute |
| 362 | * already exists in the attribute. |
| 363 | */ |
| 364 | public final static int ATTRIBUTE_OR_VALUE_EXISTS = 20; |
| 365 | |
| 366 | /** |
| 367 | * (21) The request contains invalid syntax. |
| 368 | */ |
| 369 | public final static int INVALID_ATTRIBUTE_SYNTAX = 21; |
| 370 | |
| 371 | /** |
| 372 | * (32) The entry specified in the request does not exist. |
| 373 | */ |
| 374 | public final static int NO_SUCH_OBJECT = 32; |
| 375 | |
| 376 | /** |
| 377 | * (33) An problem occurred with an alias. |
| 378 | */ |
| 379 | public final static int ALIAS_PROBLEM = 33; |
| 380 | |
| 381 | /** |
| 382 | * (34) The specified distinguished name (DN) uses invalid syntax. |
| 383 | */ |
| 384 | public final static int INVALID_DN_SYNTAX = 34; |
| 385 | |
| 386 | /** |
| 387 | * (35) The specified entry is a "leaf" entry (it has no entries |
| 388 | * beneath it in the directory tree). |
| 389 | */ |
| 390 | public final static int IS_LEAF = 35; |
| 391 | |
| 392 | /** |
| 393 | * (36) An error occurred when dereferencing an alias. |
| 394 | */ |
| 395 | public final static int ALIAS_DEREFERENCING_PROBLEM = 36; |
| 396 | |
| 397 | /** |
| 398 | * (48) The authentication presented to the server is inappropriate. |
| 399 | * This result code might occur, for example, if your client |
| 400 | * presents a password and the corresponding entry has no |
| 401 | * userpassword attribute. |
| 402 | */ |
| 403 | public final static int INAPPROPRIATE_AUTHENTICATION = 48; |
| 404 | |
| 405 | /** |
| 406 | * (49) The credentials presented to the server for authentication |
| 407 | * are not valid. (For example, the password sent to the server |
| 408 | * does not match the user's password in the directory.) |
| 409 | */ |
| 410 | public final static int INVALID_CREDENTIALS = 49; |
| 411 | |
| 412 | /** |
| 413 | * (50) The client is authenticated as a user who does not have the |
| 414 | * access privileges to perform this operation. |
| 415 | */ |
| 416 | public final static int INSUFFICIENT_ACCESS_RIGHTS = 50; |
| 417 | |
| 418 | /** |
| 419 | * (51) The LDAP server is busy. |
| 420 | */ |
| 421 | public final static int BUSY = 51; |
| 422 | |
| 423 | /** |
| 424 | * (52) The LDAP server is unavailable. |
| 425 | */ |
| 426 | public final static int UNAVAILABLE = 52; |
| 427 | |
| 428 | /** |
| 429 | * (53) The LDAP server is unable to perform the specified operation. |
| 430 | */ |
| 431 | public final static int UNWILLING_TO_PERFORM = 53; |
| 432 | |
| 433 | /** |
| 434 | * (54) A loop has been detected. |
| 435 | */ |
| 436 | public final static int LOOP_DETECT = 54; |
| 437 | |
| 438 | /** |
| 439 | * (60) The "server-side sorting" control |
| 440 | * was not included with the "virtual list view" |
| 441 | * control in the search request. |
| 442 | */ |
| 443 | public final static int SORT_CONTROL_MISSING = 60; |
| 444 | |
| 445 | /** |
| 446 | * (61) An index range error occurred. |
| 447 | */ |
| 448 | public final static int INDEX_RANGE_ERROR = 61; |
| 449 | |
| 450 | /** |
| 451 | * (64) A naming violation has occurred. |
| 452 | */ |
| 453 | public final static int NAMING_VIOLATION = 64; |
| 454 | |
| 455 | /** |
| 456 | * (65) The requested operation will add or change |
| 457 | * data so that the data no longer complies with |
| 458 | * the schema. |
| 459 | */ |
| 460 | public final static int OBJECT_CLASS_VIOLATION = 65; |
| 461 | |
| 462 | /** |
| 463 | * (66) The requested operation can only be performed |
| 464 | * on an entry that has no entries beneath it in the |
| 465 | * directory tree (in other words, a "leaf" entry). |
| 466 | * <P> |
| 467 | * |
| 468 | * For example, you cannot delete or rename an entry |
| 469 | * if the entry has subentries beneath it. |
| 470 | * <P> |
| 471 | */ |
| 472 | public final static int NOT_ALLOWED_ON_NONLEAF = 66; |
| 473 | |
| 474 | /** |
| 475 | * (67) The specified operation cannot be performed on |
| 476 | * a relative distinguished name (RDN). |
| 477 | */ |
| 478 | public final static int NOT_ALLOWED_ON_RDN = 67; |
| 479 | |
| 480 | /** |
| 481 | * (68) The specified entry already exists. You might receive |
| 482 | * this error if, for example, you attempt to add an entry |
| 483 | * that already exists or if you attempt to change the name |
| 484 | * of an entry to the name of an entry that already exists. |
| 485 | */ |
| 486 | public final static int ENTRY_ALREADY_EXISTS = 68; |
| 487 | |
| 488 | /** |
| 489 | * (69) You cannot modify the specified object class. |
| 490 | */ |
| 491 | public final static int OBJECT_CLASS_MODS_PROHIBITED = 69; |
| 492 | |
| 493 | /** |
| 494 | * (71) [LDAP v3] The client attempted to move an entry |
| 495 | * from one LDAP server to another by requesting a "modify |
| 496 | * DN" operation. In general, clients should not be able |
| 497 | * to arbitrarily move entries and subtrees between servers. |
| 498 | * <P> |
| 499 | * |
| 500 | * @see org.ietf.ldap.LDAPConnection#rename(java.lang.String, java.lang.String, java.lang.String, boolean) |
| 501 | * @see org.ietf.ldap.LDAPConnection#rename(java.lang.String, java.lang.String, java.lang.String, boolean, LDAPConstraints) |
| 502 | */ |
| 503 | public final static int AFFECTS_MULTIPLE_DSAS = 71; |
| 504 | |
| 505 | /** |
| 506 | * (80) General result code for other types of errors |
| 507 | * that may occur. |
| 508 | */ |
| 509 | public final static int OTHER = 80; |
| 510 | |
| 511 | /** |
| 512 | * (81) The LDAP server cannot be contacted. |
| 513 | */ |
| 514 | public final static int SERVER_DOWN = 0x51; |
| 515 | |
| 516 | /** |
| 517 | * (85) The operation could not be completed within the |
| 518 | * maximum time limit. You can specify the maximum time limit |
| 519 | * by calling the <CODE>LDAPConstraints.setTimeLimit</CODE> |
| 520 | * method.<P> |
| 521 | * |
| 522 | * @see org.ietf.ldap.LDAPConstraints#setTimeLimit |
| 523 | */ |
| 524 | public final static int LDAP_TIMEOUT = 0x55; |
| 525 | |
| 526 | |
| 527 | /** |
| 528 | * (89) When calling a constructor or method from your client, |
| 529 | * one or more parameters were incorrectly specified. |
| 530 | */ |
| 531 | public final static int PARAM_ERROR = 0x59; |
| 532 | |
| 533 | /** |
| 534 | * (91) Your LDAP client failed to connect to the LDAP server. |
| 535 | */ |
| 536 | public final static int CONNECT_ERROR = 0x5b; |
| 537 | |
| 538 | /** |
| 539 | * (92) The request is not supported by this version of the LDAP protocol. |
| 540 | */ |
| 541 | public final static int LDAP_NOT_SUPPORTED = 0x5c; |
| 542 | |
| 543 | /** |
| 544 | * (93) The requested control is not found. |
| 545 | * <P> |
| 546 | * |
| 547 | * @see org.ietf.ldap.LDAPControl |
| 548 | */ |
| 549 | public final static int CONTROL_NOT_FOUND = 0x5d; |
| 550 | |
| 551 | /** |
| 552 | * (94) No results have been returned from the server. |
| 553 | */ |
| 554 | public final static int NO_RESULTS_RETURNED = 0x5e; |
| 555 | |
| 556 | /** |
| 557 | * (95) More results are being returned from the server. |
| 558 | */ |
| 559 | public final static int MORE_RESULTS_TO_RETURN = 0x5f; |
| 560 | |
| 561 | /** |
| 562 | * (96) Your LDAP client detected a loop in the referral. |
| 563 | */ |
| 564 | public final static int CLIENT_LOOP = 0x60; |
| 565 | |
| 566 | /** |
| 567 | * (97) The number of sequential referrals (for example, |
| 568 | * the client may be referred first from LDAP server A to |
| 569 | * LDAP server B, then from LDAP server B to LDAP server C, |
| 570 | * and so on) has exceeded the maximum number of referrals |
| 571 | * (the <CODE>LDAPConnection.REFERRALS_HOP_LIMIT</CODE> option). |
| 572 | * <P> |
| 573 | * |
| 574 | * @see org.ietf.ldap.LDAPConnection#REFERRALS_HOP_LIMIT |
| 575 | * @see org.ietf.ldap.LDAPConnection#getOption |
| 576 | * @see org.ietf.ldap.LDAPConnection#setOption |
| 577 | */ |
| 578 | public final static int REFERRAL_LIMIT_EXCEEDED = 0x61; |
| 579 | |
| 580 | /** |
| 581 | * (100) Invalid response |
| 582 | */ |
| 583 | public final static int INVALID_RESPONSE = 0x64; |
| 584 | |
| 585 | /** |
| 586 | * (101) Ambiguous response |
| 587 | */ |
| 588 | public final static int AMBIGUOUS_RESPONSE = 0x65; |
| 589 | |
| 590 | /** |
| 591 | * (112) This implementation does not support TLS |
| 592 | */ |
| 593 | public final static int TLS_NOT_SUPPORTED = 0x70; |
| 594 | |
| 595 | /** |
| 596 | * Internal variables |
| 597 | */ |
| 598 | private int resultCode = -1; |
| 599 | private String errorMessage = null; |
| 600 | private String matchedDN = null; |
| 601 | private Throwable rootException = null; |
| 602 | private Locale m_locale = Locale.getDefault(); |
| 603 | private static Hashtable<String, PropertyResourceBundle> cacheResource = new Hashtable<>(); |
| 604 | private static final String baseName = "org/ietf/ldap/errors/ErrorCodes"; |
| 605 | |
| 606 | /** |
| 607 | * Constructs a default exception with no specific error information. |
| 608 | */ |
| 609 | public LDAPException() { |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * Constructs an exception with a specified string of |
| 614 | * additional information. This string appears if you call |
| 615 | * the <CODE>toString()</CODE> method. |
| 616 | * <P> |
| 617 | * |
| 618 | * This form is used for lower-level errors. |
| 619 | * It is recommended that you always use one of the constructors |
| 620 | * that takes a result code as a parameter. (If your exception is |
| 621 | * thrown, any code that catches the exception may need to extract |
| 622 | * the result code from the exception.) |
| 623 | * <P> |
| 624 | * @param message the additional error information |
| 625 | * @see org.ietf.ldap.LDAPException#toString() |
| 626 | */ |
| 627 | public LDAPException( String message ) { |
| 628 | super( message ); |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Constructs an exception with a result code and |
| 633 | * a specified string of additional information. This string |
| 634 | * appears if you call the <CODE>toString()</CODE> method. |
| 635 | * The result code that you set is accessible through the |
| 636 | * <CODE>getResultCode()</CODE> method. |
| 637 | * <P> |
| 638 | * |
| 639 | * @param message the additional error information to specify |
| 640 | * @param resultCode the result code returned from the |
| 641 | * operation that caused this exception |
| 642 | * @see org.ietf.ldap.LDAPException#toString() |
| 643 | * @see org.ietf.ldap.LDAPException#getResultCode() |
| 644 | */ |
| 645 | public LDAPException( String message, int resultCode ) { |
| 646 | super( message ); |
| 647 | this.resultCode = resultCode; |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * Constructs an exception with a result code, a specified |
| 652 | * string of additional information, and a string containing |
| 653 | * information passed back from the server. |
| 654 | * <P> |
| 655 | * |
| 656 | * After you construct the <CODE>LDAPException</CODE> object, |
| 657 | * the result code and messages will be accessible through the |
| 658 | * following ways: |
| 659 | * <P> |
| 660 | * <UL> |
| 661 | * <LI>The first string of additional information appears if you |
| 662 | * call the <CODE>toString()</CODE> method. <P> |
| 663 | * <LI>The result code that you set is accessible through the |
| 664 | * <CODE>getResultCode()</CODE> method. <P> |
| 665 | * <LI>The string of server error information that you set |
| 666 | * is accessible through the <CODE>getLDAPErrorMessage</CODE> |
| 667 | * method. <P> |
| 668 | * </UL> |
| 669 | * <P> |
| 670 | * |
| 671 | * Use this form of the constructor |
| 672 | * for higher-level LDAP operational errors. |
| 673 | * @param message the additional error information to specify |
| 674 | * @param resultCode the result code returned from the |
| 675 | * operation that caused this exception |
| 676 | * @param serverErrorMessage error message specifying additional |
| 677 | * information returned from the server |
| 678 | * @see org.ietf.ldap.LDAPException#toString() |
| 679 | * @see org.ietf.ldap.LDAPException#getResultCode() |
| 680 | * @see org.ietf.ldap.LDAPException#getLDAPErrorMessage() |
| 681 | */ |
| 682 | public LDAPException( String message, |
| 683 | int resultCode, |
| 684 | String serverErrorMessage ) { |
| 685 | super( message ); |
| 686 | this.resultCode = resultCode; |
| 687 | this.errorMessage = serverErrorMessage; |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Constructs an exception with a result code, a specified |
| 692 | * string of additional information, and a root cause exception. |
| 693 | * <P> |
| 694 | * |
| 695 | * After you construct the <CODE>LDAPException</CODE> object, |
| 696 | * the result code and messages will be accessible through the |
| 697 | * following ways: |
| 698 | * <P> |
| 699 | * <UL> |
| 700 | * <LI>The first string of additional information appears if you |
| 701 | * call the <CODE>toString()</CODE> method. <P> |
| 702 | * <LI>The result code that you set is accessible through the |
| 703 | * <CODE>getResultCode()</CODE> method. <P> |
| 704 | * </UL> |
| 705 | * <P> |
| 706 | * |
| 707 | * Use this form of the constructor |
| 708 | * for higher-level LDAP operational errors. |
| 709 | * @param message the additional error information to specify |
| 710 | * @param resultCode the result code returned from the |
| 711 | * operation that caused this exception |
| 712 | * @param rootException An exception which caused the failure, if any |
| 713 | * @see org.ietf.ldap.LDAPException#toString() |
| 714 | * @see org.ietf.ldap.LDAPException#getResultCode() |
| 715 | * @see org.ietf.ldap.LDAPException#getLDAPErrorMessage() |
| 716 | */ |
| 717 | public LDAPException( String message, |
| 718 | int resultCode, |
| 719 | Throwable rootException ) { |
| 720 | super( message ); |
| 721 | this.resultCode = resultCode; |
| 722 | this.rootException = rootException; |
| 723 | } |
| 724 | |
| 725 | /** |
| 726 | * Constructs an exception with a result code, a specified |
| 727 | * string of additional information, and the DN of the |
| 728 | * closest matching entry. The latter only if the exception was thrown |
| 729 | * because an entry could not be found (for example, if |
| 730 | * <CODE>cn=Babs Jensen,ou=People,c=Airius.com</CODE> could not be found |
| 731 | * but <CODE>ou=People,c=Airius.com</CODE> is a valid directory entry, |
| 732 | * the "matched DN" is <CODE>ou=People,c=Airius.com</CODE>. |
| 733 | * <P> |
| 734 | * |
| 735 | * After you construct the <CODE>LDAPException</CODE> object, |
| 736 | * the result code and messages will be accessible through the |
| 737 | * following ways: |
| 738 | * <P> |
| 739 | * <UL> |
| 740 | * <LI>This string of additional information appears if you |
| 741 | * call the <CODE>toString()</CODE> method. <P> |
| 742 | * <LI>The result code that you set is accessible through the |
| 743 | * <CODE>getResultCode()</CODE> method. <P> |
| 744 | * <LI>The string of server error information that you set |
| 745 | * is accessible through the <CODE>getLDAPErrorMessage</CODE> |
| 746 | * method. <P> |
| 747 | * <LI>The matched DN that you set is accessible through the |
| 748 | * <CODE>getMatchedDN</CODE> method.<P> |
| 749 | * </UL> |
| 750 | * <P> |
| 751 | * |
| 752 | * This form is used for higher-level LDAP operational errors. |
| 753 | * @param message the additional error information |
| 754 | * @param resultCode the result code returned |
| 755 | * @param matchedDN maximal subset of a specified DN which could be |
| 756 | * matched by the server |
| 757 | * @see org.ietf.ldap.LDAPException#toString() |
| 758 | * @see org.ietf.ldap.LDAPException#getResultCode() |
| 759 | * @see org.ietf.ldap.LDAPException#getLDAPErrorMessage() |
| 760 | * @see org.ietf.ldap.LDAPException#getMatchedDN() |
| 761 | */ |
| 762 | public LDAPException( String message, |
| 763 | String serverErrorMessage, |
| 764 | String matchedDN ) { |
| 765 | super( message ); |
| 766 | this.resultCode = resultCode; |
| 767 | this.matchedDN = matchedDN; |
| 768 | } |
| 769 | |
| 770 | /** |
| 771 | * Constructs an exception with a result code, a specified |
| 772 | * string of additional information, a string containing |
| 773 | * information passed back from the server, and the DN of the |
| 774 | * closest matching entry. The latter only if the exception was thrown |
| 775 | * because an entry could not be found (for example, if |
| 776 | * <CODE>cn=Babs Jensen,ou=People,c=Airius.com</CODE> could not be found |
| 777 | * but <CODE>ou=People,c=Airius.com</CODE> is a valid directory entry, |
| 778 | * the "matched DN" is <CODE>ou=People,c=Airius.com</CODE>. |
| 779 | * <P> |
| 780 | * |
| 781 | * After you construct the <CODE>LDAPException</CODE> object, |
| 782 | * the result code and messages will be accessible through the |
| 783 | * following ways: |
| 784 | * <P> |
| 785 | * <UL> |
| 786 | * <LI>This string of additional information appears if you |
| 787 | * call the <CODE>toString()</CODE> method. <P> |
| 788 | * <LI>The result code that you set is accessible through the |
| 789 | * <CODE>getResultCode()</CODE> method. <P> |
| 790 | * <LI>The string of server error information that you set |
| 791 | * is accessible through the <CODE>getLDAPErrorMessage</CODE> |
| 792 | * method. <P> |
| 793 | * <LI>The matched DN that you set is accessible through the |
| 794 | * <CODE>getMatchedDN</CODE> method.<P> |
| 795 | * </UL> |
| 796 | * <P> |
| 797 | * |
| 798 | * This form is used for higher-level LDAP operational errors. |
| 799 | * @param message the additional error information |
| 800 | * @param resultCode the result code returned |
| 801 | * @param serverErrorMessage error message specifying additional information |
| 802 | * returned from the server |
| 803 | * @param matchedDN maximal subset of a specified DN which could be |
| 804 | * matched by the server |
| 805 | * @see org.ietf.ldap.LDAPException#toString() |
| 806 | * @see org.ietf.ldap.LDAPException#getResultCode() |
| 807 | * @see org.ietf.ldap.LDAPException#getLDAPErrorMessage() |
| 808 | * @see org.ietf.ldap.LDAPException#getMatchedDN() |
| 809 | */ |
| 810 | public LDAPException( String message, |
| 811 | int resultCode, |
| 812 | String serverErrorMessage, |
| 813 | String matchedDN ) { |
| 814 | super( message ); |
| 815 | this.resultCode = resultCode; |
| 816 | this.errorMessage = serverErrorMessage; |
| 817 | this.matchedDN = matchedDN; |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * Constructs an exception with a result code, a specified |
| 822 | * string of additional information, a string containing |
| 823 | * information passed back from the server, and a possible root |
| 824 | * exception. |
| 825 | * <P> |
| 826 | * |
| 827 | * After you construct the <CODE>LDAPException</CODE> object, |
| 828 | * the result code and messages will be accessible through the |
| 829 | * following ways: |
| 830 | * <P> |
| 831 | * <UL> |
| 832 | * <LI>This string of additional information appears if you |
| 833 | * call the <CODE>toString()</CODE> method. <P> |
| 834 | * <LI>The result code that you set is accessible through the |
| 835 | * <CODE>getResultCode()</CODE> method. <P> |
| 836 | * <LI>The string of server error information that you set |
| 837 | * is accessible through the <CODE>getLDAPErrorMessage</CODE> |
| 838 | * method. <P> |
| 839 | * </UL> |
| 840 | * <P> |
| 841 | * |
| 842 | * This form is used for higher-level LDAP operational errors. |
| 843 | * @param message the additional error information |
| 844 | * @param resultCode the result code returned |
| 845 | * @param serverErrorMessage error message specifying additional information |
| 846 | * returned from the server |
| 847 | * @param rootException An exception which caused the failure, if any |
| 848 | * @see org.ietf.ldap.LDAPException#toString() |
| 849 | * @see org.ietf.ldap.LDAPException#getResultCode() |
| 850 | * @see org.ietf.ldap.LDAPException#getLDAPErrorMessage() |
| 851 | * @see org.ietf.ldap.LDAPException#getMatchedDN() |
| 852 | */ |
| 853 | public LDAPException( String message, |
| 854 | int resultCode, |
| 855 | String serverErrorMessage, |
| 856 | Throwable rootException ) { |
| 857 | super( message ); |
| 858 | this.resultCode = resultCode; |
| 859 | this.errorMessage = serverErrorMessage; |
| 860 | this.rootException = rootException; |
| 861 | } |
| 862 | |
| 863 | /** |
| 864 | * Returns the root exception that caused this exception. |
| 865 | * @return The possibly null root exception that caused this exception. |
| 866 | */ |
| 867 | public Throwable getCause() { |
| 868 | return rootException; |
| 869 | } |
| 870 | |
| 871 | /** |
| 872 | * Returns the error message from the last error, if this message |
| 873 | * is available (that is, if this message was set). If the message |
| 874 | * was not set, this method returns <CODE>null</CODE>. |
| 875 | * <P> |
| 876 | * |
| 877 | * Note that this message is rarely set. (In order to set this message, |
| 878 | * the code constructing this exception must have called the constructor |
| 879 | * <CODE>LDAPException(String, int, String)</CODE>. The last argument, |
| 880 | * which is additional error information returned from the server, |
| 881 | * is the string returned by <CODE>getLDAPErrorMessage</CODE>. |
| 882 | * <P> |
| 883 | * |
| 884 | * In most cases, if you want information about |
| 885 | * the error generated, you should call the <CODE>toString()</CODE> |
| 886 | * method instead. |
| 887 | * <P> |
| 888 | * |
| 889 | * @return the error message of the last error (or <CODE>null</CODE> |
| 890 | * if no message was set). |
| 891 | * @see org.ietf.ldap.LDAPException#toString() |
| 892 | */ |
| 893 | public String getLDAPErrorMessage () { |
| 894 | return errorMessage; |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * Returns the maximal subset of a DN which could be matched by the |
| 899 | * server. This only the case if the server returned one of the following |
| 900 | * errors: |
| 901 | * <UL> |
| 902 | * <LI><CODE>NO_SUCH_OBJECT</CODE> |
| 903 | * <LI><CODE>ALIAS_PROBLEM</CODE> |
| 904 | * <LI><CODE>INVALID_DN_SYNTAX</CODE> |
| 905 | * <LI><CODE>ALIAS_DEREFERENCING_PROBLEM</CODE> |
| 906 | * </UL> |
| 907 | * </PRE> |
| 908 | * For example, if the DN <CODE>cn=Babs Jensen, o=People, c=Airius.com</CODE> |
| 909 | * could not be found by the DN <CODE>o=People, c=Airius.com</CODE> |
| 910 | * could be found, the matched DN is |
| 911 | * <CODE>o=People, c=Airius.com</CODE>. |
| 912 | * <P> |
| 913 | * |
| 914 | * If the exception does not specify a matching DN, |
| 915 | * this method returns <CODE>null</CODE>. |
| 916 | * @return the maximal subset of a DN which could be matched, |
| 917 | * or <CODE>null</CODE> if the error is not one of the above. |
| 918 | */ |
| 919 | public String getMatchedDN () { |
| 920 | return matchedDN; |
| 921 | } |
| 922 | |
| 923 | /** |
| 924 | * Returns the result code from the last error that occurred. |
| 925 | * This result code is defined as a public final static int member |
| 926 | * of this class. Note that this value is not always valid. |
| 927 | * -1 indicates that the result code is invalid. |
| 928 | * @return the LDAP result code of the last operation. |
| 929 | */ |
| 930 | public int getResultCode () { |
| 931 | return resultCode; |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * Prints this exception's stack trace to <tt>System.err</tt>. |
| 936 | * If this exception has a root exception; the stack trace of the |
| 937 | * root exception is printed to <tt>System.err</tt> instead. |
| 938 | */ |
| 939 | public void printStackTrace() { |
| 940 | printStackTrace( System.err ); |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * Prints this exception's stack trace to a print stream. |
| 945 | * If this exception has a root exception; the stack trace of the |
| 946 | * root exception is printed to the print stream instead. |
| 947 | * @param ps The non-null print stream to which to print. |
| 948 | */ |
| 949 | public void printStackTrace(java.io.PrintStream ps) { |
| 950 | if ( rootException != null ) { |
| 951 | String superString = super.toString(); |
| 952 | synchronized ( ps ) { |
| 953 | ps.print(superString |
| 954 | + (superString.endsWith(".") ? "" : ".") |
| 955 | + " Root exception is "); |
| 956 | rootException.printStackTrace( ps ); |
| 957 | } |
| 958 | } else { |
| 959 | super.printStackTrace( ps ); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | /** |
| 964 | * Prints this exception's stack trace to a print writer. |
| 965 | * If this exception has a root exception; the stack trace of the |
| 966 | * root exception is printed to the print writer instead. |
| 967 | * @param ps The non-null print writer to which to print. |
| 968 | */ |
| 969 | public void printStackTrace( java.io.PrintWriter pw ) { |
| 970 | if ( rootException != null ) { |
| 971 | String superString = super.toString(); |
| 972 | synchronized (pw) { |
| 973 | pw.print(superString |
| 974 | + (superString.endsWith(".") ? "" : ".") |
| 975 | + " Root exception is "); |
| 976 | rootException.printStackTrace( pw ); |
| 977 | } |
| 978 | } else { |
| 979 | super.printStackTrace( pw ); |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | /** |
| 984 | * Returns the error message describing the error code (for this |
| 985 | * exception). The error message is specific to the default locale |
| 986 | * for this system. (The LDAP Java classes determine the default |
| 987 | * locale by calling the <CODE>java.util.Locale.getDefault</CODE> |
| 988 | * method and retrieve the error messages from the following file: |
| 989 | * <PRE>netscape/ldap/error/ErrorCodes_<I>locale_name</I>.props</PRE> |
| 990 | * where <I>locale_name</I> is the language and country (concatenated |
| 991 | * and delimited by an underscore) of the default locale. For example: |
| 992 | * <PRE>netscape/ldap/error/ErrorCodes_en_US.props</PRE> |
| 993 | * |
| 994 | * @return the error message describing the error code for this |
| 995 | * exception in the default locale. |
| 996 | */ |
| 997 | public String resultCodeToString() { |
| 998 | return resultCodeToString( resultCode, m_locale ); |
| 999 | } |
| 1000 | |
| 1001 | /** |
| 1002 | * Returns the error message describing the error code for this |
| 1003 | * exception. The error message for the specified locale is retrieved |
| 1004 | * from the following file: |
| 1005 | * <PRE>netscape/ldap/error/ErrorCodes_<I>locale_name</I>.props</PRE> |
| 1006 | * where <I>locale_name</I> is the language and country (concatenated |
| 1007 | * and delimited by an underscore) of the default locale. For example: |
| 1008 | * <PRE>netscape/ldap/error/ErrorCodes_en_US.props</PRE> |
| 1009 | * |
| 1010 | * @param l the <CODE>java.util.Locale</CODE> object representing the |
| 1011 | * locale of the error message to retrieve |
| 1012 | * @return the error message describing the current error code |
| 1013 | * in the specified locale. |
| 1014 | */ |
| 1015 | public String resultCodeToString( Locale l ) { |
| 1016 | return resultCodeToString( resultCode, l ); |
| 1017 | } |
| 1018 | |
| 1019 | /** |
| 1020 | * Returns the error message describing the specified error code. |
| 1021 | * The error message is specific to the default locale |
| 1022 | * for this system. (The LDAP Java classes determine the default |
| 1023 | * locale by calling the <CODE>java.util.Locale.getDefault</CODE> |
| 1024 | * method and retrieve the error messages from the following file: |
| 1025 | * <PRE>netscape/ldap/error/ErrorCodes_<I>locale_name</I>.props</PRE> |
| 1026 | * where <I>locale_name</I> is the language and country (concatenated |
| 1027 | * and delimited by an underscore) of the default locale. For example: |
| 1028 | * <PRE>netscape/ldap/error/ErrorCodes_en_US.props</PRE> |
| 1029 | * |
| 1030 | * @param code the error code for which to get the |
| 1031 | * corresponding error message |
| 1032 | * @return error message describing the specified error code for |
| 1033 | * the default locale. |
| 1034 | */ |
| 1035 | public static String resultCodeToString( int code ) { |
| 1036 | return resultCodeToString( code, Locale.getDefault() ); |
| 1037 | } |
| 1038 | |
| 1039 | /** |
| 1040 | * Returns the error message describing the specified error code. |
| 1041 | * The error message for the specified locale is retrieved from |
| 1042 | * the following file: |
| 1043 | * <PRE>netscape/ldap/error/ErrorCodes_<I>locale_name</I>.props</PRE> |
| 1044 | * where <I>locale_name</I> is the language and country (concatenated |
| 1045 | * and delimited by an underscore) of the default locale. For example: |
| 1046 | * <PRE>netscape/ldap/error/ErrorCodes_en_US.props</PRE> |
| 1047 | * |
| 1048 | * @param code the error code for which to get the |
| 1049 | * corresponding error |
| 1050 | * @param locale the <CODE>java.util.Locale</CODE> object representing the |
| 1051 | * locale of the error message that you want to retrieve |
| 1052 | * @return error message describing the specified error code for |
| 1053 | * the specified locale. |
| 1054 | */ |
| 1055 | public synchronized static String resultCodeToString( int code, |
| 1056 | Locale locale ) { |
| 1057 | try { |
| 1058 | String localeStr = locale.toString(); |
| 1059 | PropertyResourceBundle p = |
| 1060 | cacheResource.get(localeStr); |
| 1061 | |
| 1062 | if (p == null) { |
| 1063 | p = LDAPResourceBundle.getBundle(baseName); |
| 1064 | |
| 1065 | if (p != null) |
| 1066 | cacheResource.put(localeStr, p); |
| 1067 | } |
| 1068 | |
| 1069 | if (p != null) { |
| 1070 | return (String)p.handleGetObject(Integer.toString(code)); |
| 1071 | } |
| 1072 | } catch (IOException e) { |
| 1073 | System.out.println("Cannot open resource file for LDAPException "+ |
| 1074 | baseName); |
| 1075 | } |
| 1076 | |
| 1077 | return null; |
| 1078 | } |
| 1079 | |
| 1080 | /** |
| 1081 | * Gets the string representation of the exception, which |
| 1082 | * includes the result code, the message sent back from |
| 1083 | * the LDAP server, the portion of the DN that the server |
| 1084 | * could find in the directory (if applicable), and the |
| 1085 | * error message corresponding to this result code. |
| 1086 | * <P> |
| 1087 | * |
| 1088 | * For example: |
| 1089 | * |
| 1090 | * <PRE>org.ietf.ldap.LDAPException: error result (32); server error message; matchedDN = ou=people,o=airius.com; No such object</PRE> |
| 1091 | * |
| 1092 | * In this example, <CODE>error result</CODE> is the string of |
| 1093 | * additional information specified in the exception, <CODE>32</CODE> is |
| 1094 | * the result code, <CODE>server error message</CODE> is the additional |
| 1095 | * information from the server specified in the exception, the |
| 1096 | * matched DN is <CODE>ou=people,o=airius.com</CODE>, and the error message |
| 1097 | * corresponding to the result code <CODE>32</CODE> is <CODE>No such |
| 1098 | * object</CODE>. |
| 1099 | * <P> |
| 1100 | * |
| 1101 | * The error message corresponding to the error code can also be |
| 1102 | * retrieved by using the <CODE>resultCodeToString</CODE> method. |
| 1103 | * Note that this method can generate error messages specific to |
| 1104 | * a current locale. |
| 1105 | * <P> |
| 1106 | * |
| 1107 | * @return string representation of exception. |
| 1108 | * @see org.ietf.ldap.LDAPException#resultCodeToString(int) |
| 1109 | */ |
| 1110 | public String toString() { |
| 1111 | String str = super.toString() + " (" + resultCode + ")" ; |
| 1112 | if ( (errorMessage != null) && (errorMessage.length() > 0) ) { |
| 1113 | str += "; " + errorMessage; |
| 1114 | } |
| 1115 | if ( (matchedDN != null) && (matchedDN.length() > 0) ) { |
| 1116 | str += "; matchedDN = " + matchedDN; |
| 1117 | } |
| 1118 | if ( (rootException != null) && (rootException != this) ) { |
| 1119 | str += " [Root exception is " + rootException.toString() + "]"; |
| 1120 | } |
| 1121 | return str; |
| 1122 | } |
| 1123 | } |