001/*
002 * Copyright 2009-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2009-2018 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.NotMutable;
032import com.unboundid.util.InternalUseOnly;
033import com.unboundid.util.ThreadSafety;
034import com.unboundid.util.ThreadSafetyLevel;
035
036import static com.unboundid.ldap.protocol.ProtocolMessages.*;
037import static com.unboundid.util.Debug.*;
038import static com.unboundid.util.StaticUtils.*;
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      debugException(e);
095
096      throw new LDAPException(ResultCode.DECODING_ERROR,
097           ERR_ABANDON_REQUEST_CANNOT_DECODE.get(getExceptionMessage(e)), e);
098    }
099  }
100
101
102
103  /**
104   * Retrieves the message ID of the operation to abandon.
105   *
106   * @return  The message ID of the operation to abandon.
107   */
108  public int getIDToAbandon()
109  {
110    return idToAbandon;
111  }
112
113
114
115  /**
116   * {@inheritDoc}
117   */
118  @Override()
119  public byte getProtocolOpType()
120  {
121    return LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST;
122  }
123
124
125
126  /**
127   * {@inheritDoc}
128   */
129  @Override()
130  public ASN1Element encodeProtocolOp()
131  {
132    return new ASN1Integer(LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST,
133         idToAbandon);
134  }
135
136
137
138  /**
139   * Decodes the provided ASN.1 element as an abandon request protocol op.
140   *
141   * @param  element  The ASN.1 element to be decoded.
142   *
143   * @return  The decoded abandon request protocol op.
144   *
145   * @throws  LDAPException  If the provided ASN.1 element cannot be decoded as
146   *                         an abandon request protocol op.
147   */
148  public static AbandonRequestProtocolOp decodeProtocolOp(
149                                              final ASN1Element element)
150         throws LDAPException
151  {
152    try
153    {
154      return new AbandonRequestProtocolOp(
155           ASN1Integer.decodeAsInteger(element).intValue());
156    }
157    catch (final Exception e)
158    {
159      debugException(e);
160      throw new LDAPException(ResultCode.DECODING_ERROR,
161           ERR_ABANDON_REQUEST_CANNOT_DECODE.get(getExceptionMessage(e)),
162           e);
163    }
164  }
165
166
167
168  /**
169   * {@inheritDoc}
170   */
171  @Override()
172  public void writeTo(final ASN1Buffer buffer)
173  {
174    buffer.addInteger(LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST,
175                      idToAbandon);
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  public String toString()
187  {
188    final StringBuilder buffer = new StringBuilder();
189    toString(buffer);
190    return buffer.toString();
191  }
192
193
194
195  /**
196   * {@inheritDoc}
197   */
198  @Override()
199  public void toString(final StringBuilder buffer)
200  {
201    buffer.append("AbandonRequestProtocolOp(idToAbandon=");
202    buffer.append(idToAbandon);
203    buffer.append(')');
204  }
205}