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