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.types;
018
019import org.forgerock.i18n.LocalizableMessage;
020import org.forgerock.opendj.ldap.DN;
021
022
023
024
025/**
026 * This class defines an exception that may be thrown if a problem
027 * occurs while interacting with an LDAP protocol element.
028 */
029@org.opends.server.types.PublicAPI(
030     stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
031     mayInstantiate=true,
032     mayExtend=false,
033     mayInvoke=true)
034public final class LDAPException
035       extends IdentifiedException
036{
037  /**
038   * The serial version identifier required to satisfy the compiler
039   * because this class extends {@code java.lang.Exception}, which
040   * implements the {@code java.io.Serializable} interface.  This
041   * value was generated using the {@code serialver} command-line
042   * utility included with the Java SDK.
043   */
044  private static final long serialVersionUID = -7273984376022613884L;
045
046
047
048  /** The matched DN associated with this LDAP exception. */
049  private final DN matchedDN;
050
051  /** The LDAP result code associated with this exception. */
052  private final int resultCode;
053
054  /** The server-provided error message for this LDAP exception. */
055  private final LocalizableMessage errorMessage;
056
057
058
059  /**
060   * Creates a new LDAP exception with the provided message.
061   *
062   * @param  resultCode  The LDAP result code associated with this
063   *                     exception.
064   * @param  message     The message that explains the problem that
065   *                     occurred.
066   */
067  public LDAPException(int resultCode, LocalizableMessage message)
068  {
069    super(message);
070
071    this.resultCode = resultCode;
072
073    errorMessage = null;
074    matchedDN    = null;
075  }
076
077
078
079  /**
080   * Creates a new LDAP exception with the provided message.
081   *
082   * @param  resultCode    The LDAP result code associated with this
083   *                       exception.
084   * @param  errorMessage  The server-provided error message.
085   * @param  message       The message that explains the problem that
086   *                       occurred.
087   */
088  public LDAPException(int resultCode, LocalizableMessage errorMessage,
089                       LocalizableMessage message)
090  {
091    super(message);
092
093    this.resultCode   = resultCode;
094    this.errorMessage = errorMessage;
095
096    matchedDN    = null;
097  }
098
099
100
101  /**
102   * Creates a new LDAP exception with the provided message and root
103   * cause.
104   *
105   * @param  resultCode  The LDAP result code associated with this
106   *                     exception.
107   * @param  message     The message that explains the problem that
108   *                     occurred.
109   * @param  cause       The exception that was caught to trigger this
110   *                     exception.
111   */
112  public LDAPException(int resultCode, LocalizableMessage message,
113                       Throwable cause)
114  {
115    super(message, cause);
116
117    this.resultCode = resultCode;
118
119    errorMessage = null;
120    matchedDN    = null;
121  }
122
123
124
125  /**
126   * Creates a new LDAP exception with the provided message and root
127   * cause.
128   *
129   * @param  resultCode    The LDAP result code associated with this
130   *                       exception.
131   * @param  errorMessage  The server-provided error message.
132   * @param  message       The message that explains the problem that
133   *                       occurred.
134   * @param  cause         The exception that was caught to trigger
135   *                       this exception.
136   */
137  public LDAPException(int resultCode, LocalizableMessage errorMessage,
138                       LocalizableMessage message, Throwable cause)
139  {
140    super(message, cause);
141
142    this.resultCode   = resultCode;
143    this.errorMessage = errorMessage;
144
145    matchedDN    = null;
146  }
147
148
149
150  /**
151   * Creates a new LDAP exception with the provided message and root
152   * cause.
153   *
154   * @param  resultCode    The LDAP result code associated with this
155   *                       exception.
156   * @param  errorMessage  The server-provided error message.
157   * @param  message       The message that explains the problem that
158   *                       occurred.
159   * @param  matchedDN     The matched DN returned by the server.
160   * @param  cause         The exception that was caught to trigger
161   *                       this exception.
162   */
163  public LDAPException(int resultCode, LocalizableMessage errorMessage,
164                       LocalizableMessage message, DN matchedDN,
165                       Throwable cause)
166  {
167    super(message, cause);
168
169    this.resultCode   = resultCode;
170    this.errorMessage = errorMessage;
171    this.matchedDN    = matchedDN;
172  }
173
174
175
176  /**
177   * Retrieves the LDAP result code associated with this exception.
178   *
179   * @return  The LDAP result code associated with this exception.
180   */
181  public int getResultCode()
182  {
183    return resultCode;
184  }
185
186
187
188  /**
189   * Retrieves the server-provided error message for this exception.
190   *
191   * @return  The server-provided error message for this exception, or
192   *          {@code null} if none was given.
193   */
194  public LocalizableMessage getErrorMessage()
195  {
196    return errorMessage;
197  }
198
199
200
201  /**
202   * Retrieves the matched DN for this exception.
203   *
204   * @return  The matched DN for this exception, or {@code null} if
205   *          there is none.
206   */
207  public DN getMatchedDN()
208  {
209    return matchedDN;
210  }
211}
212