001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *  
010     *    http://www.apache.org/licenses/LICENSE-2.0
011     *  
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License. 
018     *  
019     */
020    package org.apache.directory.shared.ldap.codec.unbind;
021    
022    
023    import java.nio.BufferOverflowException;
024    import java.nio.ByteBuffer;
025    
026    import org.apache.directory.shared.asn1.codec.EncoderException;
027    import org.apache.directory.shared.i18n.I18n;
028    import org.apache.directory.shared.ldap.codec.LdapConstants;
029    import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
030    import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
031    import org.slf4j.Logger;
032    import org.slf4j.LoggerFactory;
033    
034    
035    /**
036     * A UnBindRequest ldapObject. 
037     * 
038     * Its syntax is : 
039     * UnbindRequest ::= [APPLICATION 2] NULL 
040     * 
041     * This ldapObject is empty.
042     * 
043     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
044     * @version $Rev: 912399 $, $Date: 2010-02-21 21:52:31 +0100 (Sun, 21 Feb 2010) $, 
045     */
046    public class UnBindRequestCodec extends LdapMessageCodec
047    {
048        /** The logger */
049        private static Logger LOGGER = LoggerFactory.getLogger( UnBindRequestCodec.class );
050    
051        // ~ Constructors
052        // -------------------------------------------------------------------------------
053    
054        /**
055         * Creates a new BindRequest object.
056         */
057        public UnBindRequestCodec()
058        {
059            super();
060        }
061    
062    
063        // ~ Methods
064        // ------------------------------------------------------------------------------------
065    
066        /**
067         * Get the message type
068         * 
069         * @return Returns the type.
070         */
071        public MessageTypeEnum getMessageType()
072        {
073            return MessageTypeEnum.UNBIND_REQUEST;
074        }
075    
076    
077        /**
078         * Compute the UnBindRequest length 
079         * 
080         * UnBindRequest : 
081         * 0x42 00
082         */
083        protected int computeLengthProtocolOp()
084        {
085            return 2; // Always 2
086        }
087    
088    
089        /**
090         * Encode the Unbind protocolOp part
091         */
092        protected void encodeProtocolOp( ByteBuffer buffer ) throws EncoderException
093        {
094            try
095            {
096                // The tag
097                buffer.put( LdapConstants.UNBIND_REQUEST_TAG );
098    
099                // The length is always null.
100                buffer.put( ( byte ) 0 );
101            }
102            catch ( BufferOverflowException boe )
103            {
104                String msg = I18n.err( I18n.ERR_04005 );
105                LOGGER.error( msg );
106                throw new EncoderException( msg );
107            }
108        }
109    
110    
111        /**
112         * {@inheritDoc}
113         */
114        public String getMessageTypeName()
115        {
116            return "UNBIND_REQUEST";
117        }
118    
119    
120        /**
121         * Get a String representation of a UnBindRequest
122         * 
123         * @return A UnBindRequest String
124         */
125        public String toString()
126        {
127            return super.toString( "    UnBind Request" );
128        }
129    }