001/*
002 * Copyright 2011-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2011-2024 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2011-2024 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk;
037
038
039
040import com.unboundid.util.LDAPSDKRuntimeException;
041import com.unboundid.util.NotMutable;
042import com.unboundid.util.NotNull;
043import com.unboundid.util.Nullable;
044import com.unboundid.util.ThreadSafety;
045import com.unboundid.util.ThreadSafetyLevel;
046
047
048
049/**
050 * This class defines a version of the {@link LDAPException} class that may be
051 * thrown as a {@code RuntimeException} without the need for it to have been
052 * explicitly declared in the method's throws list.
053 */
054@NotMutable()
055@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
056public final class LDAPRuntimeException
057       extends LDAPSDKRuntimeException
058{
059  /**
060   * The serial version UID for this serializable class.
061   */
062  private static final long serialVersionUID = 6201514484547092642L;
063
064
065
066  // The LDAPException object wrapped by this runtime exception.
067  @NotNull private final LDAPException ldapException;
068
069
070
071  /**
072   * Creates a new instance of this {@code LDAPRuntimeException} using the
073   * provided {@code LDAPException}.
074   *
075   * @param  ldapException  The {@code LDAPException} object wrapped by this
076   *                        runtime exception.
077   */
078  public LDAPRuntimeException(@NotNull final LDAPException ldapException)
079  {
080    super(ldapException.getMessage(), ldapException.getCause());
081
082    this.ldapException = ldapException;
083  }
084
085
086
087  /**
088   * Retrieves the {@code LDAPException} object wrapped by this runtime
089   * exception.
090   *
091   * @return  The {@code LDAPException} object wrapped by this runtime
092   *          exception.
093   */
094  @NotNull()
095  public LDAPException getLDAPException()
096  {
097    return ldapException;
098  }
099
100
101
102  /**
103   * Throws the wrapped {@code LDAPException} object.
104   *
105   * @throws  LDAPException  The wrapped {@code LDAPException} object.
106   */
107  public void throwLDAPException()
108         throws LDAPException
109  {
110    throw ldapException;
111  }
112
113
114
115  /**
116   * Retrieves the result code for this LDAP exception.
117   *
118   * @return  The result code for this LDAP exception.
119   */
120  @NotNull()
121  public ResultCode getResultCode()
122  {
123    return ldapException.getResultCode();
124  }
125
126
127
128  /**
129   * Retrieves the matched DN for this LDAP exception.
130   *
131   * @return  The matched DN for this LDAP exception, or {@code null} if there
132   *          is none.
133   */
134  @Nullable()
135  public String getMatchedDN()
136  {
137    return ldapException.getMatchedDN();
138  }
139
140
141
142  /**
143   * Retrieves the diagnostic message returned by the directory server.
144   *
145   * @return  The diagnostic message returned by the directory server, or
146   *          {@code null} if there is none.
147   */
148  @Nullable()
149  public String getDiagnosticMessage()
150  {
151    return ldapException.getDiagnosticMessage();
152  }
153
154
155
156  /**
157   * Retrieves the set of referral URLs for this LDAP exception.
158   *
159   * @return  The set of referral URLs for this LDAP exception, or an empty
160   *          array if there are none.
161   */
162  @NotNull()
163  public String[] getReferralURLs()
164  {
165    return ldapException.getReferralURLs();
166  }
167
168
169
170  /**
171   * Indicates whether this result contains at least one control.
172   *
173   * @return  {@code true} if this result contains at least one control, or
174   *          {@code false} if not.
175   */
176  public boolean hasResponseControl()
177  {
178    return ldapException.hasResponseControl();
179  }
180
181
182
183  /**
184   * Indicates whether this result contains at least one control with the
185   * specified OID.
186   *
187   * @param  oid  The object identifier for which to make the determination.  It
188   *              must not be {@code null}.
189   *
190   * @return  {@code true} if this result contains at least one control with
191   *          the specified OID, or {@code false} if not.
192   */
193  public boolean hasResponseControl(@NotNull final String oid)
194  {
195    return ldapException.hasResponseControl(oid);
196  }
197
198
199
200  /**
201   * Retrieves the set of response controls for this LDAP exception.
202   *
203   * @return  The set of response controls for this LDAP exception, or an empty
204   *          array if there are none.
205   */
206  @NotNull()
207  public Control[] getResponseControls()
208  {
209    return ldapException.getResponseControls();
210  }
211
212
213
214  /**
215   * Retrieves the response control with the specified OID.
216   *
217   * @param  oid  The OID of the control to retrieve.
218   *
219   * @return  The response control with the specified OID, or {@code null} if
220   *          there is no such control.
221   */
222  @Nullable()
223  public Control getResponseControl(@NotNull final String oid)
224  {
225    return ldapException.getResponseControl(oid);
226  }
227
228
229
230  /**
231   * Creates a new {@code LDAPResult} object from this exception.
232   *
233   * @return  The {@code LDAPResult} object created from this exception.
234   */
235  @NotNull()
236  public LDAPResult toLDAPResult()
237  {
238    return ldapException.toLDAPResult();
239  }
240
241
242
243  /**
244   * {@inheritDoc}
245   */
246  @Override()
247  public void toString(@NotNull final StringBuilder buffer)
248  {
249    ldapException.toString(buffer);
250  }
251
252
253
254  /**
255   * {@inheritDoc}
256   */
257  @Override()
258  @NotNull()
259  public String getExceptionMessage()
260  {
261    return ldapException.getExceptionMessage();
262  }
263
264
265
266  /**
267   * {@inheritDoc}
268   */
269  @Override()
270  @NotNull()
271  public String getExceptionMessage(final boolean includeStackTrace,
272                                    final boolean includeCause)
273  {
274    return ldapException.getExceptionMessage(includeStackTrace, includeCause);
275  }
276}