001/*
002 * Copyright 2007-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2007-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) 2015-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.unboundidds.extensions;
037
038
039
040import com.unboundid.asn1.ASN1OctetString;
041import com.unboundid.ldap.sdk.Control;
042import com.unboundid.ldap.sdk.ExtendedResult;
043import com.unboundid.ldap.sdk.ResultCode;
044import com.unboundid.util.NotMutable;
045import com.unboundid.util.ThreadSafety;
046import com.unboundid.util.ThreadSafetyLevel;
047
048import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
049
050
051
052/**
053 * This class implements a data structure for storing the information from an
054 * extended result for the start batched transaction extended request.  It is
055 * able to decode a generic extended result to extract the transaction ID that
056 * it contains, if the operation was successful.
057 * <BR>
058 * <BLOCKQUOTE>
059 *   <B>NOTE:</B>  This class, and other classes within the
060 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
061 *   supported for use against Ping Identity, UnboundID, and
062 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
063 *   for proprietary functionality or for external specifications that are not
064 *   considered stable or mature enough to be guaranteed to work in an
065 *   interoperable way with other types of LDAP servers.
066 * </BLOCKQUOTE>
067 * <BR>
068 * See the documentation for the {@link StartBatchedTransactionExtendedRequest}
069 * class for an example that demonstrates the use of batched transactions.
070 */
071@NotMutable()
072@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
073public final class StartBatchedTransactionExtendedResult
074       extends ExtendedResult
075{
076  /**
077   * The serial version UID for this serializable class.
078   */
079  private static final long serialVersionUID = 7661263203064470371L;
080
081
082
083  // The transaction ID returned by the server.
084  private final ASN1OctetString transactionID;
085
086
087
088  /**
089   * Creates a new start batched transaction extended result from the provided
090   * extended result.
091   *
092   * @param  extendedResult  The extended result to be decoded as a start
093   *                         batched transaction extended result.  It must not
094   *                         be {@code null}.
095   */
096  public StartBatchedTransactionExtendedResult(
097              final ExtendedResult extendedResult)
098  {
099    super(extendedResult);
100
101    transactionID = extendedResult.getValue();
102  }
103
104
105
106  /**
107   * Creates a new start batched transaction extended result with the provided
108   * information.
109   *
110   * @param  messageID          The message ID for the LDAP message that is
111   *                            associated with this LDAP result.
112   * @param  resultCode         The result code from the response.
113   * @param  diagnosticMessage  The diagnostic message from the response, if
114   *                            available.
115   * @param  matchedDN          The matched DN from the response, if available.
116   * @param  referralURLs       The set of referral URLs from the response, if
117   *                            available.
118   * @param  transactionID      The transaction ID for this response, if
119   *                            available.
120   * @param  responseControls   The set of controls from the response, if
121   *                            available.
122   */
123  public StartBatchedTransactionExtendedResult(final int messageID,
124              final ResultCode resultCode, final String diagnosticMessage,
125              final String matchedDN, final String[] referralURLs,
126              final ASN1OctetString transactionID,
127              final Control[] responseControls)
128  {
129    super(messageID, resultCode, diagnosticMessage, matchedDN, referralURLs,
130          null, transactionID, responseControls);
131
132    this.transactionID = transactionID;
133  }
134
135
136
137  /**
138   * Retrieves the transaction ID for this start batched transaction extended
139   * result, if available.
140   *
141   * @return  The transaction ID for this start batched transaction extended
142   *          result, or {@code null} if none was provided.
143   */
144  public ASN1OctetString getTransactionID()
145  {
146    return transactionID;
147  }
148
149
150
151  /**
152   * {@inheritDoc}
153   */
154  @Override()
155  public String getExtendedResultName()
156  {
157    return INFO_EXTENDED_RESULT_NAME_START_BATCHED_TXN.get();
158  }
159
160
161
162  /**
163   * Appends a string representation of this extended result to the provided
164   * buffer.
165   *
166   * @param  buffer  The buffer to which a string representation of this
167   *                 extended result will be appended.
168   */
169  @Override()
170  public void toString(final StringBuilder buffer)
171  {
172    buffer.append("StartBatchedTransactionExtendedResult(resultCode=");
173    buffer.append(getResultCode());
174
175    final int messageID = getMessageID();
176    if (messageID >= 0)
177    {
178      buffer.append(", messageID=");
179      buffer.append(messageID);
180    }
181
182    if (transactionID != null)
183    {
184      buffer.append(", transactionID='");
185      buffer.append(transactionID.stringValue());
186      buffer.append('\'');
187    }
188
189    final String diagnosticMessage = getDiagnosticMessage();
190    if (diagnosticMessage != null)
191    {
192      buffer.append(", diagnosticMessage='");
193      buffer.append(diagnosticMessage);
194      buffer.append('\'');
195    }
196
197    final String matchedDN = getMatchedDN();
198    if (matchedDN != null)
199    {
200      buffer.append(", matchedDN='");
201      buffer.append(matchedDN);
202      buffer.append('\'');
203    }
204
205    final String[] referralURLs = getReferralURLs();
206    if (referralURLs.length > 0)
207    {
208      buffer.append(", referralURLs={");
209      for (int i=0; i < referralURLs.length; i++)
210      {
211        if (i > 0)
212        {
213          buffer.append(", ");
214        }
215
216        buffer.append('\'');
217        buffer.append(referralURLs[i]);
218        buffer.append('\'');
219      }
220      buffer.append('}');
221    }
222
223    final Control[] responseControls = getResponseControls();
224    if (responseControls.length > 0)
225    {
226      buffer.append(", responseControls={");
227      for (int i=0; i < responseControls.length; i++)
228      {
229        if (i > 0)
230        {
231          buffer.append(", ");
232        }
233
234        buffer.append(responseControls[i]);
235      }
236      buffer.append('}');
237    }
238
239    buffer.append(')');
240  }
241}