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.tools;
028 import org.opends.messages.Message;
029
030
031 import org.opends.server.types.DN;
032 import org.opends.server.types.OpenDsException;
033
034
035
036 /**
037 * This class defines an exception that may be thrown during the course of
038 * creating an LDAP connection to the server.
039 */
040 public class LDAPConnectionException extends OpenDsException {
041
042 /**
043 * The serial version identifier required to satisfy the compiler because this
044 * class extends <CODE>java.lang.Exception</CODE>, which implements the
045 * <CODE>java.io.Serializable</CODE> interface. This value was generated
046 * using the <CODE>serialver</CODE> command-line utility included with the
047 * Java SDK.
048 */
049 private static final long serialVersionUID = 3135563348838654570L;
050
051
052 /**
053 * The LDAP result code associated with the exception.
054 */
055 private final int resultCode;
056
057
058 /**
059 * The matched DN associated with the exception.
060 */
061 private final DN matchedDN;
062
063
064 /**
065 * The server-provided error message for this exception.
066 */
067 private final Message errorMessage;
068
069
070 /**
071 * Creates a new exception with the provided message.
072 *
073 * @param message The message to use for this exception.
074 */
075 public LDAPConnectionException(Message message)
076 {
077 super(message);
078
079 resultCode = -1;
080 matchedDN = null;
081 errorMessage = null;
082 }
083
084
085 /**
086 * Creates a new exception with the provided message.
087 *
088 * @param message The message to use for this exception.
089 * @param resultCode The result code for this exception.
090 * @param errorMessage The server-provided error message for this exception.
091 */
092 public LDAPConnectionException(Message message, int resultCode,
093 Message errorMessage)
094 {
095 super(message);
096
097 this.resultCode = resultCode;
098 this.errorMessage = errorMessage;
099
100 matchedDN = null;
101 }
102
103
104 /**
105 * Creates a new exception with the provided message and
106 * underlying cause.
107 *
108 * @param message The message to use for this exception.
109 * @param cause The underlying cause that triggered this
110 * exception.
111 */
112 public LDAPConnectionException(Message message, Throwable cause)
113 {
114 super(message, cause);
115
116 resultCode = -1;
117 matchedDN = null;
118 errorMessage = null;
119 }
120
121
122 /**
123 * Creates a new exception with the provided message and
124 * underlying cause.
125 *
126 * @param message The message to use for this exception.
127 * @param resultCode The result code for this exception.
128 * @param errorMessage The server-provided error message for this exception.
129 * @param cause The underlying cause that triggered this
130 * exception.
131 */
132 public LDAPConnectionException(Message message, int resultCode,
133 Message errorMessage, Throwable cause)
134 {
135 super(message, cause);
136
137 this.resultCode = resultCode;
138 this.errorMessage = errorMessage;
139
140 matchedDN = null;
141 }
142
143
144 /**
145 * Creates a new exception with the provided message and
146 * underlying cause.
147 *
148 * @param message The explanation to use for this exception.
149 * @param resultCode The result code for this exception.
150 * @param errorMessage The server-provided error message for this
151 * exception.
152 * @param matchedDN The matched DN string for this exception.
153 * @param cause The underlying cause that triggered this
154 * exception.
155 */
156 public LDAPConnectionException(Message message, int resultCode,
157 Message errorMessage, DN matchedDN,
158 Throwable cause)
159 {
160 super(message, cause);
161
162 this.resultCode = resultCode;
163 this.errorMessage = errorMessage;
164 this.matchedDN = matchedDN;
165 }
166
167
168 /**
169 * Return the result code associated with this exception.
170 *
171 * @return The result code associated with this exception, or -1 if none was
172 * provided.
173 */
174 public int getResultCode()
175 {
176 return this.resultCode;
177 }
178
179
180 /**
181 * Retrieves the server-provided error message associated with this exception.
182 *
183 * @return The server-provided error message associated with this exception.
184 */
185 public Message getErrorMessage()
186 {
187 return this.errorMessage;
188 }
189
190
191 /**
192 * Return the matched DN associated with this exception.
193 *
194 * @return The matched DN associated with this exception, or {@code null} if
195 * none was provided.
196 */
197 public DN getMatchedDN()
198 {
199 return this.matchedDN;
200 }
201 }
202