001/* 002 * Copyright 2011-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2011-2020 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-2020 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.ThreadSafety; 043import com.unboundid.util.ThreadSafetyLevel; 044 045 046 047/** 048 * This class defines a version of the {@link LDAPException} class that may be 049 * thrown as a {@code RuntimeException} without the need for it to have been 050 * explicitly declared in the method's throws list. 051 */ 052@NotMutable() 053@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 054public final class LDAPRuntimeException 055 extends LDAPSDKRuntimeException 056{ 057 /** 058 * The serial version UID for this serializable class. 059 */ 060 private static final long serialVersionUID = 6201514484547092642L; 061 062 063 064 // The LDAPException object wrapped by this runtime exception. 065 private final LDAPException ldapException; 066 067 068 069 /** 070 * Creates a new instance of this {@code LDAPRuntimeException} using the 071 * provided {@code LDAPException}. 072 * 073 * @param ldapException The {@code LDAPException} object wrapped by this 074 * runtime exception. 075 */ 076 public LDAPRuntimeException(final LDAPException ldapException) 077 { 078 super(ldapException.getMessage(), ldapException.getCause()); 079 080 this.ldapException = ldapException; 081 } 082 083 084 085 /** 086 * Retrieves the {@code LDAPException} object wrapped by this runtime 087 * exception. 088 * 089 * @return The {@code LDAPException} object wrapped by this runtime 090 * exception. 091 */ 092 public LDAPException getLDAPException() 093 { 094 return ldapException; 095 } 096 097 098 099 /** 100 * Throws the wrapped {@code LDAPException} object. 101 * 102 * @throws LDAPException The wrapped {@code LDAPException} object. 103 */ 104 public void throwLDAPException() 105 throws LDAPException 106 { 107 throw ldapException; 108 } 109 110 111 112 /** 113 * Retrieves the result code for this LDAP exception. 114 * 115 * @return The result code for this LDAP exception. 116 */ 117 public ResultCode getResultCode() 118 { 119 return ldapException.getResultCode(); 120 } 121 122 123 124 /** 125 * Retrieves the matched DN for this LDAP exception. 126 * 127 * @return The matched DN for this LDAP exception, or {@code null} if there 128 * is none. 129 */ 130 public String getMatchedDN() 131 { 132 return ldapException.getMatchedDN(); 133 } 134 135 136 137 /** 138 * Retrieves the diagnostic message returned by the directory server. 139 * 140 * @return The diagnostic message returned by the directory server, or 141 * {@code null} if there is none. 142 */ 143 public String getDiagnosticMessage() 144 { 145 return ldapException.getDiagnosticMessage(); 146 } 147 148 149 150 /** 151 * Retrieves the set of referral URLs for this LDAP exception. 152 * 153 * @return The set of referral URLs for this LDAP exception, or an empty 154 * array if there are none. 155 */ 156 public String[] getReferralURLs() 157 { 158 return ldapException.getReferralURLs(); 159 } 160 161 162 163 /** 164 * Indicates whether this result contains at least one control. 165 * 166 * @return {@code true} if this result contains at least one control, or 167 * {@code false} if not. 168 */ 169 public boolean hasResponseControl() 170 { 171 return ldapException.hasResponseControl(); 172 } 173 174 175 176 /** 177 * Indicates whether this result contains at least one control with the 178 * specified OID. 179 * 180 * @param oid The object identifier for which to make the determination. It 181 * must not be {@code null}. 182 * 183 * @return {@code true} if this result contains at least one control with 184 * the specified OID, or {@code false} if not. 185 */ 186 public boolean hasResponseControl(final String oid) 187 { 188 return ldapException.hasResponseControl(oid); 189 } 190 191 192 193 /** 194 * Retrieves the set of response controls for this LDAP exception. 195 * 196 * @return The set of response controls for this LDAP exception, or an empty 197 * array if there are none. 198 */ 199 public Control[] getResponseControls() 200 { 201 return ldapException.getResponseControls(); 202 } 203 204 205 206 /** 207 * Retrieves the response control with the specified OID. 208 * 209 * @param oid The OID of the control to retrieve. 210 * 211 * @return The response control with the specified OID, or {@code null} if 212 * there is no such control. 213 */ 214 public Control getResponseControl(final String oid) 215 { 216 return ldapException.getResponseControl(oid); 217 } 218 219 220 221 /** 222 * Creates a new {@code LDAPResult} object from this exception. 223 * 224 * @return The {@code LDAPResult} object created from this exception. 225 */ 226 public LDAPResult toLDAPResult() 227 { 228 return ldapException.toLDAPResult(); 229 } 230 231 232 233 /** 234 * {@inheritDoc} 235 */ 236 @Override() 237 public void toString(final StringBuilder buffer) 238 { 239 ldapException.toString(buffer); 240 } 241 242 243 244 /** 245 * {@inheritDoc} 246 */ 247 @Override() 248 public String getExceptionMessage() 249 { 250 return ldapException.getExceptionMessage(); 251 } 252 253 254 255 /** 256 * {@inheritDoc} 257 */ 258 @Override() 259 public String getExceptionMessage(final boolean includeStackTrace, 260 final boolean includeCause) 261 { 262 return ldapException.getExceptionMessage(includeStackTrace, includeCause); 263 } 264}