View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.codec.decorators;
21  
22  
23  import java.nio.BufferOverflowException;
24  import java.nio.ByteBuffer;
25  
26  import org.apache.directory.api.asn1.EncoderException;
27  import org.apache.directory.api.i18n.I18n;
28  import org.apache.directory.api.ldap.codec.api.LdapApiService;
29  import org.apache.directory.api.ldap.codec.api.LdapCodecConstants;
30  import org.apache.directory.api.ldap.model.message.Control;
31  import org.apache.directory.api.ldap.model.message.UnbindRequest;
32  
33  
34  /**
35   * A decorator for the LdapResultResponse message
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   */
39  public class UnbindRequestDecorator extends RequestDecorator<UnbindRequest> implements UnbindRequest
40  {
41      /**
42       * Makes Request a MessageDecorator.
43       *
44       * @param decoratedMessage the decorated message
45       */
46      public UnbindRequestDecorator( LdapApiService codec, UnbindRequest decoratedMessage )
47      {
48          super( codec, decoratedMessage );
49      }
50  
51  
52      /**
53       * {@inheritDoc}
54       */
55      public UnbindRequest setMessageId( int messageId )
56      {
57          super.setMessageId( messageId );
58  
59          return this;
60      }
61  
62  
63      /**
64       * {@inheritDoc}
65       */
66      public UnbindRequest addControl( Control control )
67      {
68          return ( UnbindRequest ) super.addControl( control );
69      }
70  
71  
72      /**
73       * {@inheritDoc}
74       */
75      public UnbindRequest addAllControls( Control[] controls )
76      {
77          return ( UnbindRequest ) super.addAllControls( controls );
78      }
79  
80  
81      /**
82       * {@inheritDoc}
83       */
84      public UnbindRequest removeControl( Control control )
85      {
86          return ( UnbindRequest ) super.removeControl( control );
87      }
88  
89  
90      //-------------------------------------------------------------------------
91      // The Decorator methods
92      //-------------------------------------------------------------------------
93  
94      /**
95       * Compute the UnBindRequest length 
96       * 
97       * UnBindRequest : 
98       * 0x42 00
99       */
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( LdapCodecConstants.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 }