directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject [directory-ldap-api] branch master updated: o Made the LdapEncoder class a static class
Date Thu, 15 Nov 2018 06:36:53 GMT
This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git


The following commit(s) were added to refs/heads/master by this push:
     new 518b4b4  o Made the LdapEncoder class a static class
518b4b4 is described below

commit 518b4b4df0ff41577db11576746877415030ddb9
Author: elecharny <elecharny@pierre-arnauds-macbook-pro.home>
AuthorDate: Thu Nov 15 07:36:50 2018 +0100

    o Made the LdapEncoder class a static class
---
 .../directory/api/ldap/codec/api/LdapEncoder.java  | 89 +++++++++-------------
 .../directory/api/ldap/codec/LdapControlTest.java  | 43 ++++++-----
 .../directory/api/ldap/codec/LdapMessageTest.java  | 29 +++----
 .../directory/api/ldap/codec/LdapResultTest.java   | 21 ++---
 .../api/ldap/codec/abandon/AbandonRequestTest.java | 31 ++++----
 .../api/ldap/codec/add/AddRequestTest.java         | 25 +++---
 .../api/ldap/codec/add/AddResponseTest.java        | 17 +++--
 .../api/ldap/codec/bind/BindRequestPerfTest.java   | 15 ++--
 .../api/ldap/codec/bind/BindRequestTest.java       | 79 +++++++++----------
 .../api/ldap/codec/bind/BindResponseTest.java      | 25 +++---
 .../api/ldap/codec/compare/CompareRequestTest.java | 25 +++---
 .../ldap/codec/compare/CompareResponseTest.java    | 17 +++--
 .../api/ldap/codec/del/DelRequestTest.java         | 29 +++----
 .../api/ldap/codec/del/DelResponseTest.java        | 17 +++--
 .../ldap/codec/extended/ExtendedRequestTest.java   | 23 +++---
 .../ldap/codec/extended/ExtendedResponseTest.java  | 35 ++++-----
 .../intermediate/IntermediateResponseTest.java     | 37 ++++-----
 .../api/ldap/codec/modify/ModifyRequestTest.java   | 31 ++++----
 .../api/ldap/codec/modify/ModifyResponseTest.java  | 17 +++--
 .../ldap/codec/modifyDn/ModifyDNRequestTest.java   | 29 +++----
 .../ldap/codec/modifyDn/ModifyDNResponseTest.java  | 17 +++--
 .../ldap/codec/osgi/AbstractCodecServiceTest.java  |  5 +-
 .../SearchRequestMatchingRuleAssertionTest.java    | 19 ++---
 .../codec/search/SearchRequestSubstringTest.java   | 43 ++++++-----
 .../api/ldap/codec/search/SearchRequestTest.java   | 59 +++++++-------
 .../ldap/codec/search/SearchResultDoneTest.java    | 19 ++---
 .../ldap/codec/search/SearchResultEntryTest.java   | 33 ++++----
 .../codec/search/SearchResultReferenceTest.java    | 25 +++---
 .../api/ldap/codec/unbind/UnBindRequestTest.java   | 29 +++----
 .../api/ldap/extras/AbstractCodecServiceTest.java  | 26 -------
 .../codec/protocol/mina/LdapProtocolEncoder.java   | 15 ++--
 31 files changed, 454 insertions(+), 470 deletions(-)

diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
index be7db9b..d0d72c6 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.api;
 
@@ -38,35 +38,20 @@ import org.apache.directory.api.util.Strings;
 
 /**
  * LDAP BER encoder.
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class LdapEncoder
+public final class LdapEncoder
 {
-    /** The LdapCodecService */
-    private LdapApiService codec;
-
-
-    /**
-     * Creates an instance of Ldap message encoder
-     * 
-     * @param codec The Codec service to use to handle Controls and extended operations,
-     * plus to get access to the underlying services.
-     */
-    public LdapEncoder( LdapApiService codec )
+    private LdapEncoder()
     {
-        if ( codec == null )
-        {
-            throw new NullPointerException( I18n.err( I18n.ERR_05203_CODEC_ARGS_CANNOT_BE_NULL ) );
-        }
-
-        this.codec = codec;
+        // Nothing to do
     }
 
 
     /**
      * Compute the control's encoded length
-     * 
+     *
      * @param control The control to compute
      * @return the encoded control length
      */
@@ -98,7 +83,7 @@ public class LdapEncoder
 
     /**
      * Encode a control to a byte[]
-     * 
+     *
      * @param buffer The buffer that will contain the encoded control
      * @param control The control to encode
      * @return The control encoded in a byte[]
@@ -137,35 +122,35 @@ public class LdapEncoder
         return buffer;
     }
 
-
     /**
-     * Generate the PDU which contains the encoded object. 
-     * 
-     * The generation is done in two phases : 
+     * Generate the PDU which contains the encoded object.
+     *
+     * The generation is done in two phases :
      * - first, we compute the length of each part and the
-     * global PDU length 
-     * - second, we produce the PDU. 
-     * 
+     * global PDU length
+     * - second, we produce the PDU.
+     *
      * <pre>
-     * 0x30 L1 
-     *   | 
-     *   +--&gt; 0x02 L2 MessageId  
-     *   +--&gt; ProtocolOp 
-     *   +--&gt; Controls 
-     *   
+     * 0x30 L1
+     *   |
+     *   +--&gt; 0x02 L2 MessageId
+     *   +--&gt; ProtocolOp
+     *   +--&gt; Controls
+     *
      * L2 = Length(MessageId)
      * L1 = Length(0x02) + Length(L2) + L2 + Length(ProtocolOp) + Length(Controls)
      * LdapMessageLength = Length(0x30) + Length(L1) + L1
      * </pre>
-     * 
+     *
      * @param message The message to encode
      * @return A ByteBuffer that contains the PDU
      * @throws EncoderException If anything goes wrong.
      */
-    public ByteBuffer encodeMessage( Message message ) throws EncoderException
+    public static ByteBuffer encodeMessage( LdapApiService codec, Message message ) throws EncoderException
     {
         AbstractMessageDecorator<? extends Message> decorator = AbstractMessageDecorator.getDecorator( codec, message );
         int length = computeMessageLength( decorator );
+
         ByteBuffer buffer = ByteBuffer.allocate( length );
 
         try
@@ -229,23 +214,23 @@ public class LdapEncoder
 
 
     /**
-     * Compute the LdapMessage length LdapMessage : 
+     * Compute the LdapMessage length LdapMessage :
      * <pre>
-     * 0x30 L1 
-     *   | 
-     *   +--&gt; 0x02 0x0(1-4) [0..2^31-1] (MessageId) 
-     *   +--&gt; protocolOp 
-     *   [+--&gt; Controls] 
-     *   
-     * MessageId length = Length(0x02) + length(MessageId) + MessageId.length 
-     * L1 = length(ProtocolOp) 
+     * 0x30 L1
+     *   |
+     *   +--&gt; 0x02 0x0(1-4) [0..2^31-1] (MessageId)
+     *   +--&gt; protocolOp
+     *   [+--&gt; Controls]
+     *
+     * MessageId length = Length(0x02) + length(MessageId) + MessageId.length
+     * L1 = length(ProtocolOp)
      * LdapMessage length = Length(0x30) + Length(L1) + MessageId length + L1
      * </pre>
-     * 
+     *
      * @param messageDecorator the decorated Message who's length is to be encoded
      * @return The message length
      */
-    private int computeMessageLength( AbstractMessageDecorator<? extends Message> messageDecorator )
+    private static int computeMessageLength( AbstractMessageDecorator<? extends Message> messageDecorator )
     {
         // The length of the MessageId. It's the sum of
         // - the tag (0x02), 1 byte
@@ -310,7 +295,7 @@ public class LdapEncoder
 
     /**
      * Encode the Referral message to a PDU.
-     * 
+     *
      * @param buffer The buffer where to put the PDU
      * @param referral The referral to encode
      * @exception EncoderException If the encoding failed
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapControlTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapControlTest.java
index 968b224..4913d41 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapControlTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapControlTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec;
 
@@ -32,9 +32,10 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Container;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
-import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
 import org.apache.directory.api.ldap.model.message.AbandonRequest;
@@ -64,7 +65,7 @@ public class LdapControlTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x64 );
         stream.put( new byte[]
-            { 
+            {
                 0x30, 0x62,                         // LDAPMessage ::=SEQUENCE {
                   0x02, 0x01, 0x03,                 // messageID MessageID
                     0x50, 0x01, 0x02,               // CHOICE { ..., abandonRequest
@@ -73,7 +74,7 @@ public class LdapControlTest extends AbstractCodecServiceTest
                     0x30, 0x1A,                     // Control ::= SEQUENCE {
                       0x04, 0x0D,                   // controlType LDAPOID,
                         '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
-                      0x01, 0x01, ( byte ) 0xFF,    // criticality BOOLEAN DEFAULT FALSE, 
+                      0x01, 0x01, ( byte ) 0xFF,    // criticality BOOLEAN DEFAULT FALSE,
                       0x04, 0x06,                   // controlValue OCTET STRING OPTIONAL }
                         'a', 'b', 'c', 'd', 'e', 'f',
                     0x30, 0x17,                     // Control ::= SEQUENCE {
@@ -87,7 +88,7 @@ public class LdapControlTest extends AbstractCodecServiceTest
                       0x01, 0x01, ( byte ) 0xFF,    // criticality BOOLEAN DEFAULT FALSE}
                     0x30, 0x0F,                     // Control ::= SEQUENCE {
                       0x04, 0x0D,                   // controlType LDAPOID}
-                        '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4' 
+                        '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4'
             } );
 
         stream.flip();
@@ -125,32 +126,32 @@ public class LdapControlTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "1.3.6.1.5.5.1" );
         assertEquals( "1.3.6.1.5.5.1", control.getOid() );
-        assertEquals( "0x61 0x62 0x63 0x64 0x65 0x66 ", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "0x61 0x62 0x63 0x64 0x65 0x66 ", Strings.dumpBytes( control.getValue() ) );
         assertTrue( control.isCritical() );
         internalAbandonRequest.addControl( control );
 
         control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls.get( "1.3.6.1.5.5.2" );
         assertEquals( "1.3.6.1.5.5.2", control.getOid() );
-        assertEquals( "0x67 0x68 0x69 0x6A 0x6B 0x6C ", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "0x67 0x68 0x69 0x6A 0x6B 0x6C ", Strings.dumpBytes( control.getValue() ) );
         assertFalse( control.isCritical() );
         internalAbandonRequest.addControl( control );
 
         control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls.get( "1.3.6.1.5.5.3" );
         assertEquals( "1.3.6.1.5.5.3", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
         assertTrue( control.isCritical() );
         internalAbandonRequest.addControl( control );
 
         control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls.get( "1.3.6.1.5.5.4" );
         assertEquals( "1.3.6.1.5.5.4", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
         assertFalse( control.isCritical() );
         internalAbandonRequest.addControl( control );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( new AbandonRequestDecorator( codec, internalAbandonRequest ) );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, new AbandonRequestDecorator( codec, internalAbandonRequest ) );
 
             // Check the length
             assertEquals( 0x64, bb.limit() );
@@ -178,7 +179,7 @@ public class LdapControlTest extends AbstractCodecServiceTest
         }
     }
 
-    
+
     /**
      * Test the decoding of a Request with an empty list of controls
      */
@@ -189,7 +190,7 @@ public class LdapControlTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0A );
         stream.put( new byte[]
-            { 
+            {
                 0x30, 0x08,                         // LDAPMessage ::=SEQUENCE {
                   0x02, 0x01, 0x03,                 // messageID MessageID
                     0x50, 0x01, 0x02,               // CHOICE { ..., abandonRequest
@@ -232,7 +233,7 @@ public class LdapControlTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( new AbandonRequestDecorator( codec, internalAbandonRequest ) );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, new AbandonRequestDecorator( codec, internalAbandonRequest ) );
 
             // Check the length, which should be 2 bytes shorter, as we don't encode teh empty control
             assertEquals( 0x08, bb.limit() );
@@ -271,7 +272,7 @@ public class LdapControlTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x19 );
         stream.put( new byte[]
-            { 
+            {
                 0x30, 0x17,                         // LDAPMessage ::=SEQUENCE {
                   0x02, 0x01, 0x03,                 // messageID MessageID
                 0x50, 0x01, 0x02,                   // CHOICE { ..., abandonRequest
@@ -281,7 +282,7 @@ public class LdapControlTest extends AbstractCodecServiceTest
                     0x04, 0x00,                     // controlType LDAPOID,
                     0x01, 0x01, ( byte ) 0xFF,      // criticality BOOLEAN DEFAULT FALSE,
                     0x04, 0x06,                     // controlValue OCTET STRING OPTIONAL }
-                      'a', 'b', 'c', 'd', 'e', 'f', 
+                      'a', 'b', 'c', 'd', 'e', 'f',
             } );
 
         stream.flip();
@@ -315,7 +316,7 @@ public class LdapControlTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x20 );
         stream.put( new byte[]
-            { 
+            {
                 0x30, 0x1E,                         // LDAPMessage ::=SEQUENCE {
                   0x02, 0x01, 0x03,                 // messageID MessageID
                 0x50, 0x01, 0x02,                   // CHOICE { ..., abandonRequest
@@ -327,7 +328,7 @@ public class LdapControlTest extends AbstractCodecServiceTest
                       'b', 'a', 'd', ' ', 'o', 'i', 'd',
                     0x01, 0x01, ( byte ) 0xFF,
                     0x04, 0x06,                     // controlValue OCTET STRING OPTIONAL }
-                      'a', 'b', 'c', 'd', 'e', 'f', 
+                      'a', 'b', 'c', 'd', 'e', 'f',
             } );
 
         stream.flip();
@@ -361,7 +362,7 @@ public class LdapControlTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x25 );
         stream.put( new byte[]
-            { 
+            {
                 0x30, 0x23,                         // LDAPMessage ::=SEQUENCE {
                   0x02, 0x01, 0x03,                 // messageID MessageID
                 0x50, 0x01, 0x02,                   // CHOICE { ..., abandonRequest
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapMessageTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapMessageTest.java
index 2e40318..2c61f3f 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapMessageTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapMessageTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec;
 
@@ -30,8 +30,9 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Container;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
-import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
+import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.UnbindRequestDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
 import org.apache.directory.api.ldap.model.message.Message;
@@ -47,7 +48,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * A global Ldap Decoder test
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -65,7 +66,7 @@ public class LdapMessageTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x02 );
         stream.put( new byte[]
-            { 
+            {
                 0x30, 0x00, // LDAPMessage ::=SEQUENCE {
             } );
 
@@ -100,7 +101,7 @@ public class LdapMessageTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x04 );
         stream.put( new byte[]
-            { 
+            {
                 0x30, 0x02,                         // LDAPMessage ::=SEQUENCE {
                   0x02, 0x00                        // messageID MessageID
             } );
@@ -136,7 +137,7 @@ public class LdapMessageTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x05 );
         stream.put( new byte[]
-            { 
+            {
                 0x30, 0x03,                         // LDAPMessage ::=SEQUENCE {
                   0x02, 0x01, ( byte ) 0xff         // messageID MessageID = -1
             } );
@@ -172,10 +173,10 @@ public class LdapMessageTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x08 );
         stream.put( new byte[]
-            { 
+            {
                 0x30, 0x06,                         // LDAPMessage ::=SEQUENCE {
                   0x02, 0x04,                       // messageID MessageID = -1
-                    ( byte ) 0x7f,( byte ) 0xff, ( byte ) 0xff, ( byte ) 0xff 
+                    ( byte ) 0x7f,( byte ) 0xff, ( byte ) 0xff, ( byte ) 0xff
             } );
 
         stream.flip();
@@ -205,7 +206,7 @@ public class LdapMessageTest extends AbstractCodecServiceTest
     public void testDecodeWrongProtocolOpMaxInt()
     {
         byte[] buffer = new byte[]
-            { 
+            {
                 0x30, 0x05,                         // LDAPMessage ::=SEQUENCE {
                   0x02, 0x01, 0x01,                 // messageID MessageID = 1
                   0x42, 0x00                        // ProtocolOp
@@ -292,7 +293,7 @@ public class LdapMessageTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x08 );
         stream.put( new byte[]
-            { 
+            {
                 0x30, 0x06,                         // LDAPMessage ::=SEQUENCE {
                   0x02, 0x02, 0x01, ( byte ) 0xF4,  // messageID MessageID (500)
                   0x42, 0x00,                       // CHOICE { ..., unbindRequest UnbindRequest,...
@@ -326,7 +327,7 @@ public class LdapMessageTest extends AbstractCodecServiceTest
 
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( new UnbindRequestDecorator( codec, internalUnbindRequest ) );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, new UnbindRequestDecorator( codec, internalUnbindRequest ) );
 
             // Check the length
             assertEquals( 0x08, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapResultTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapResultTest.java
index bd85073..4ca9494 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapResultTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapResultTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec;
 
@@ -32,8 +32,9 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Container;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
-import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
+import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
 import org.apache.directory.api.ldap.model.message.AddResponse;
@@ -51,7 +52,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 /**
  * A test for LdapResults. We will use a AddResponse message to test the
  * LdapResult part
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -334,7 +335,7 @@ public class LdapResultTest extends AbstractCodecServiceTest
 
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( addResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, addResponse );
 
             // Check the length
             assertEquals( 0x0E, bb.limit() );
@@ -423,7 +424,7 @@ public class LdapResultTest extends AbstractCodecServiceTest
 
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( addResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, addResponse );
 
             // Check the length
             assertEquals( 0x1A, bb.limit() );
@@ -528,7 +529,7 @@ public class LdapResultTest extends AbstractCodecServiceTest
 
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( addResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, addResponse );
 
             // Check the length
             assertEquals( 0x24, bb.limit() );
@@ -630,7 +631,7 @@ public class LdapResultTest extends AbstractCodecServiceTest
 
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( addResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, addResponse );
 
             // Check the length
             assertEquals( 0x1C, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/abandon/AbandonRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/abandon/AbandonRequestTest.java
index f7d75c0..c5ebc82 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/abandon/AbandonRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/abandon/AbandonRequestTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.abandon;
 
@@ -31,9 +31,10 @@ import java.util.Map;
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
-import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
 import org.apache.directory.api.ldap.model.message.AbandonRequest;
@@ -50,7 +51,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test an AbandonRequest
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -89,7 +90,7 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
                     0x01, 0x01, ( byte ) 0xFF,          // criticality BOOLEAN DEFAULT FALSE }
                   0x30, 0x0F,                           // Control ::= SEQUENCE {
                     0x04, 0x0D,                         // controlType LDAPOID}
-                      '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4' 
+                      '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4'
             } );
 
         stream.flip();
@@ -127,32 +128,32 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
         CodecControl<? extends Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<?> ) controls
             .get( "1.3.6.1.5.5.1" );
         assertEquals( "1.3.6.1.5.5.1", control.getOid() );
-        assertEquals( "0x61 0x62 0x63 0x64 0x65 0x66 ", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "0x61 0x62 0x63 0x64 0x65 0x66 ", Strings.dumpBytes( control.getValue() ) );
         assertTrue( control.isCritical() );
         internalAbandonRequest.addControl( control );
 
         control = ( org.apache.directory.api.ldap.codec.api.CodecControl<?> ) controls.get( "1.3.6.1.5.5.2" );
         assertEquals( "1.3.6.1.5.5.2", control.getOid() );
-        assertEquals( "0x67 0x68 0x69 0x6A 0x6B 0x6C ", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "0x67 0x68 0x69 0x6A 0x6B 0x6C ", Strings.dumpBytes( control.getValue() ) );
         assertFalse( control.isCritical() );
         internalAbandonRequest.addControl( control );
 
         control = ( org.apache.directory.api.ldap.codec.api.CodecControl<?> ) controls.get( "1.3.6.1.5.5.3" );
         assertEquals( "1.3.6.1.5.5.3", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
         assertTrue( control.isCritical() );
         internalAbandonRequest.addControl( control );
 
         control = ( org.apache.directory.api.ldap.codec.api.CodecControl<?> ) controls.get( "1.3.6.1.5.5.4" );
         assertEquals( "1.3.6.1.5.5.4", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
         assertFalse( control.isCritical() );
         internalAbandonRequest.addControl( control );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( new AbandonRequestDecorator( codec, internalAbandonRequest ) );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, new AbandonRequestDecorator( codec, internalAbandonRequest ) );
 
             // Check the length
             assertEquals( 0x64, bb.limit() );
@@ -190,7 +191,7 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0A );
         stream.put( new byte[]
-            { 
+            {
               0x30, 0x08,                                   // LDAPMessage ::=SEQUENCE {
                 0x02, 0x03, 0x00, ( byte ) 0x80, 0x13,      // messageID MessageID
                 0x50, 0x01, 0x02                            // CHOICE { ..., abandonRequest
@@ -229,7 +230,7 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage(  new AbandonRequestDecorator( codec, internalAbandonRequest )  );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, new AbandonRequestDecorator( codec, internalAbandonRequest )  );
 
             // Check the length
             assertEquals( 0x0A, bb.limit() );
@@ -294,7 +295,7 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0B );
         stream.put( new byte[]
-            { 
+            {
               0x30, 0x09,                   // LDAPMessage ::=SEQUENCE {
                 0x02, 0x01, 0x01,           // messageID MessageID
                 0x50, 0x01, ( byte ) 0xFF   // CHOICE { ..., abandonRequest AbandonRequest,...
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddRequestTest.java
index 67ad120..edfce4c 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddRequestTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.add;
 
@@ -36,9 +36,10 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Container;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
-import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
 import org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -60,7 +61,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the AddRequest codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -226,7 +227,7 @@ public class AddRequestTest extends AbstractCodecServiceTest
 
         assertTrue( expectedTypes.contains( Strings.toLowerCaseAscii( attribute.getId() ) ) );
 
-        Set<String> vals = ( Set<String> ) typesVals.get( Strings.toLowerCaseAscii( attribute.getId() ) );
+        Set<String> vals = typesVals.get( Strings.toLowerCaseAscii( attribute.getId() ) );
 
         for ( Value value : attribute )
         {
@@ -239,7 +240,7 @@ public class AddRequestTest extends AbstractCodecServiceTest
 
         assertTrue( expectedTypes.contains( Strings.toLowerCaseAscii( attribute.getId() ) ) );
 
-        vals = ( Set<String> ) typesVals.get( Strings.toLowerCaseAscii( attribute.getId() ) );
+        vals = typesVals.get( Strings.toLowerCaseAscii( attribute.getId() ) );
 
         for ( Value value : attribute )
         {
@@ -251,7 +252,7 @@ public class AddRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( addRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, addRequest );
 
             // Check the length
             assertEquals( 0x59, bb.limit() );
@@ -1075,7 +1076,7 @@ public class AddRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( addRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, addRequest );
 
             // Check the length
             assertEquals( 0x34, bb.limit() );
@@ -1237,12 +1238,12 @@ public class AddRequestTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( addRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, addRequest );
 
             // Check the length
             assertEquals( 0x51, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddResponseTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddResponseTest.java
index 50cb025..7695573 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddResponseTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddResponseTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.add;
 
@@ -31,9 +31,10 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Container;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
-import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
 import org.apache.directory.api.ldap.model.message.AddResponse;
@@ -114,7 +115,7 @@ public class AddResponseTest extends AbstractCodecServiceTest
 
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( addResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, addResponse );
 
             // Check the length
             assertEquals( 0x0E, bb.limit() );
@@ -265,12 +266,12 @@ public class AddResponseTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         try
         {
             /** The encoder instance */
-            ByteBuffer bb = encoder.encodeMessage( addResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, addResponse );
 
             // Check the length
             assertEquals( 0x02B, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestPerfTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestPerfTest.java
index cf04cc8..69f6d12 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestPerfTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestPerfTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.bind;
 
@@ -31,6 +31,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -204,12 +205,12 @@ public class BindRequestPerfTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
 
             // Check the length
             assertEquals( 0x52, bb.limit() );
@@ -254,7 +255,7 @@ public class BindRequestPerfTest extends AbstractCodecServiceTest
             // Check the encoding
             try
             {
-                encoder.encodeMessage( bindRequest );
+                LdapEncoder.encodeMessage( codec, bindRequest );
             }
             catch ( EncoderException ee )
             {
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestTest.java
index b1ba11c..b4564c7 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestTest.java
@@ -6,39 +6,37 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.bind;
 
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.junit.Assert.assertNull;
 
 import java.nio.ByteBuffer;
 import java.util.Map;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Container;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
-import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
 import org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -51,6 +49,9 @@ import org.apache.directory.api.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -71,7 +72,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x52 );
         stream.put( new byte[]
-             { 
+             {
              0x30, 0x50,                 // LDAPMessage ::=SEQUENCE {
                0x02, 0x01, 0x01,         // messageID MessageID
                0x60, 0x2E,               // CHOICE { ..., bindRequest BindRequest, ...
@@ -79,16 +80,16 @@ public class BindRequestTest extends AbstractCodecServiceTest
                  0x02, 0x01, 0x03,       // version INTEGER (1..127),
                  0x04, 0x1F,             // name LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
-                 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 
+                 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                  ( byte ) 0x80, 0x08,    // authentication AuthenticationChoice
                                          // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
                                          // ...
-                   'p', 'a', 's', 's', 'w', 'o', 'r', 'd', 
+                   'p', 'a', 's', 's', 'w', 'o', 'r', 'd',
                ( byte ) 0xA0, 0x1B, // A control
-                 0x30, 0x19, 
-                   0x04, 0x17, 
-                     0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 
-                     0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 
+                 0x30, 0x19,
+                   0x04, 0x17,
+                     0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33,
+                     0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
              } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -109,7 +110,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
             }
             long t1 = System.currentTimeMillis();
             System.out.println( "Delta = " + ( t1 - t0 ) );
-            
+
             ldapDecoder.decode( stream, container );
         }
         catch ( DecoderException de )
@@ -255,7 +256,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
 
             // Check the length
             assertEquals( 0x35, bb.limit() );
@@ -350,7 +351,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
         try
         {
             ldapDecoder.decode( stream, container );
-            
+
             BindRequest bindRequest = ((BindRequestDecorator)container.getMessage());
             assertNull( bindRequest.getDn() );
             assertEquals( "uid:akarasulu,dc=example,dc=com", bindRequest.getName() );
@@ -488,7 +489,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
 
             // Check the length
             assertEquals( 0x16, bb.limit() );
@@ -610,7 +611,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
 
             // Check the length
             assertEquals( 0x3A, bb.limit() );
@@ -707,7 +708,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
                 0x06, // SaslCredentials ::= SEQUENCE {
                 // ...
                 // credentials OCTET STRING OPTIONAL }
-                // 
+                //
                 'a',
                 'b',
                 'c',
@@ -745,7 +746,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
 
             // Check the length
             assertEquals( 0x42, bb.limit() );
@@ -810,7 +811,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
                 0x06, // SaslCredentials ::= SEQUENCE {
                 // ...
                 // credentials OCTET STRING OPTIONAL }
-                // 
+                //
                 'a',
                 'b',
                 'c',
@@ -848,7 +849,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
 
             // Check the length
             assertEquals( 0x23, bb.limit() );
@@ -1203,7 +1204,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
 
             // Check the length
             assertEquals( 0x0E, bb.limit() );
@@ -1323,7 +1324,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
 
             // Check the length
             assertEquals( 0x10, bb.limit() );
@@ -1351,13 +1352,13 @@ public class BindRequestTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x11 );
         stream.put( new byte[]
-            { 
+            {
             0x30, 0x0F,                 // LDAPMessage ::=SEQUENCE {
               0x02, 0x01, 0x01,         // messageID MessageID
               0x60, 0x0A,               // CHOICE { ..., bindRequest BindRequest, ...
                 0x02, 0x01, 0x03,       // version INTEGER (1..127),
-                0x04, 0x00, 
-                ( byte ) 0xA3, 0x03, 
+                0x04, 0x00,
+                ( byte ) 0xA3, 0x03,
                   0x04, 0x01, (byte)0xFF
             } );
 
@@ -1442,7 +1443,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
 
             // Check the length
             assertEquals( 0x12, bb.limit() );
@@ -1554,12 +1555,12 @@ public class BindRequestTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
 
             // Check the length
             assertEquals( 0x2F, bb.limit() );
@@ -1668,12 +1669,12 @@ public class BindRequestTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
 
             // Check the length
             assertEquals( 0x2D, bb.limit() );
@@ -1699,17 +1700,17 @@ public class BindRequestTest extends AbstractCodecServiceTest
     {
         Dn name = new Dn( "uid=akarasulu,dc=example,dc=com" );
         long t0 = System.currentTimeMillis();
-        
+
         for ( int i = 0; i< 10000; i++)
         {
             // Check the decoded BindRequest
             LdapMessage message = new LdapMessage();
             message.setMessageId( 1 );
-            
+
             BindRequest br = new BindRequest();
             br.setMessageId( 1 );
             br.setName( name );
-            
+
             Control control = new Control();
             control.setControlType( "2.16.840.1.113730.3.4.2" );
 
@@ -1719,7 +1720,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
             br.addControl( control );
             br.setAuthentication( authentication );
             message.setProtocolOP( br );
-    
+
             // Check the encoding
             try
             {
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindResponseTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindResponseTest.java
index f55e5bf..895b29c 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindResponseTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindResponseTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.bind;
 
@@ -32,9 +32,10 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Container;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
-import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
 import org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsDecorator;
 import org.apache.directory.api.ldap.codec.decorators.BindResponseDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -118,7 +119,7 @@ public class BindResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindResponse );
 
             // Check the length
             assertEquals( 0x0E, bb.limit() );
@@ -203,7 +204,7 @@ public class BindResponseTest extends AbstractCodecServiceTest
                 0x0B,
                 0x02,
                 0x01,
-                0x05, // Size = 5, cookie = "abcdef" 
+                0x05, // Size = 5, cookie = "abcdef"
                 0x04,
                 0x06,
                 'a',
@@ -255,7 +256,7 @@ public class BindResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindResponse );
 
             // Check the length
             assertEquals( 0x3C, bb.limit() );
@@ -336,7 +337,7 @@ public class BindResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindResponse );
 
             // Check the length
             assertEquals( 0x10, bb.limit() );
@@ -453,12 +454,12 @@ public class BindResponseTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindResponse );
 
             // Check the length
             assertEquals( 0x2D, bb.limit() );
@@ -542,7 +543,7 @@ public class BindResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindResponse );
 
             // Check the length
             assertEquals( 0x12, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java
index 44d0c85..49667bb 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.compare;
 
@@ -27,13 +27,11 @@ import static org.junit.Assert.fail;
 import java.nio.ByteBuffer;
 import java.util.Map;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
 import org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator;
@@ -47,10 +45,13 @@ import org.apache.directory.api.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * Test the CompareRequest codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -159,7 +160,7 @@ public class CompareRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( compareRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, compareRequest );
 
             // Check the length
             assertEquals( 0x38, bb.limit() );
@@ -615,7 +616,7 @@ public class CompareRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( compareRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, compareRequest );
 
             // Check the length
             assertEquals( 0x33, bb.limit() );
@@ -770,12 +771,12 @@ public class CompareRequestTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( compareRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, compareRequest );
 
             // Check the length
             assertEquals( 0x55, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareResponseTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareResponseTest.java
index 8b2019c..d29e205 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareResponseTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareResponseTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.compare;
 
@@ -31,6 +31,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.CompareResponseDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -47,7 +48,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the CompareResponse codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -116,7 +117,7 @@ public class CompareResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( compareResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, compareResponse );
 
             // Check the length
             assertEquals( 0x0E, bb.limit() );
@@ -230,12 +231,12 @@ public class CompareResponseTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( compareResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, compareResponse );
 
             // Check the length
             assertEquals( 0x2B, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelRequestTest.java
index 89f348d..49f68a7 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelRequestTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.del;
 
@@ -31,6 +31,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
 import org.apache.directory.api.ldap.codec.decorators.DeleteRequestDecorator;
@@ -51,7 +52,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the DelRequest codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -69,14 +70,14 @@ public class DelRequestTest extends AbstractCodecServiceTest
         ByteBuffer stream = ByteBuffer.allocate( 0x27 );
 
         stream.put( new byte[]
-            { 
+            {
               0x30, 0x25,               // LDAPMessage ::= SEQUENCE {
                 0x02, 0x01, 0x01,       // messageID MessageID
                                         // CHOICE { ..., delRequest DelRequest, ...
                                         // DelRequest ::= [APPLICATION 10] LDAPDN;
                 0x4A, 0x20,
                   'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',',
-                  'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' 
+                  'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm'
             } );
 
         String decodedPdu = Strings.dumpBytes( stream.array() );
@@ -111,7 +112,7 @@ public class DelRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( new DeleteRequestDecorator( codec, internalDeleteRequest ) );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, new DeleteRequestDecorator( codec, internalDeleteRequest ) );
 
             // Check the length
             assertEquals( 0x27, bb.limit() );
@@ -145,8 +146,8 @@ public class DelRequestTest extends AbstractCodecServiceTest
                                         // CHOICE { ..., delRequest DelRequest, ...
                                         // DelRequest ::= [APPLICATION 10] LDAPDN;
                 0x4A, 0x20,
-                  'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 
-                  'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' 
+                  'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',',
+                  'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm'
             } );
 
         stream.flip();
@@ -185,7 +186,7 @@ public class DelRequestTest extends AbstractCodecServiceTest
         ByteBuffer stream = ByteBuffer.allocate( 0x07 );
 
         stream.put( new byte[]
-            { 
+            {
               0x30, 0x05,               // LDAPMessage ::= SEQUENCE {
                 0x02, 0x01, 0x01,       // messageID MessageID
                                         // CHOICE { ..., delRequest DelRequest, ...
@@ -234,7 +235,7 @@ public class DelRequestTest extends AbstractCodecServiceTest
                 ( byte ) 0xA0, 0x1B,    // A control
                   0x30, 0x19,
                     0x04, 0x17,
-                      '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', 
+                      '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3',
                       '7', '3', '0', '.', '3', '.', '4', '.', '2'
             } );
 
@@ -271,7 +272,7 @@ public class DelRequestTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         DeleteRequest internalDeleteRequest = new DeleteRequestImpl();
         internalDeleteRequest.setMessageId( delRequest.getMessageId() );
@@ -281,7 +282,7 @@ public class DelRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( new DeleteRequestDecorator( codec, internalDeleteRequest ) );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, new DeleteRequestDecorator( codec, internalDeleteRequest ) );
 
             // Check the length
             assertEquals( 0x44, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelResponseTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelResponseTest.java
index 49a6589..58dc490 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelResponseTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelResponseTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.del;
 
@@ -31,6 +31,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.DeleteResponseDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -47,7 +48,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the DelResponse codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -148,7 +149,7 @@ public class DelResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( delResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, delResponse );
 
             // Check the length
             assertEquals( 0x2D, bb.limit() );
@@ -335,12 +336,12 @@ public class DelResponseTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( delResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, delResponse );
 
             // Check the length
             assertEquals( 0x4A, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/extended/ExtendedRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/extended/ExtendedRequestTest.java
index 1509b09..d55622f 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/extended/ExtendedRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/extended/ExtendedRequestTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.extended;
 
@@ -31,6 +31,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -45,7 +46,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the ExtendedRequest codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -123,7 +124,7 @@ public class ExtendedRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedRequest );
 
             // Check the length
             assertEquals( 0x1D, bb.limit() );
@@ -252,7 +253,7 @@ public class ExtendedRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedRequest );
 
             // Check the length
             assertEquals( 0x3A, bb.limit() );
@@ -376,7 +377,7 @@ public class ExtendedRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedRequest );
 
             // Check the length
             assertEquals( 0x33, bb.limit() );
@@ -473,7 +474,7 @@ public class ExtendedRequestTest extends AbstractCodecServiceTest
 
 
     /**
-     * Test the decoding of a bad name 
+     * Test the decoding of a bad name
      */
     @Test
     public void testDecodeExtendedBadRequestName()
@@ -588,7 +589,7 @@ public class ExtendedRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedRequest );
 
             // Check the length
             assertEquals( 0x16, bb.limit() );
@@ -671,7 +672,7 @@ public class ExtendedRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedRequest );
 
             // Check the length
             assertEquals( 0x18, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/extended/ExtendedResponseTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/extended/ExtendedResponseTest.java
index 66ed151..b9f6d1b 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/extended/ExtendedResponseTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/extended/ExtendedResponseTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.extended;
 
@@ -31,6 +31,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -48,7 +49,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the ExtendedResponse codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -141,7 +142,7 @@ public class ExtendedResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedResponse );
 
             // Check the length
             assertEquals( 0x24, bb.limit() );
@@ -175,9 +176,9 @@ public class ExtendedResponseTest extends AbstractCodecServiceTest
                 0x02,
                 0x01,
                 0x01, // messageID MessageID
-                // CHOICE { 
-                //    ..., 
-                //    extendedResp ExtendedResponse, 
+                // CHOICE {
+                //    ...,
+                //    extendedResp ExtendedResponse,
                 //    ...
                 0x78,
                 0x1D, // ExtendedResponse ::= [APPLICATION 23] SEQUENCE {
@@ -209,7 +210,7 @@ public class ExtendedResponseTest extends AbstractCodecServiceTest
                 '.',
                 '2',
                 ( byte ) 0x8B,
-                0x05, // response [11] OCTET STRING OPTIONAL } 
+                0x05, // response [11] OCTET STRING OPTIONAL }
                 'v',
                 'a',
                 'l',
@@ -287,7 +288,7 @@ public class ExtendedResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedResponse );
 
             // Check the length
             assertEquals( 0x41, bb.limit() );
@@ -366,7 +367,7 @@ public class ExtendedResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedResponse );
 
             // Check the length
             assertEquals( 0x0E, bb.limit() );
@@ -484,7 +485,7 @@ public class ExtendedResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedResponse );
 
             // Check the length
             assertEquals( 0x2B, bb.limit() );
@@ -726,7 +727,7 @@ public class ExtendedResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedResponse );
 
             // Check the length
             assertEquals( 0x1D, bb.limit() );
@@ -863,7 +864,7 @@ public class ExtendedResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedResponse );
 
             // Check the length
             assertEquals( 0x3A, bb.limit() );
@@ -961,7 +962,7 @@ public class ExtendedResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedResponse );
 
             // Check the length
             assertEquals( 0x1F, bb.limit() );
@@ -1101,7 +1102,7 @@ public class ExtendedResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( extendedResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, extendedResponse );
 
             // Check the length
             assertEquals( 0x3C, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/intermediate/IntermediateResponseTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/intermediate/IntermediateResponseTest.java
index 6d0d960..3510b5c 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/intermediate/IntermediateResponseTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/intermediate/IntermediateResponseTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.intermediate;
 
@@ -27,13 +27,11 @@ import static org.junit.Assert.fail;
 import java.nio.ByteBuffer;
 import java.util.Map;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.IntermediateResponseDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -43,10 +41,13 @@ import org.apache.directory.api.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * Test the IntermediateResponse codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -124,7 +125,7 @@ public class IntermediateResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( intermediateResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, intermediateResponse );
 
             // Check the length
             assertEquals( 0x1D, bb.limit() );
@@ -248,12 +249,12 @@ public class IntermediateResponseTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( intermediateResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, intermediateResponse );
 
             // Check the length
             assertEquals( 0x3A, bb.limit() );
@@ -371,12 +372,12 @@ public class IntermediateResponseTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( intermediateResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, intermediateResponse );
 
             // Check the length
             assertEquals( 0x33, bb.limit() );
@@ -473,7 +474,7 @@ public class IntermediateResponseTest extends AbstractCodecServiceTest
 
 
     /**
-     * Test the decoding of a bad name 
+     * Test the decoding of a bad name
      */
     @Test
     public void testDecodeExtendedBadRequestName()
@@ -588,7 +589,7 @@ public class IntermediateResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( intermediateResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, intermediateResponse );
 
             // Check the length
             assertEquals( 0x16, bb.limit() );
@@ -671,7 +672,7 @@ public class IntermediateResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( intermediateResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, intermediateResponse );
 
             // Check the length
             assertEquals( 0x18, bb.limit() );
@@ -743,7 +744,7 @@ public class IntermediateResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( intermediateResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, intermediateResponse );
 
             // Check the length
             assertEquals( 0x0E, bb.limit() );
@@ -823,7 +824,7 @@ public class IntermediateResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( intermediateResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, intermediateResponse );
 
             // Check the length
             assertEquals( 0x16, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyRequestTest.java
index 9a26729..c98ea2d 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyRequestTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.modify;
 
@@ -32,6 +32,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
 import org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator;
@@ -54,7 +55,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the ModifyRequest codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -217,7 +218,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
 
             // Check the length
             assertEquals( 0x54, bb.limit() );
@@ -560,7 +561,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
         // Check the encoding, by decoding and re-encoding the result
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
 
             // Check the length
             assertEquals( 0x8C, bb.limit() );
@@ -579,7 +580,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
 
             ModifyRequest modifyRequest2 = ldapMessageContainer.getMessage();
 
-            bb = encoder.encodeMessage( modifyRequest2 );
+            bb = LdapEncoder.encodeMessage( codec, modifyRequest2 );
             String decodedPdu2 = Strings.dumpBytes( bb.array() );
 
             assertEquals( decodedPdu1, decodedPdu2 );
@@ -845,7 +846,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
         // Check the encoding, by decoding and re-encoding the result
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
 
             // Check the length
             assertEquals( 0xB9, bb.limit() );
@@ -864,7 +865,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
 
             ModifyRequest modifyRequest2 = ldapMessageContainer.getMessage();
 
-            bb = encoder.encodeMessage( modifyRequest2 );
+            bb = LdapEncoder.encodeMessage( codec, modifyRequest2 );
             String decodedPdu2 = Strings.dumpBytes( bb.array() );
 
             assertEquals( decodedPdu1, decodedPdu2 );
@@ -1039,7 +1040,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
 
             // Check the length
             assertEquals( 0x5C, bb.limit() );
@@ -1962,7 +1963,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
 
             // Check the length
             assertEquals( 0x37, bb.limit() );
@@ -2120,12 +2121,12 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) modifyRequest
             .getControl( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
 
             // Check the length
             assertEquals( 0x54, bb.limit() );
@@ -2257,7 +2258,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
 
             // Check the length
             assertEquals( 0x3D, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyResponseTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyResponseTest.java
index b987df1..e9e42fd 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyResponseTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyResponseTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.modify;
 
@@ -31,6 +31,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.ModifyResponseDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -47,7 +48,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the ModifyResponse codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -115,7 +116,7 @@ public class ModifyResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyResponse );
 
             // Check the length
             assertEquals( 0x0E, bb.limit() );
@@ -228,12 +229,12 @@ public class ModifyResponseTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyResponse );
 
             // Check the length
             assertEquals( 0x2B, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNRequestTest.java
index b94a9a0..df3cf95 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNRequestTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.modifyDn;
 
@@ -27,13 +27,11 @@ import static org.junit.Assert.fail;
 import java.nio.ByteBuffer;
 import java.util.Map;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
 import org.apache.directory.api.ldap.codec.decorators.ModifyDnRequestDecorator;
@@ -47,10 +45,13 @@ import org.apache.directory.api.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * Test the ModifyDNRequest codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -175,7 +176,7 @@ public class ModifyDNRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyDnRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyDnRequest );
 
             // Check the length
             assertEquals( 0x48, bb.limit() );
@@ -687,12 +688,12 @@ public class ModifyDNRequestTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) modifyDnRequest
             .getControl( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyDnRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyDnRequest );
 
             // Check the length
             assertEquals( 0x65, bb.limit() );
@@ -815,7 +816,7 @@ public class ModifyDNRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyDnRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyDnRequest );
 
             // Check the length
             assertEquals( 0x3D, bb.limit() );
@@ -975,12 +976,12 @@ public class ModifyDNRequestTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) modifyDnRequest
             .getControl( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyDnRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyDnRequest );
 
             // Check the length
             assertEquals( 0x5A, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNResponseTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNResponseTest.java
index 20553fb..35f8872 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNResponseTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNResponseTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.modifyDn;
 
@@ -31,6 +31,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.ModifyDnResponseDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -47,7 +48,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the ModifyDNResponse codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -116,7 +117,7 @@ public class ModifyDNResponseTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyDnResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyDnResponse );
 
             // Check the length
             assertEquals( 0x0E, bb.limit() );
@@ -230,12 +231,12 @@ public class ModifyDNResponseTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( modifyDnResponse );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyDnResponse );
 
             // Check the length
             assertEquals( 0x2B, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/osgi/AbstractCodecServiceTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/osgi/AbstractCodecServiceTest.java
index 2a00ad5..95b33b6 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/osgi/AbstractCodecServiceTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/osgi/AbstractCodecServiceTest.java
@@ -22,7 +22,6 @@ package org.apache.directory.api.ldap.codec.osgi;
 
 import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
 import org.apache.directory.api.ldap.codec.api.LdapEncoder;
-import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
 import org.apache.mina.filter.codec.ProtocolDecoder;
@@ -54,12 +53,14 @@ public abstract class AbstractCodecServiceTest
 
         codec.registerProtocolCodecFactory( new ProtocolCodecFactory()
         {
+            @Override
             public ProtocolEncoder getEncoder( IoSession session ) throws Exception
             {
                 return null;
             }
 
 
+            @Override
             public ProtocolDecoder getDecoder( IoSession session ) throws Exception
             {
                 return null;
@@ -70,7 +71,6 @@ public abstract class AbstractCodecServiceTest
         {
             LdapApiServiceFactory.initialize( codec );
         }
-        encoder = new LdapEncoder( codec );
     }
 
 
@@ -81,6 +81,5 @@ public abstract class AbstractCodecServiceTest
     public static void tearDownLdapCodecService()
     {
         codec = null;
-        encoder = null;
     }
 }
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestMatchingRuleAssertionTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestMatchingRuleAssertionTest.java
index 634583c..941b478 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestMatchingRuleAssertionTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestMatchingRuleAssertionTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.search;
 
@@ -32,12 +32,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -54,10 +52,13 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * A test case for SearchRequest messages
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -258,7 +259,7 @@ public class SearchRequestMatchingRuleAssertionTest extends AbstractCodecService
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x63, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestSubstringTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestSubstringTest.java
index 7a60dc0..8864c45 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestSubstringTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestSubstringTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.search;
 
@@ -30,13 +30,11 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -54,10 +52,13 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * A test case for SearchRequest messages
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -113,7 +114,7 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
                 0x01,
                 0x01, //      messageID MessageID
                 0x63,
-                0x5D, //      CHOICE { ..., 
+                0x5D, //      CHOICE { ...,
                 //          searchRequest SearchRequest, ...
                 // SearchRequest ::= APPLICATION[3] SEQUENCE {
                 0x04,
@@ -169,7 +170,7 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
                 0x02,
                 0x02,
                 0x03,
-                ( byte ) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000) 
+                ( byte ) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000)
                 0x01,
                 0x01,
                 ( byte ) 0xFF, // typesOnly
@@ -276,7 +277,7 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x64, bb.limit() );
@@ -509,14 +510,14 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) searchRequest
             .getControl( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         // We won't check the whole PDU, as it may differs because
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x0081, bb.limit() );
@@ -718,7 +719,7 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x64, bb.limit() );
@@ -923,7 +924,7 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x67, bb.limit() );
@@ -1131,7 +1132,7 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x6A, bb.limit() );
@@ -1335,7 +1336,7 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x67, bb.limit() );
@@ -1534,7 +1535,7 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x6A, bb.limit() );
@@ -1738,7 +1739,7 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x67, bb.limit() );
@@ -1948,7 +1949,7 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x6A, bb.limit() );
@@ -2154,7 +2155,7 @@ public class SearchRequestSubstringTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x67, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestTest.java
index eb641ae..9acaacc 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchRequestTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License.
- * 
+ *
  */
 package org.apache.directory.api.ldap.codec.search;
 
@@ -36,6 +36,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.asn1.ber.tlv.TLVStateEnum;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
 import org.apache.directory.api.ldap.codec.controls.search.subentries.SubentriesDecorator;
@@ -72,7 +73,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * A test case for SearchRequest messages
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -370,7 +371,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x90, bb.limit() );
@@ -642,7 +643,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x0090, bb.limit() );
@@ -906,7 +907,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x7B, bb.limit() );
@@ -1058,7 +1059,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x39, bb.limit() );
@@ -1588,7 +1589,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x0096, bb.limit() );
@@ -1928,7 +1929,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x81, bb.limit() );
@@ -2393,7 +2394,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x5F, bb.limit() );
@@ -2711,7 +2712,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x6F, bb.limit() );
@@ -4854,7 +4855,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x43, bb.limit() );
@@ -4879,7 +4880,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
     public void testDecodeSearchRequestEmptyGreaterOrEqualEmptyAttrValueStar()
     {
         byte[] asn1BER = new byte[]
-            { 
+            {
               0x30, 0x44,
                 0x02, 0x01, 0x04, // messageID
                 0x63, 0x3F,
@@ -4899,7 +4900,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
                     0x04, 0x00,
                   0x30, 0x03,             // AttributeDescriptionList ::= SEQUENCE
                                           // OF AttributeDescription
-                    0x04, 0x01, '*' 
+                    0x04, 0x01, '*'
             };
 
         Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -4954,7 +4955,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x46, bb.limit() );
@@ -5558,7 +5559,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x62, bb.limit() );
@@ -5682,7 +5683,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x25, bb.limit() );
@@ -5816,7 +5817,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x27, bb.limit() );
@@ -5967,7 +5968,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x2F, bb.limit() );
@@ -6108,7 +6109,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x29, bb.limit() );
@@ -6267,7 +6268,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x31, bb.limit() );
@@ -6425,7 +6426,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x31, bb.limit() );
@@ -6599,7 +6600,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x39, bb.limit() );
@@ -6773,7 +6774,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x39, bb.limit() );
@@ -6940,7 +6941,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x33, bb.limit() );
@@ -7123,7 +7124,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x3B, bb.limit() );
@@ -7298,7 +7299,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
         // attributes may have been reordered
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchRequest );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchRequest );
 
             // Check the length
             assertEquals( 0x3B, bb.limit() );
@@ -7576,7 +7577,7 @@ public class SearchRequestTest extends AbstractCodecServiceTest
                 0x73,
                 0x73,
                 0x04,
-                0x06, // 'person' 
+                0x06, // 'person'
                 0x70,
                 0x65,
                 0x72,
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultDoneTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultDoneTest.java
index a6da968..a303691 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultDoneTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultDoneTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.search;
 
@@ -31,6 +31,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.SearchResultDoneDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -47,7 +48,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the SearchResultDone codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -113,7 +114,7 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultDone );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultDone );
 
             // Check the length
             assertEquals( 0x0E, bb.limit() );
@@ -226,12 +227,12 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultDone );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultDone );
 
             // Check the length
             assertEquals( 0x2B, bb.limit() );
@@ -348,7 +349,7 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultDone );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultDone );
 
             // Check the length
             assertEquals( 0x0F, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultEntryTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultEntryTest.java
index 962f360..cc5237a 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultEntryTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultEntryTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.search;
 
@@ -33,6 +33,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -50,7 +51,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the SearchResultEntry codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -199,7 +200,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
 
             // Check the length
             assertEquals( 0x50, bb.limit() );
@@ -408,7 +409,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
 
             // Check the length
             assertEquals( 0x7B, bb.limit() );
@@ -603,7 +604,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
 
             // Check the length
             assertEquals( 0x61, bb.limit() );
@@ -868,7 +869,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
 
             // Check the length
             assertEquals( 0x26, bb.limit() );
@@ -1357,7 +1358,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
 
             // Check the length
             assertEquals( 0x37, bb.limit() );
@@ -1504,7 +1505,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
 
             // Check the length
             assertEquals( 0x48, bb.limit() );
@@ -1670,12 +1671,12 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
 
             // Check the length
             assertEquals( 0x54, bb.limit() );
@@ -1807,7 +1808,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
 
             // Check the length
             assertEquals( 0x39, bb.limit() );
@@ -1976,12 +1977,12 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
 
             // Check the length
             assertEquals( 0x56, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultReferenceTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultReferenceTest.java
index 2e8e3e4..36c1741 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultReferenceTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultReferenceTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.search;
 
@@ -30,13 +30,11 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.SearchResultReferenceDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -47,10 +45,13 @@ import org.apache.directory.api.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * Test the SearchResultReference codec
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -162,7 +163,7 @@ public class SearchResultReferenceTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultReference );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultReference );
 
             // Check the length
             assertEquals( 0x3D8, bb.limit() );
@@ -329,12 +330,12 @@ public class SearchResultReferenceTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( org.apache.directory.api.ldap.codec.api.CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultReference );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultReference );
 
             // Check the length
             assertEquals( 0x3F5, bb.limit() );
@@ -466,7 +467,7 @@ public class SearchResultReferenceTest extends AbstractCodecServiceTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( searchResultReference );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultReference );
 
             // Check the length
             assertEquals( 0x11, bb.limit() );
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/unbind/UnBindRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/unbind/UnBindRequestTest.java
index 6956276..9ecda0f 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/unbind/UnBindRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/unbind/UnBindRequestTest.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.unbind;
 
@@ -31,6 +31,7 @@ import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.decorators.UnbindRequestDecorator;
 import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
@@ -62,7 +63,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x07 );
         stream.put( new byte[]
-            { 
+            {
               0x30, 0x05,               // LDAPMessage ::=SEQUENCE {
                 0x02, 0x01, 0x01,       // messageID MessageID
                 0x42, 0x00,             // CHOICE { ..., unbindRequest UnbindRequest,...
@@ -73,7 +74,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
         stream.flip();
 
         // Allocate a BindRequest Container
-        LdapMessageContainer<UnbindRequestDecorator> ldapMessageContainer = 
+        LdapMessageContainer<UnbindRequestDecorator> ldapMessageContainer =
                 new LdapMessageContainer<UnbindRequestDecorator>( codec );
 
         try
@@ -96,7 +97,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
 
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( new UnbindRequestDecorator( codec, internalUnbindRequest ) );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, new UnbindRequestDecorator( codec, internalUnbindRequest ) );
 
             // Check the length
             assertEquals( 0x07, bb.limit() );
@@ -123,7 +124,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x24 );
         stream.put( new byte[]
-            { 
+            {
               0x30, 0x22,               // LDAPMessage ::=SEQUENCE {
                 0x02, 0x01, 0x01,       // messageID MessageID
                 0x42, 0x00,             // CHOICE { ..., unbindRequest UnbindRequest,...
@@ -131,7 +132,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
                 ( byte ) 0xA0, 0x1B,    // A control
                   0x30, 0x19,
                     0x04, 0x17,
-                      '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', 
+                      '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
                       '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
             } );
 
@@ -139,7 +140,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
         stream.flip();
 
         // Allocate a BindRequest Container
-        LdapMessageContainer<UnbindRequestDecorator> ldapMessageContainer = 
+        LdapMessageContainer<UnbindRequestDecorator> ldapMessageContainer =
                 new LdapMessageContainer<UnbindRequestDecorator>( codec );
 
         try
@@ -165,7 +166,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
         CodecControl<Control> control = ( CodecControl<Control> ) controls
             .get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
-        assertEquals( "", Strings.dumpBytes( ( byte[] ) control.getValue() ) );
+        assertEquals( "", Strings.dumpBytes( control.getValue() ) );
 
         // Check the encoding
         UnbindRequest internalUnbindRequest = new UnbindRequestImpl();
@@ -174,7 +175,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
 
         try
         {
-            ByteBuffer bb = encoder.encodeMessage( new UnbindRequestDecorator( codec, internalUnbindRequest ) );
+            ByteBuffer bb = LdapEncoder.encodeMessage( codec, new UnbindRequestDecorator( codec, internalUnbindRequest ) );
 
             // Check the length
             assertEquals( 0x24, bb.limit() );
@@ -201,7 +202,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x09 );
         stream.put( new byte[]
-            { 
+            {
               0x30, 0x07,               // LDAPMessage ::=SEQUENCE {
                 0x02, 0x01, 0x01,       // messageID MessageID
                 0x42, 0x02,             // CHOICE { ..., unbindRequest UnbindRequest,...
@@ -211,7 +212,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
         stream.flip();
 
         // Allocate a LdapMessage Container
-        LdapMessageContainer<UnbindRequestDecorator> ldapMessageContainer = 
+        LdapMessageContainer<UnbindRequestDecorator> ldapMessageContainer =
                 new LdapMessageContainer<UnbindRequestDecorator>( codec );
 
         // Decode a UnbindRequest message
diff --git a/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/AbstractCodecServiceTest.java b/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/AbstractCodecServiceTest.java
index 65204d0..7ee5f06 100644
--- a/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/AbstractCodecServiceTest.java
+++ b/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/AbstractCodecServiceTest.java
@@ -1,27 +1,6 @@
 package org.apache.directory.api.ldap.extras;
 
 
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-
-import org.apache.directory.api.ldap.codec.api.LdapEncoder;
 import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -36,9 +15,6 @@ public abstract class AbstractCodecServiceTest
 {
     protected static DefaultLdapCodecService codec;
 
-    /** The encoder instance */
-    protected static LdapEncoder encoder;
-
 
     /**
      * Initialize the codec service
@@ -47,7 +23,6 @@ public abstract class AbstractCodecServiceTest
     public static void setupLdapCodecService()
     {
         codec = new DefaultLdapCodecService();
-        encoder = new LdapEncoder( codec );
     }
 
 
@@ -58,6 +33,5 @@ public abstract class AbstractCodecServiceTest
     public static void tearDownLdapCodecService()
     {
         codec = null;
-        encoder = null;
     }
 }
diff --git a/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolEncoder.java b/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolEncoder.java
index ee5daa8..68bf3ec 100644
--- a/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolEncoder.java
+++ b/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolEncoder.java
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.codec.protocol.mina;
 
@@ -47,9 +47,8 @@ public class LdapProtocolEncoder implements ProtocolEncoder
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger CODEC_LOG = LoggerFactory.getLogger( Loggers.CODEC_LOG.getName() );
 
-    /** The stateful encoder */
-    private LdapEncoder encoder;
 
+    private LdapApiService codec;
 
     /**
      * Creates a new instance of LdapProtocolEncoder.
@@ -66,7 +65,7 @@ public class LdapProtocolEncoder implements ProtocolEncoder
      */
     public LdapProtocolEncoder( LdapApiService ldapApiService )
     {
-        this.encoder = new LdapEncoder( ldapApiService );
+        codec = ldapApiService;
     }
 
 
@@ -76,7 +75,7 @@ public class LdapProtocolEncoder implements ProtocolEncoder
     @Override
     public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws Exception
     {
-        ByteBuffer buffer = encoder.encodeMessage( ( Message ) message );
+        ByteBuffer buffer = LdapEncoder.encodeMessage( codec, ( Message ) message );
 
         IoBuffer ioBuffer = IoBuffer.wrap( buffer );
 


Mime
View raw message