001/*
002 * Copyright 2009-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2009-2024 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) 2009-2024 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.protocol;
037
038
039
040import com.unboundid.asn1.ASN1Buffer;
041import com.unboundid.asn1.ASN1Element;
042import com.unboundid.asn1.ASN1Null;
043import com.unboundid.asn1.ASN1StreamReader;
044import com.unboundid.ldap.sdk.LDAPException;
045import com.unboundid.ldap.sdk.ResultCode;
046import com.unboundid.util.Debug;
047import com.unboundid.util.InternalUseOnly;
048import com.unboundid.util.NotMutable;
049import com.unboundid.util.NotNull;
050import com.unboundid.util.StaticUtils;
051import com.unboundid.util.ThreadSafety;
052import com.unboundid.util.ThreadSafetyLevel;
053
054import static com.unboundid.ldap.protocol.ProtocolMessages.*;
055
056
057
058/**
059 * This class provides an implementation of an LDAP unbind request protocol op.
060 */
061@InternalUseOnly()
062@NotMutable()
063@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
064public final class UnbindRequestProtocolOp
065       implements ProtocolOp
066{
067  /**
068   * The serial version UID for this serializable class.
069   */
070  private static final long serialVersionUID = 1703200292192488474L;
071
072
073
074  /**
075   * Creates a new unbind request protocol op.
076   */
077  public UnbindRequestProtocolOp()
078  {
079    // No implementation required.
080  }
081
082
083
084  /**
085   * Creates a new unbind request protocol op read from the provided ASN.1
086   * stream reader.
087   *
088   * @param  reader  The ASN.1 stream reader from which to read the unbind
089   *                 request protocol op.
090   *
091   * @throws  LDAPException  If a problem occurs while reading or parsing the
092   *                         unbind request.
093   */
094  UnbindRequestProtocolOp(@NotNull final ASN1StreamReader reader)
095       throws LDAPException
096  {
097    try
098    {
099      reader.readNull();
100    }
101    catch (final Exception e)
102    {
103      Debug.debugException(e);
104
105      throw new LDAPException(ResultCode.DECODING_ERROR,
106           ERR_UNBIND_REQUEST_CANNOT_DECODE.get(
107                StaticUtils.getExceptionMessage(e)),
108           e);
109    }
110  }
111
112
113
114  /**
115   * {@inheritDoc}
116   */
117  @Override()
118  public byte getProtocolOpType()
119  {
120    return LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST;
121  }
122
123
124
125  /**
126   * {@inheritDoc}
127   */
128  @Override()
129  public void writeTo(@NotNull final ASN1Buffer buffer)
130  {
131    buffer.addNull(LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST);
132  }
133
134
135
136  /**
137   * {@inheritDoc}
138   */
139  @Override()
140  @NotNull()
141  public ASN1Element encodeProtocolOp()
142  {
143    return new ASN1Null(LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST);
144  }
145
146
147
148  /**
149   * Decodes the provided ASN.1 element as an unbind request protocol op.
150   *
151   * @param  element  The ASN.1 element to be decoded.
152   *
153   * @return  The decoded unbind request protocol op.
154   *
155   * @throws  LDAPException  If the provided ASN.1 element cannot be decoded as
156   *                         an unbind request protocol op.
157   */
158  @NotNull()
159  public static UnbindRequestProtocolOp decodeProtocolOp(
160                                             @NotNull final ASN1Element element)
161         throws LDAPException
162  {
163    try
164    {
165      ASN1Null.decodeAsNull(element);
166      return new UnbindRequestProtocolOp();
167    }
168    catch (final Exception e)
169    {
170      Debug.debugException(e);
171      throw new LDAPException(ResultCode.DECODING_ERROR,
172           ERR_UNBIND_REQUEST_CANNOT_DECODE.get(
173                StaticUtils.getExceptionMessage(e)),
174           e);
175    }
176  }
177
178
179
180  /**
181   * Retrieves a string representation of this protocol op.
182   *
183   * @return  A string representation of this protocol op.
184   */
185  @Override()
186  @NotNull()
187  public String toString()
188  {
189    final StringBuilder buffer = new StringBuilder();
190    toString(buffer);
191    return buffer.toString();
192  }
193
194
195
196  /**
197   * {@inheritDoc}
198   */
199  @Override()
200  public void toString(@NotNull final StringBuilder buffer)
201  {
202    buffer.append("UnbindRequestProtocolOp()");
203  }
204}