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