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