001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2006-2008 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2016 ForgeRock AS. 016 */ 017package org.opends.server.tools; 018import org.forgerock.i18n.LocalizableMessage; 019 020 021import org.forgerock.opendj.ldap.DN; 022import org.opends.server.types.OpenDsException; 023 024 025 026/** 027 * This class defines an exception that may be thrown during the course of 028 * creating an LDAP connection to the server. 029 */ 030public class LDAPConnectionException extends OpenDsException { 031 032 /** 033 * The serial version identifier required to satisfy the compiler because this 034 * class extends <CODE>java.lang.Exception</CODE>, which implements the 035 * <CODE>java.io.Serializable</CODE> interface. This value was generated 036 * using the <CODE>serialver</CODE> command-line utility included with the 037 * Java SDK. 038 */ 039 private static final long serialVersionUID = 3135563348838654570L; 040 041 042 /** 043 * The LDAP result code associated with the exception. 044 */ 045 private final int resultCode; 046 047 048 /** 049 * The matched DN associated with the exception. 050 */ 051 private final DN matchedDN; 052 053 054 /** 055 * The server-provided error message for this exception. 056 */ 057 private final LocalizableMessage errorMessage; 058 059 060 /** 061 * Creates a new exception with the provided message. 062 * 063 * @param message The message to use for this exception. 064 */ 065 public LDAPConnectionException(LocalizableMessage message) 066 { 067 super(message); 068 069 resultCode = -1; 070 matchedDN = null; 071 errorMessage = null; 072 } 073 074 075 /** 076 * Creates a new exception with the provided message. 077 * 078 * @param message The message to use for this exception. 079 * @param resultCode The result code for this exception. 080 * @param errorMessage The server-provided error message for this exception. 081 */ 082 public LDAPConnectionException(LocalizableMessage message, int resultCode, 083 LocalizableMessage errorMessage) 084 { 085 super(message); 086 087 this.resultCode = resultCode; 088 this.errorMessage = errorMessage; 089 090 matchedDN = null; 091 } 092 093 094 /** 095 * Creates a new exception with the provided message and 096 * underlying cause. 097 * 098 * @param message The message to use for this exception. 099 * @param cause The underlying cause that triggered this 100 * exception. 101 */ 102 public LDAPConnectionException(LocalizableMessage message, Throwable cause) 103 { 104 super(message, cause); 105 106 resultCode = -1; 107 matchedDN = null; 108 errorMessage = null; 109 } 110 111 112 /** 113 * Creates a new exception with the provided message and 114 * underlying cause. 115 * 116 * @param message The message to use for this exception. 117 * @param resultCode The result code for this exception. 118 * @param errorMessage The server-provided error message for this exception. 119 * @param cause The underlying cause that triggered this 120 * exception. 121 */ 122 public LDAPConnectionException(LocalizableMessage message, int resultCode, 123 LocalizableMessage errorMessage, Throwable cause) 124 { 125 super(message, cause); 126 127 this.resultCode = resultCode; 128 this.errorMessage = errorMessage; 129 130 matchedDN = null; 131 } 132 133 134 /** 135 * Creates a new exception with the provided message and 136 * underlying cause. 137 * 138 * @param message The explanation to use for this exception. 139 * @param resultCode The result code for this exception. 140 * @param errorMessage The server-provided error message for this 141 * exception. 142 * @param matchedDN The matched DN string for this exception. 143 * @param cause The underlying cause that triggered this 144 * exception. 145 */ 146 public LDAPConnectionException(LocalizableMessage message, int resultCode, 147 LocalizableMessage errorMessage, DN matchedDN, 148 Throwable cause) 149 { 150 super(message, cause); 151 152 this.resultCode = resultCode; 153 this.errorMessage = errorMessage; 154 this.matchedDN = matchedDN; 155 } 156 157 158 /** 159 * Return the result code associated with this exception. 160 * 161 * @return The result code associated with this exception, or -1 if none was 162 * provided. 163 */ 164 public int getResultCode() 165 { 166 return this.resultCode; 167 } 168 169 170 /** 171 * Retrieves the server-provided error message associated with this exception. 172 * 173 * @return The server-provided error message associated with this exception. 174 */ 175 public LocalizableMessage getErrorMessage() 176 { 177 return this.errorMessage; 178 } 179 180 181 /** 182 * Return the matched DN associated with this exception. 183 * 184 * @return The matched DN associated with this exception, or {@code null} if 185 * none was provided. 186 */ 187 public DN getMatchedDN() 188 { 189 return this.matchedDN; 190 } 191} 192