001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2008 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027package org.opends.server.types; 028 029import org.forgerock.i18n.LocalizableMessage; 030 031 032 033 034/** 035 * This class defines an exception that may be thrown if a problem 036 * occurs while interacting with an LDAP protocol element. 037 */ 038@org.opends.server.types.PublicAPI( 039 stability=org.opends.server.types.StabilityLevel.UNCOMMITTED, 040 mayInstantiate=true, 041 mayExtend=false, 042 mayInvoke=true) 043public final class LDAPException 044 extends IdentifiedException 045{ 046 /** 047 * The serial version identifier required to satisfy the compiler 048 * because this class extends {@code java.lang.Exception}, which 049 * implements the {@code java.io.Serializable} interface. This 050 * value was generated using the {@code serialver} command-line 051 * utility included with the Java SDK. 052 */ 053 private static final long serialVersionUID = -7273984376022613884L; 054 055 056 057 /** The matched DN associated with this LDAP exception. */ 058 private final DN matchedDN; 059 060 /** The LDAP result code associated with this exception. */ 061 private final int resultCode; 062 063 /** The server-provided error message for this LDAP exception. */ 064 private final LocalizableMessage errorMessage; 065 066 067 068 /** 069 * Creates a new LDAP exception with the provided message. 070 * 071 * @param resultCode The LDAP result code associated with this 072 * exception. 073 * @param message The message that explains the problem that 074 * occurred. 075 */ 076 public LDAPException(int resultCode, LocalizableMessage message) 077 { 078 super(message); 079 080 this.resultCode = resultCode; 081 082 errorMessage = null; 083 matchedDN = null; 084 } 085 086 087 088 /** 089 * Creates a new LDAP exception with the provided message. 090 * 091 * @param resultCode The LDAP result code associated with this 092 * exception. 093 * @param errorMessage The server-provided error message. 094 * @param message The message that explains the problem that 095 * occurred. 096 */ 097 public LDAPException(int resultCode, LocalizableMessage errorMessage, 098 LocalizableMessage message) 099 { 100 super(message); 101 102 this.resultCode = resultCode; 103 this.errorMessage = errorMessage; 104 105 matchedDN = null; 106 } 107 108 109 110 /** 111 * Creates a new LDAP exception with the provided message and root 112 * cause. 113 * 114 * @param resultCode The LDAP result code associated with this 115 * exception. 116 * @param message The message that explains the problem that 117 * occurred. 118 * @param cause The exception that was caught to trigger this 119 * exception. 120 */ 121 public LDAPException(int resultCode, LocalizableMessage message, 122 Throwable cause) 123 { 124 super(message, cause); 125 126 this.resultCode = resultCode; 127 128 errorMessage = null; 129 matchedDN = null; 130 } 131 132 133 134 /** 135 * Creates a new LDAP exception with the provided message and root 136 * cause. 137 * 138 * @param resultCode The LDAP result code associated with this 139 * exception. 140 * @param errorMessage The server-provided error message. 141 * @param message The message that explains the problem that 142 * occurred. 143 * @param cause The exception that was caught to trigger 144 * this exception. 145 */ 146 public LDAPException(int resultCode, LocalizableMessage errorMessage, 147 LocalizableMessage message, Throwable cause) 148 { 149 super(message, cause); 150 151 this.resultCode = resultCode; 152 this.errorMessage = errorMessage; 153 154 matchedDN = null; 155 } 156 157 158 159 /** 160 * Creates a new LDAP exception with the provided message and root 161 * cause. 162 * 163 * @param resultCode The LDAP result code associated with this 164 * exception. 165 * @param errorMessage The server-provided error message. 166 * @param message The message that explains the problem that 167 * occurred. 168 * @param matchedDN The matched DN returned by the server. 169 * @param cause The exception that was caught to trigger 170 * this exception. 171 */ 172 public LDAPException(int resultCode, LocalizableMessage errorMessage, 173 LocalizableMessage message, DN matchedDN, 174 Throwable cause) 175 { 176 super(message, cause); 177 178 this.resultCode = resultCode; 179 this.errorMessage = errorMessage; 180 this.matchedDN = matchedDN; 181 } 182 183 184 185 /** 186 * Retrieves the LDAP result code associated with this exception. 187 * 188 * @return The LDAP result code associated with this exception. 189 */ 190 public int getResultCode() 191 { 192 return resultCode; 193 } 194 195 196 197 /** 198 * Retrieves the server-provided error message for this exception. 199 * 200 * @return The server-provided error message for this exception, or 201 * {@code null} if none was given. 202 */ 203 public LocalizableMessage getErrorMessage() 204 { 205 return errorMessage; 206 } 207 208 209 210 /** 211 * Retrieves the matched DN for this exception. 212 * 213 * @return The matched DN for this exception, or {@code null} if 214 * there is none. 215 */ 216 public DN getMatchedDN() 217 { 218 return matchedDN; 219 } 220} 221