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