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.ASN1Null; 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 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 debugException(e); 088 089 throw new LDAPException(ResultCode.DECODING_ERROR, 090 ERR_UNBIND_REQUEST_CANNOT_DECODE.get(getExceptionMessage(e)), e); 091 } 092 } 093 094 095 096 /** 097 * {@inheritDoc} 098 */ 099 @Override() 100 public byte getProtocolOpType() 101 { 102 return LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST; 103 } 104 105 106 107 /** 108 * {@inheritDoc} 109 */ 110 @Override() 111 public void writeTo(final ASN1Buffer buffer) 112 { 113 buffer.addNull(LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST); 114 } 115 116 117 118 /** 119 * {@inheritDoc} 120 */ 121 @Override() 122 public ASN1Element encodeProtocolOp() 123 { 124 return new ASN1Null(LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST); 125 } 126 127 128 129 /** 130 * Decodes the provided ASN.1 element as an unbind request protocol op. 131 * 132 * @param element The ASN.1 element to be decoded. 133 * 134 * @return The decoded unbind request protocol op. 135 * 136 * @throws LDAPException If the provided ASN.1 element cannot be decoded as 137 * an unbind request protocol op. 138 */ 139 public static UnbindRequestProtocolOp decodeProtocolOp( 140 final ASN1Element element) 141 throws LDAPException 142 { 143 try 144 { 145 ASN1Null.decodeAsNull(element); 146 return new UnbindRequestProtocolOp(); 147 } 148 catch (final Exception e) 149 { 150 debugException(e); 151 throw new LDAPException(ResultCode.DECODING_ERROR, 152 ERR_UNBIND_REQUEST_CANNOT_DECODE.get(getExceptionMessage(e)), 153 e); 154 } 155 } 156 157 158 159 /** 160 * Retrieves a string representation of this protocol op. 161 * 162 * @return A string representation of this protocol op. 163 */ 164 @Override() 165 public String toString() 166 { 167 final StringBuilder buffer = new StringBuilder(); 168 toString(buffer); 169 return buffer.toString(); 170 } 171 172 173 174 /** 175 * {@inheritDoc} 176 */ 177 @Override() 178 public void toString(final StringBuilder buffer) 179 { 180 buffer.append("UnbindRequestProtocolOp()"); 181 } 182}