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