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