001/*
002 * Copyright 2015-2017 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2017 Ping Identity Corporation
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 */
021package com.unboundid.ldap.sdk;
022
023
024
025import com.unboundid.asn1.ASN1OctetString;
026import com.unboundid.util.NotExtensible;
027import com.unboundid.util.NotMutable;
028import com.unboundid.util.ThreadSafety;
029import com.unboundid.util.ThreadSafetyLevel;
030
031
032
033/**
034 * This class defines an exception that can be thrown if the server returns an
035 * extended response that indicates that the operation did not complete
036 * successfully.  This may be used to obtain access to any response OID and/or
037 * value that may have been included in the extended result.
038 */
039@NotExtensible()
040@NotMutable()
041@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
042public class LDAPExtendedOperationException
043       extends LDAPException
044{
045  /**
046   * The serial version UID for this serializable class.
047   */
048  private static final long serialVersionUID = -5674215690199642408L;
049
050
051
052  // The extended result for this exception.
053  private final ExtendedResult extendedResult;
054
055
056
057  /**
058   * Creates a new LDAP extended operation exception from the provided extended
059   * result.
060   *
061   * @param  extendedResult  The extended result to use to create this
062   *                         exception.
063   */
064  public LDAPExtendedOperationException(final ExtendedResult extendedResult)
065  {
066    super(extendedResult);
067
068    this.extendedResult = extendedResult;
069  }
070
071
072
073  /**
074   * {@inheritDoc}
075   */
076  @Override()
077  public LDAPResult toLDAPResult()
078  {
079    return extendedResult;
080  }
081
082
083
084  /**
085   * Retrieves the extended result that was returned by the server.
086   *
087   * @return  The extended result that was returned by the server.
088   */
089  public ExtendedResult getExtendedResult()
090  {
091    return extendedResult;
092  }
093
094
095
096  /**
097   * Retrieves the response OID from the extended result, if any.
098   *
099   * @return  The response OID from the extended result, or {@code null} if the
100   *          result did not include an OID.
101   */
102  public String getResponseOID()
103  {
104    return extendedResult.getOID();
105  }
106
107
108
109  /**
110   * Retrieves the response value from the extended result, if any.
111   *
112   * @return  The response value from the extended result, or {@code null} if
113   *          the result did not include a value.
114   */
115  public ASN1OctetString getResponseValue()
116  {
117    return extendedResult.getValue();
118  }
119
120
121
122  /**
123   * {@inheritDoc}
124   */
125  @Override()
126  public void toString(final StringBuilder buffer)
127  {
128    buffer.append("LDAPException(resultCode=");
129    buffer.append(getResultCode());
130
131    final String errorMessage = getMessage();
132    if (errorMessage != null)
133    {
134      buffer.append(", errorMessage='");
135      buffer.append(errorMessage);
136      buffer.append('\'');
137    }
138
139    final String responseOID = getResponseOID();
140    if (responseOID != null)
141    {
142      buffer.append(", responseOID='");
143      buffer.append(responseOID);
144      buffer.append('\'');
145    }
146
147    final String responseName = getExtendedResult().getExtendedResultName();
148    if ((responseName != null) && (! responseName.equals(responseOID)))
149    {
150      buffer.append(", responseName='");
151      buffer.append(responseName);
152      buffer.append('\'');
153    }
154
155    final String matchedDN = getMatchedDN();
156    if (matchedDN != null)
157    {
158      buffer.append(", matchedDN='");
159      buffer.append(matchedDN);
160      buffer.append('\'');
161    }
162
163    final String diagnosticMessage = getDiagnosticMessage();
164    if (diagnosticMessage != null)
165    {
166      buffer.append(", diagnosticMessage='");
167      buffer.append(diagnosticMessage);
168      buffer.append('\'');
169    }
170
171    final String[] referralURLs = getReferralURLs();
172    if (referralURLs.length > 0)
173    {
174      buffer.append(", referralURLs={");
175
176      for (int i=0; i < referralURLs.length; i++)
177      {
178        if (i > 0)
179        {
180          buffer.append(", ");
181        }
182
183        buffer.append('\'');
184        buffer.append(referralURLs[i]);
185        buffer.append('\'');
186      }
187
188      buffer.append('}');
189    }
190
191    final Control[] responseControls = getResponseControls();
192    if (responseControls.length > 0)
193    {
194      buffer.append(", responseControls={");
195
196      for (int i=0; i < responseControls.length; i++)
197      {
198        if (i > 0)
199        {
200          buffer.append(", ");
201        }
202
203        buffer.append(responseControls[i]);
204      }
205
206      buffer.append('}');
207    }
208
209    buffer.append(", ldapSDKVersion=");
210    buffer.append(Version.NUMERIC_VERSION_STRING);
211    buffer.append(", revision='");
212    buffer.append(Version.REVISION_ID);
213    buffer.append("')");
214  }
215}