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