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