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.ASN1Null; 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 unbind request protocol op. 044 */ 045@InternalUseOnly() 046@NotMutable() 047@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 048public final class UnbindRequestProtocolOp 049 implements ProtocolOp 050{ 051 /** 052 * The serial version UID for this serializable class. 053 */ 054 private static final long serialVersionUID = 1703200292192488474L; 055 056 057 058 /** 059 * Creates a new unbind request protocol op. 060 */ 061 public UnbindRequestProtocolOp() 062 { 063 // No implementation required. 064 } 065 066 067 068 /** 069 * Creates a new unbind request protocol op read from the provided ASN.1 070 * stream reader. 071 * 072 * @param reader The ASN.1 stream reader from which to read the unbind 073 * request protocol op. 074 * 075 * @throws LDAPException If a problem occurs while reading or parsing the 076 * unbind request. 077 */ 078 UnbindRequestProtocolOp(final ASN1StreamReader reader) 079 throws LDAPException 080 { 081 try 082 { 083 reader.readNull(); 084 } 085 catch (final Exception e) 086 { 087 Debug.debugException(e); 088 089 throw new LDAPException(ResultCode.DECODING_ERROR, 090 ERR_UNBIND_REQUEST_CANNOT_DECODE.get( 091 StaticUtils.getExceptionMessage(e)), 092 e); 093 } 094 } 095 096 097 098 /** 099 * {@inheritDoc} 100 */ 101 @Override() 102 public byte getProtocolOpType() 103 { 104 return LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST; 105 } 106 107 108 109 /** 110 * {@inheritDoc} 111 */ 112 @Override() 113 public void writeTo(final ASN1Buffer buffer) 114 { 115 buffer.addNull(LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST); 116 } 117 118 119 120 /** 121 * {@inheritDoc} 122 */ 123 @Override() 124 public ASN1Element encodeProtocolOp() 125 { 126 return new ASN1Null(LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST); 127 } 128 129 130 131 /** 132 * Decodes the provided ASN.1 element as an unbind request protocol op. 133 * 134 * @param element The ASN.1 element to be decoded. 135 * 136 * @return The decoded unbind request protocol op. 137 * 138 * @throws LDAPException If the provided ASN.1 element cannot be decoded as 139 * an unbind request protocol op. 140 */ 141 public static UnbindRequestProtocolOp decodeProtocolOp( 142 final ASN1Element element) 143 throws LDAPException 144 { 145 try 146 { 147 ASN1Null.decodeAsNull(element); 148 return new UnbindRequestProtocolOp(); 149 } 150 catch (final Exception e) 151 { 152 Debug.debugException(e); 153 throw new LDAPException(ResultCode.DECODING_ERROR, 154 ERR_UNBIND_REQUEST_CANNOT_DECODE.get( 155 StaticUtils.getExceptionMessage(e)), 156 e); 157 } 158 } 159 160 161 162 /** 163 * Retrieves a string representation of this protocol op. 164 * 165 * @return A string representation of this protocol op. 166 */ 167 @Override() 168 public String toString() 169 { 170 final StringBuilder buffer = new StringBuilder(); 171 toString(buffer); 172 return buffer.toString(); 173 } 174 175 176 177 /** 178 * {@inheritDoc} 179 */ 180 @Override() 181 public void toString(final StringBuilder buffer) 182 { 183 buffer.append("UnbindRequestProtocolOp()"); 184 } 185}