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.ASN1Integer;
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 abandon request protocol op.
060 */
061@InternalUseOnly()
062@NotMutable()
063@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
064public final class AbandonRequestProtocolOp
065       implements ProtocolOp
066{
067  /**
068   * The serial version UID for this serializable class.
069   */
070  private static final long serialVersionUID = -7824390696388231825L;
071
072
073
074  // The message ID of the operation to abandon.
075  private final int idToAbandon;
076
077
078
079  /**
080   * Creates a new abandon request protocol op with the provided information.
081   *
082   * @param  idToAbandon  The message ID of the operation to abandon.
083   */
084  public AbandonRequestProtocolOp(final int idToAbandon)
085  {
086    this.idToAbandon = idToAbandon;
087  }
088
089
090
091  /**
092   * Creates a new abandon request protocol op read from the provided ASN.1
093   * stream reader.
094   *
095   * @param  reader  The ASN.1 stream reader from which to read the abandon
096   *                 request protocol op.
097   *
098   * @throws  LDAPException  If a problem occurs while reading or parsing the
099   *                         abandon request.
100   */
101  AbandonRequestProtocolOp(@NotNull final ASN1StreamReader reader)
102       throws LDAPException
103  {
104    try
105    {
106      idToAbandon = reader.readInteger();
107    }
108    catch (final Exception e)
109    {
110      Debug.debugException(e);
111
112      throw new LDAPException(ResultCode.DECODING_ERROR,
113           ERR_ABANDON_REQUEST_CANNOT_DECODE.get(
114                StaticUtils.getExceptionMessage(e)),
115           e);
116    }
117  }
118
119
120
121  /**
122   * Retrieves the message ID of the operation to abandon.
123   *
124   * @return  The message ID of the operation to abandon.
125   */
126  public int getIDToAbandon()
127  {
128    return idToAbandon;
129  }
130
131
132
133  /**
134   * {@inheritDoc}
135   */
136  @Override()
137  public byte getProtocolOpType()
138  {
139    return LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST;
140  }
141
142
143
144  /**
145   * {@inheritDoc}
146   */
147  @Override()
148  @NotNull()
149  public ASN1Element encodeProtocolOp()
150  {
151    return new ASN1Integer(LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST,
152         idToAbandon);
153  }
154
155
156
157  /**
158   * Decodes the provided ASN.1 element as an abandon request protocol op.
159   *
160   * @param  element  The ASN.1 element to be decoded.
161   *
162   * @return  The decoded abandon request protocol op.
163   *
164   * @throws  LDAPException  If the provided ASN.1 element cannot be decoded as
165   *                         an abandon request protocol op.
166   */
167  @NotNull()
168  public static AbandonRequestProtocolOp decodeProtocolOp(
169                     @NotNull final ASN1Element element)
170         throws LDAPException
171  {
172    try
173    {
174      return new AbandonRequestProtocolOp(
175           ASN1Integer.decodeAsInteger(element).intValue());
176    }
177    catch (final Exception e)
178    {
179      Debug.debugException(e);
180      throw new LDAPException(ResultCode.DECODING_ERROR,
181           ERR_ABANDON_REQUEST_CANNOT_DECODE.get(
182                StaticUtils.getExceptionMessage(e)),
183           e);
184    }
185  }
186
187
188
189  /**
190   * {@inheritDoc}
191   */
192  @Override()
193  public void writeTo(@NotNull final ASN1Buffer buffer)
194  {
195    buffer.addInteger(LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST,
196                      idToAbandon);
197  }
198
199
200
201  /**
202   * Retrieves a string representation of this protocol op.
203   *
204   * @return  A string representation of this protocol op.
205   */
206  @Override()
207  @NotNull()
208  public String toString()
209  {
210    final StringBuilder buffer = new StringBuilder();
211    toString(buffer);
212    return buffer.toString();
213  }
214
215
216
217  /**
218   * {@inheritDoc}
219   */
220  @Override()
221  public void toString(@NotNull final StringBuilder buffer)
222  {
223    buffer.append("AbandonRequestProtocolOp(idToAbandon=");
224    buffer.append(idToAbandon);
225    buffer.append(')');
226  }
227}