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