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