001 /*
002 * Copyright 2009-2012 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2009-2012 UnboundID Corp.
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 */
021 package com.unboundid.ldap.protocol;
022
023
024
025 import com.unboundid.asn1.ASN1Buffer;
026 import com.unboundid.asn1.ASN1StreamReader;
027 import com.unboundid.ldap.sdk.LDAPException;
028 import com.unboundid.ldap.sdk.ResultCode;
029 import com.unboundid.util.NotMutable;
030 import com.unboundid.util.InternalUseOnly;
031 import com.unboundid.util.ThreadSafety;
032 import com.unboundid.util.ThreadSafetyLevel;
033
034 import static com.unboundid.ldap.protocol.ProtocolMessages.*;
035 import static com.unboundid.util.Debug.*;
036 import static com.unboundid.util.StaticUtils.*;
037
038
039
040 /**
041 * This class provides an implementation of an LDAP abandon request protocol op.
042 */
043 @InternalUseOnly()
044 @NotMutable()
045 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
046 public final class AbandonRequestProtocolOp
047 implements ProtocolOp
048 {
049 /**
050 * The serial version UID for this serializable class.
051 */
052 private static final long serialVersionUID = -7824390696388231825L;
053
054
055
056 // The message ID of the operation to abandon.
057 private final int idToAbandon;
058
059
060
061 /**
062 * Creates a new abandon request protocol op with the provided information.
063 *
064 * @param idToAbandon The message ID of the operation to abandon.
065 */
066 public AbandonRequestProtocolOp(final int idToAbandon)
067 {
068 this.idToAbandon = idToAbandon;
069 }
070
071
072
073 /**
074 * Creates a new abandon request protocol op read from the provided ASN.1
075 * stream reader.
076 *
077 * @param reader The ASN.1 stream reader from which to read the abandon
078 * request protocol op.
079 *
080 * @throws LDAPException If a problem occurs while reading or parsing the
081 * abandon request.
082 */
083 AbandonRequestProtocolOp(final ASN1StreamReader reader)
084 throws LDAPException
085 {
086 try
087 {
088 idToAbandon = reader.readInteger();
089 }
090 catch (Exception e)
091 {
092 debugException(e);
093
094 throw new LDAPException(ResultCode.DECODING_ERROR,
095 ERR_ABANDON_REQUEST_CANNOT_DECODE.get(getExceptionMessage(e)), e);
096 }
097 }
098
099
100
101 /**
102 * Retrieves the message ID of the operation to abandon.
103 *
104 * @return The message ID of the operation to abandon.
105 */
106 public int getIDToAbandon()
107 {
108 return idToAbandon;
109 }
110
111
112
113 /**
114 * {@inheritDoc}
115 */
116 public byte getProtocolOpType()
117 {
118 return LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST;
119 }
120
121
122
123 /**
124 * {@inheritDoc}
125 */
126 public void writeTo(final ASN1Buffer buffer)
127 {
128 buffer.addInteger(LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST,
129 idToAbandon);
130 }
131
132
133
134 /**
135 * Retrieves a string representation of this protocol op.
136 *
137 * @return A string representation of this protocol op.
138 */
139 @Override()
140 public String toString()
141 {
142 final StringBuilder buffer = new StringBuilder();
143 toString(buffer);
144 return buffer.toString();
145 }
146
147
148
149 /**
150 * {@inheritDoc}
151 */
152 public void toString(final StringBuilder buffer)
153 {
154 buffer.append("AbandonRequestProtocolOp(idToAbandon=");
155 buffer.append(idToAbandon);
156 buffer.append(')');
157 }
158 }