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