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