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