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