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 codec The LDAP service instance
45       * @param decoratedMessage the decorated message
46       */
47      public UnbindRequestDecorator( LdapApiService codec, UnbindRequest decoratedMessage )
48      {
49          super( codec, decoratedMessage );
50      }
51  
52  
53      /**
54       * {@inheritDoc}
55       */
56      @Override
57      public UnbindRequest setMessageId( int messageId )
58      {
59          super.setMessageId( messageId );
60  
61          return this;
62      }
63  
64  
65      /**
66       * {@inheritDoc}
67       */
68      @Override
69      public UnbindRequest addControl( Control control )
70      {
71          return ( UnbindRequest ) super.addControl( control );
72      }
73  
74  
75      /**
76       * {@inheritDoc}
77       */
78      @Override
79      public UnbindRequest addAllControls( Control[] controls )
80      {
81          return ( UnbindRequest ) super.addAllControls( controls );
82      }
83  
84  
85      /**
86       * {@inheritDoc}
87       */
88      @Override
89      public UnbindRequest removeControl( Control control )
90      {
91          return ( UnbindRequest ) super.removeControl( control );
92      }
93  
94  
95      //-------------------------------------------------------------------------
96      // The Decorator methods
97      //-------------------------------------------------------------------------
98  
99      /**
100      * Compute the UnBindRequest length 
101      * <br>
102      * UnBindRequest :
103      * <pre> 
104      * 0x42 00
105      * </pre>
106      */
107     @Override
108     public int computeLength()
109     {
110         // Always 2
111         return 2;
112     }
113 
114 
115     /**
116      * Encode the Unbind protocolOp part
117      */
118     @Override
119     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
120     {
121         try
122         {
123             // The tag
124             buffer.put( LdapCodecConstants.UNBIND_REQUEST_TAG );
125 
126             // The length is always null.
127             buffer.put( ( byte ) 0 );
128         }
129         catch ( BufferOverflowException boe )
130         {
131             String msg = I18n.err( I18n.ERR_04005 );
132             throw new EncoderException( msg, boe );
133         }
134 
135         return buffer;
136     }
137 }