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