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 */ 020package org.apache.directory.api.ldap.codec.decorators; 021 022 023import java.nio.BufferOverflowException; 024import java.nio.ByteBuffer; 025 026import org.apache.directory.api.asn1.EncoderException; 027import org.apache.directory.api.i18n.I18n; 028import org.apache.directory.api.ldap.codec.api.LdapApiService; 029import org.apache.directory.api.ldap.codec.api.LdapConstants; 030import org.apache.directory.api.ldap.model.message.Control; 031import org.apache.directory.api.ldap.model.message.UnbindRequest; 032 033 034/** 035 * A decorator for the LdapResultResponse message 036 * 037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 038 */ 039public class UnbindRequestDecorator extends RequestDecorator<UnbindRequest> implements UnbindRequest 040{ 041 /** 042 * Makes Request a MessageDecorator. 043 * 044 * @param decoratedMessage the decorated message 045 */ 046 public UnbindRequestDecorator( LdapApiService codec, UnbindRequest decoratedMessage ) 047 { 048 super( codec, decoratedMessage ); 049 } 050 051 052 /** 053 * {@inheritDoc} 054 */ 055 public UnbindRequest setMessageId( int messageId ) 056 { 057 super.setMessageId( messageId ); 058 059 return this; 060 } 061 062 063 /** 064 * {@inheritDoc} 065 */ 066 public UnbindRequest addControl( Control control ) 067 { 068 return ( UnbindRequest ) super.addControl( control ); 069 } 070 071 072 /** 073 * {@inheritDoc} 074 */ 075 public UnbindRequest addAllControls( Control[] controls ) 076 { 077 return ( UnbindRequest ) super.addAllControls( controls ); 078 } 079 080 081 /** 082 * {@inheritDoc} 083 */ 084 public UnbindRequest removeControl( Control control ) 085 { 086 return ( UnbindRequest ) super.removeControl( control ); 087 } 088 089 090 //------------------------------------------------------------------------- 091 // The Decorator methods 092 //------------------------------------------------------------------------- 093 094 /** 095 * Compute the UnBindRequest length 096 * 097 * UnBindRequest : 098 * 0x42 00 099 */ 100 public int computeLength() 101 { 102 return 2; // Always 2 103 } 104 105 106 /** 107 * Encode the Unbind protocolOp part 108 */ 109 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException 110 { 111 try 112 { 113 // The tag 114 buffer.put( LdapConstants.UNBIND_REQUEST_TAG ); 115 116 // The length is always null. 117 buffer.put( ( byte ) 0 ); 118 } 119 catch ( BufferOverflowException boe ) 120 { 121 String msg = I18n.err( I18n.ERR_04005 ); 122 throw new EncoderException( msg ); 123 } 124 125 return buffer; 126 } 127}