001    /*
002     * Copyright 2009-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2009-2015 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.ASN1Null;
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.NotMutable;
032    import com.unboundid.util.InternalUseOnly;
033    import com.unboundid.util.ThreadSafety;
034    import com.unboundid.util.ThreadSafetyLevel;
035    
036    import static com.unboundid.ldap.protocol.ProtocolMessages.*;
037    import static com.unboundid.util.Debug.*;
038    import 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)
048    public 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 (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      public byte getProtocolOpType()
100      {
101        return LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST;
102      }
103    
104    
105    
106      /**
107       * {@inheritDoc}
108       */
109      public void writeTo(final ASN1Buffer buffer)
110      {
111        buffer.addNull(LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST);
112      }
113    
114    
115    
116      /**
117       * {@inheritDoc}
118       */
119      public ASN1Element encodeProtocolOp()
120      {
121        return new ASN1Null(LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST);
122      }
123    
124    
125    
126      /**
127       * Decodes the provided ASN.1 element as an unbind request protocol op.
128       *
129       * @param  element  The ASN.1 element to be decoded.
130       *
131       * @return  The decoded unbind request protocol op.
132       *
133       * @throws  LDAPException  If the provided ASN.1 element cannot be decoded as
134       *                         an unbind request protocol op.
135       */
136      public static UnbindRequestProtocolOp decodeProtocolOp(
137                                                 final ASN1Element element)
138             throws LDAPException
139      {
140        try
141        {
142          ASN1Null.decodeAsNull(element);
143          return new UnbindRequestProtocolOp();
144        }
145        catch (final Exception e)
146        {
147          debugException(e);
148          throw new LDAPException(ResultCode.DECODING_ERROR,
149               ERR_UNBIND_REQUEST_CANNOT_DECODE.get(getExceptionMessage(e)),
150               e);
151        }
152      }
153    
154    
155    
156      /**
157       * Retrieves a string representation of this protocol op.
158       *
159       * @return  A string representation of this protocol op.
160       */
161      @Override()
162      public String toString()
163      {
164        final StringBuilder buffer = new StringBuilder();
165        toString(buffer);
166        return buffer.toString();
167      }
168    
169    
170    
171      /**
172       * {@inheritDoc}
173       */
174      public void toString(final StringBuilder buffer)
175      {
176        buffer.append("UnbindRequestProtocolOp()");
177      }
178    }