001 /*
002 * Copyright 2008-2016 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2008-2016 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.ldap.sdk.Control;
026 import com.unboundid.ldap.sdk.ExtendedResult;
027 import com.unboundid.ldap.sdk.LDAPException;
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 provides an implementation of the notice of disconnection extended
039 * result as defined in
040 * <A HREF="http://www.ietf.org/rfc/rfc4511.txt">RFC 4511</A>. It may be used
041 * as an unsolicited notification to indicate that the directory server is
042 * closing the client connection.
043 * <BR><BR>
044 * See the {@link com.unboundid.ldap.sdk.UnsolicitedNotificationHandler}
045 * interface for a mechanism that can be used to receive and handle unsolicited
046 * notifications.
047 */
048 @NotMutable()
049 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
050 public final class NoticeOfDisconnectionExtendedResult
051 extends ExtendedResult
052 {
053 /**
054 * The OID (1.3.6.1.4.1.1466.20036) for the notice of disconnection extended
055 * result.
056 */
057 public static final String NOTICE_OF_DISCONNECTION_RESULT_OID =
058 "1.3.6.1.4.1.1466.20036";
059
060
061
062 /**
063 * The serial version UID for this serializable class.
064 */
065 private static final long serialVersionUID = -4706102471360689558L;
066
067
068
069 /**
070 * Creates a new instance of this notice of disconnection extended result from
071 * the provided generic extended result.
072 *
073 * @param resultCode The result code for the notice of disconnection.
074 * @param diagnosticMessage The diagnostic message to include in the
075 * notice of disconnection. It may be {@code null}
076 * if no diagnostic message should be included.
077 * @param responseControls The set of controls to include in the notice of
078 * disconnection. It may be {@code null} or empty
079 * if no response controls are needed.
080 */
081 public NoticeOfDisconnectionExtendedResult(final ResultCode resultCode,
082 final String diagnosticMessage,
083 final Control... responseControls)
084 {
085 this(0, resultCode, diagnosticMessage, null, null, responseControls);
086 }
087
088
089
090 /**
091 * Creates a new instance of this notice of disconnection extended result from
092 * the provided generic extended result.
093 *
094 * @param extendedResult The extended result to use to create this notice of
095 * disconnection extended result.
096 */
097 public NoticeOfDisconnectionExtendedResult(
098 final ExtendedResult extendedResult)
099 {
100 super(extendedResult);
101 }
102
103
104
105 /**
106 * Creates a new instance of this notice of disconnection extended result from
107 * the provided LDAP exception.
108 *
109 * @param ldapException The LDAP exception to use to create this notice of
110 * disconnection extended result.
111 */
112 public NoticeOfDisconnectionExtendedResult(final LDAPException ldapException)
113 {
114 this(0, ldapException.getResultCode(), ldapException.getDiagnosticMessage(),
115 ldapException.getMatchedDN(), ldapException.getReferralURLs(),
116 ldapException.getResponseControls());
117 }
118
119
120
121 /**
122 * Creates a new instance of this notice of disconnection extended result from
123 * the provided information.
124 *
125 * @param messageID The message ID for the LDAP message that is
126 * associated with this LDAP result.
127 * @param resultCode The result code from the response.
128 * @param diagnosticMessage The diagnostic message from the response, if
129 * available.
130 * @param matchedDN The matched DN from the response, if available.
131 * @param referralURLs The set of referral URLs from the response, if
132 * available.
133 * @param responseControls The set of controls from the response, if
134 * available.
135 */
136 public NoticeOfDisconnectionExtendedResult(
137 final int messageID, final ResultCode resultCode,
138 final String diagnosticMessage, final String matchedDN,
139 final String[] referralURLs, final Control[] responseControls)
140 {
141 super(messageID, resultCode, diagnosticMessage, matchedDN, referralURLs,
142 NOTICE_OF_DISCONNECTION_RESULT_OID, null, responseControls);
143 }
144
145
146
147 /**
148 * {@inheritDoc}
149 */
150 @Override()
151 public String getExtendedResultName()
152 {
153 return INFO_EXTENDED_RESULT_NAME_NOTICE_OF_DISCONNECT.get();
154 }
155
156
157
158 /**
159 * Appends a string representation of this extended result to the provided
160 * buffer.
161 *
162 * @param buffer The buffer to which a string representation of this
163 * extended result will be appended.
164 */
165 @Override()
166 public void toString(final StringBuilder buffer)
167 {
168 buffer.append("NoticeOfDisconnectionExtendedResult(resultCode=");
169 buffer.append(getResultCode());
170
171 final int messageID = getMessageID();
172 if (messageID >= 0)
173 {
174 buffer.append(", messageID=");
175 buffer.append(messageID);
176 }
177
178 final String diagnosticMessage = getDiagnosticMessage();
179 if (diagnosticMessage != null)
180 {
181 buffer.append(", diagnosticMessage='");
182 buffer.append(diagnosticMessage);
183 buffer.append('\'');
184 }
185
186 final String matchedDN = getMatchedDN();
187 if (matchedDN != null)
188 {
189 buffer.append(", matchedDN='");
190 buffer.append(matchedDN);
191 buffer.append('\'');
192 }
193
194 final String[] referralURLs = getReferralURLs();
195 if (referralURLs.length > 0)
196 {
197 buffer.append(", referralURLs={");
198 for (int i=0; i < referralURLs.length; i++)
199 {
200 if (i > 0)
201 {
202 buffer.append(", ");
203 }
204
205 buffer.append('\'');
206 buffer.append(referralURLs[i]);
207 buffer.append('\'');
208 }
209 buffer.append('}');
210 }
211
212 buffer.append(", oid=");
213 buffer.append(NOTICE_OF_DISCONNECTION_RESULT_OID);
214
215 final Control[] responseControls = getResponseControls();
216 if (responseControls.length > 0)
217 {
218 buffer.append(", responseControls={");
219 for (int i=0; i < responseControls.length; i++)
220 {
221 if (i > 0)
222 {
223 buffer.append(", ");
224 }
225
226 buffer.append(responseControls[i]);
227 }
228 buffer.append('}');
229 }
230
231 buffer.append(')');
232 }
233 }