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