directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r985183 - in /directory: clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/ shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/ shared/...
Date Fri, 13 Aug 2010 12:54:55 GMT
Author: elecharny
Date: Fri Aug 13 12:54:54 2010
New Revision: 985183

URL: http://svn.apache.org/viewvc?rev=985183&view=rev
Log:
Removed the SearchResultEntryCodec class

Removed:
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryCodec.java
Modified:
    directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/SearchResultAttributeValueAction.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResultEntryImpl.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalSearchResultEntry.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java

Modified: directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=985183&r1=985182&r2=985183&view=diff
==============================================================================
--- directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original)
+++ directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Fri Aug 13 12:54:54 2010
@@ -101,7 +101,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequestCodec;
 import org.apache.directory.shared.ldap.codec.search.Filter;
 import org.apache.directory.shared.ldap.codec.search.SearchRequestCodec;
-import org.apache.directory.shared.ldap.codec.search.SearchResultEntryCodec;
 import org.apache.directory.shared.ldap.codec.search.SearchResultReferenceCodec;
 import org.apache.directory.shared.ldap.codec.unbind.UnBindRequestCodec;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
@@ -131,6 +130,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalModifyDnResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalModifyResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalSearchResultDone;
+import org.apache.directory.shared.ldap.message.internal.InternalSearchResultEntry;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.name.RDN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
@@ -466,39 +466,41 @@ public class LdapNetworkConnection exten
 
 
     /**
-     * Convert a SearchResultEntryCodec to a SearchResultEntry message
+     * Convert a SearchResultDoneImpl to a SearchResultDone message
      */
-    private SearchResultEntry convert( SearchResultEntryCodec searchEntryResultCodec )
+    private SearchResultDone convert( InternalSearchResultDone internalSearchResultDone )
     {
-        SearchResultEntry searchResultEntry = new SearchResultEntry();
+        SearchResultDone searchResultDone = new SearchResultDone();
 
-        searchResultEntry.setMessageId( searchEntryResultCodec.getMessageId() );
-        if ( schemaManager != null )
-        {
-            searchResultEntry.setEntry( new DefaultEntry( schemaManager, searchEntryResultCodec.getEntry() ) );
-        }
-        else
-        {
-            searchResultEntry.setEntry( searchEntryResultCodec.getEntry() );
-        }
-        addControls( searchEntryResultCodec, searchResultEntry );
+        searchResultDone.setMessageId( internalSearchResultDone.getMessageId() );
+        searchResultDone.setLdapResult( convert( internalSearchResultDone.getLdapResult() ) );
+        addControls( internalSearchResultDone, searchResultDone );
 
-        return searchResultEntry;
+        return searchResultDone;
     }
 
 
     /**
-     * Convert a SearchResultDoneCodec to a SearchResultDone message
+     * Convert an InternalSearchResultEntry to a SearchResultEntry message
      */
-    private SearchResultDone convert( InternalSearchResultDone internalSearchResultDone )
+    private SearchResultEntry convert( InternalSearchResultEntry internalSearchResultEntry )
     {
-        SearchResultDone searchResultDone = new SearchResultDone();
+        SearchResultEntry searchResultEntry = new SearchResultEntry();
 
-        searchResultDone.setMessageId( internalSearchResultDone.getMessageId() );
-        searchResultDone.setLdapResult( convert( internalSearchResultDone.getLdapResult() ) );
-        addControls( internalSearchResultDone, searchResultDone );
+        searchResultEntry.setMessageId( internalSearchResultEntry.getMessageId() );
 
-        return searchResultDone;
+        if ( schemaManager != null )
+        {
+            searchResultEntry.setEntry( new DefaultEntry( schemaManager, internalSearchResultEntry.getEntry() ) );
+        }
+        else
+        {
+            searchResultEntry.setEntry( internalSearchResultEntry.getEntry() );
+        }
+
+        addControls( internalSearchResultEntry, searchResultEntry );
+
+        return searchResultEntry;
     }
 
 
@@ -1871,6 +1873,28 @@ public class LdapNetworkConnection exten
 
                     break;
 
+                case SEARCH_RESULT_ENTRY:
+                    // Store the response into the responseQueue
+                    SearchResultEntry searchResultEntry = convert( ( InternalSearchResultEntry ) response );
+
+                    searchFuture = ( SearchFuture ) responseFuture;
+
+                    if ( searchFuture == null )
+                    {
+                        LOG.error( "SearchFuture is null" );
+                        throw new LdapException( "SearchFuture is null" );
+                    }
+
+                    if ( LOG.isDebugEnabled() )
+                    {
+                        LOG.debug( "Search entry found : {}", searchResultEntry );
+                    }
+
+                    // Store the response into the future
+                    searchFuture.set( searchResultEntry );
+
+                    break;
+
             }
         }
         else
@@ -1891,32 +1915,6 @@ public class LdapNetworkConnection exten
 
             switch ( response.getMessageType() )
             {
-                case SEARCH_RESULT_ENTRY:
-                    // Store the response into the responseQueue
-                    SearchResultEntryCodec searchResultEntryCodec = ( SearchResultEntryCodec ) response;
-                    searchResultEntryCodec.setMessageId( messageId );
-                    searchResultEntryCodec.addControls( response.getControls() );
-
-                    SearchResultEntry srchEntry = convert( searchResultEntryCodec );
-
-                    SearchFuture searchFuture = ( SearchFuture ) responseFuture;
-
-                    if ( searchFuture == null )
-                    {
-                        LOG.error( "SearchFuture is null" );
-                        throw new LdapException( "SearchFuture is null" );
-                    }
-
-                    if ( LOG.isDebugEnabled() )
-                    {
-                        LOG.debug( "Search entry found : {}", srchEntry );
-                    }
-
-                    // Store the response into the future
-                    searchFuture.set( srchEntry );
-
-                    break;
-
                 case SEARCH_RESULT_REFERENCE:
                     // Store the response into the responseQueue
                     SearchResultReferenceCodec searchResultReferenceCodec = ( SearchResultReferenceCodec ) response;
@@ -1925,7 +1923,7 @@ public class LdapNetworkConnection exten
 
                     SearchResultReference searchResultReference = convert( searchResultReferenceCodec );
 
-                    searchFuture = ( SearchFuture ) responseFuture;
+                    SearchFuture searchFuture = ( SearchFuture ) responseFuture;
 
                     if ( searchFuture == null )
                     {

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java?rev=985183&r1=985182&r2=985183&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java Fri Aug 13 12:54:54 2010
@@ -31,7 +31,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.modify.ModifyRequestCodec;
 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequestCodec;
 import org.apache.directory.shared.ldap.codec.search.SearchRequestCodec;
-import org.apache.directory.shared.ldap.codec.search.SearchResultEntryCodec;
 import org.apache.directory.shared.ldap.codec.search.SearchResultReferenceCodec;
 import org.apache.directory.shared.ldap.codec.unbind.UnBindRequestCodec;
 import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest;
@@ -49,6 +48,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalModifyDnResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalModifyResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalSearchResultDone;
+import org.apache.directory.shared.ldap.message.internal.InternalSearchResultEntry;
 import org.apache.directory.shared.ldap.message.internal.InternalUnbindRequest;
 import org.apache.directory.shared.ldap.message.spi.BinaryAttributeDetector;
 
@@ -344,11 +344,11 @@ public class LdapMessageContainer extend
 
 
     /**
-     * @return Returns the SearchResultEntryCodec stored in the container
+     * @return Returns the SearchResultEntry stored in the container
      */
-    public SearchResultEntryCodec getSearchResultEntry()
+    public InternalSearchResultEntry getInternalSearchResultEntry()
     {
-        return ( SearchResultEntryCodec ) ldapMessage;
+        return ( InternalSearchResultEntry ) internalMessage;
     }
 
 

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java?rev=985183&r1=985182&r2=985183&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java Fri Aug 13 12:54:54 2010
@@ -77,7 +77,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequestCodec;
 import org.apache.directory.shared.ldap.codec.search.ExtensibleMatchFilter;
 import org.apache.directory.shared.ldap.codec.search.SearchRequestCodec;
-import org.apache.directory.shared.ldap.codec.search.SearchResultEntryCodec;
 import org.apache.directory.shared.ldap.codec.search.SearchResultReferenceCodec;
 import org.apache.directory.shared.ldap.codec.search.SubstringFilter;
 import org.apache.directory.shared.ldap.exception.LdapException;
@@ -99,6 +98,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.ReferralImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.SearchResultDoneImpl;
+import org.apache.directory.shared.ldap.message.SearchResultEntryImpl;
 import org.apache.directory.shared.ldap.message.UnbindRequestImpl;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest;
@@ -119,6 +119,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalReferral;
 import org.apache.directory.shared.ldap.message.internal.InternalResultResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalSearchResultDone;
+import org.apache.directory.shared.ldap.message.internal.InternalSearchResultEntry;
 import org.apache.directory.shared.ldap.message.internal.InternalUnbindRequest;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.name.RDN;
@@ -1106,9 +1107,9 @@ public class LdapMessageGrammar extends 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
 
                     // Now, we can allocate the SearchResultEntry Object
-                    SearchResultEntryCodec searchResultEntry = new SearchResultEntryCodec();
-                    searchResultEntry.setMessageId( ldapMessageContainer.getMessageId() );
-                    ldapMessageContainer.setLdapMessage( searchResultEntry );
+                    InternalSearchResultEntry searchResultEntry = new SearchResultEntryImpl( ldapMessageContainer
+                        .getMessageId() );
+                    ldapMessageContainer.setInternalMessage( searchResultEntry );
                 }
             } );
 
@@ -1128,7 +1129,7 @@ public class LdapMessageGrammar extends 
                 {
 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
-                    SearchResultEntryCodec searchResultEntry = ldapMessageContainer.getSearchResultEntry();
+                    InternalSearchResultEntry searchResultEntry = ldapMessageContainer.getInternalSearchResultEntry();
 
                     TLV tlv = ldapMessageContainer.getCurrentTLV();
 
@@ -1234,7 +1235,7 @@ public class LdapMessageGrammar extends 
                 public void action( IAsn1Container container ) throws DecoderException
                 {
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
-                    SearchResultEntryCodec searchResultEntry = ldapMessageContainer.getSearchResultEntry();
+                    InternalSearchResultEntry searchResultEntry = ldapMessageContainer.getInternalSearchResultEntry();
 
                     TLV tlv = ldapMessageContainer.getCurrentTLV();
 
@@ -1251,7 +1252,18 @@ public class LdapMessageGrammar extends 
                     else
                     {
                         type = StringTools.getType( tlv.getValue().getData() );
-                        searchResultEntry.addAttributeValues( type );
+
+                        try
+                        {
+                            searchResultEntry.addAttribute( type );
+                        }
+                        catch ( LdapException ine )
+                        {
+                            // This is for the client side. We will never decode LdapResult on the server
+                            String msg = "The Attribute type " + type + "is invalid : " + ine.getMessage();
+                            log.error( "{} : {}", msg, ine.getMessage() );
+                            throw new DecoderException( msg, ine );
+                        }
                     }
 
                     if ( IS_DEBUG )

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java?rev=985183&r1=985182&r2=985183&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java Fri Aug 13 12:54:54 2010
@@ -23,14 +23,19 @@ package org.apache.directory.shared.ldap
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.asn1.util.Asn1StringUtils;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.codec.controls.CodecControl;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.message.AddResponseImpl;
 import org.apache.directory.shared.ldap.message.BindResponseImpl;
 import org.apache.directory.shared.ldap.message.CompareResponseImpl;
@@ -40,6 +45,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.ModifyDnResponseImpl;
 import org.apache.directory.shared.ldap.message.ModifyResponseImpl;
 import org.apache.directory.shared.ldap.message.SearchResultDoneImpl;
+import org.apache.directory.shared.ldap.message.SearchResultEntryImpl;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.message.internal.InternalAddResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalBindResponse;
@@ -53,6 +59,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalModifyResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalReferral;
 import org.apache.directory.shared.ldap.message.internal.InternalSearchResultDone;
+import org.apache.directory.shared.ldap.message.internal.InternalSearchResultEntry;
+import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.mina.core.buffer.IoBuffer;
 import org.apache.mina.core.session.IoSession;
@@ -117,7 +125,7 @@ public class LdapProtocolEncoder extends
             || ( message instanceof InternalAddResponse ) || ( message instanceof InternalCompareResponse )
             || ( message instanceof InternalExtendedResponse ) || ( message instanceof InternalModifyResponse )
             || ( message instanceof InternalModifyDnResponse ) || ( message instanceof InternalIntermediateResponse )
-            || ( message instanceof InternalSearchResultDone ) )
+            || ( message instanceof InternalSearchResultDone ) || ( message instanceof InternalSearchResultEntry ) )
         {
             try
             {
@@ -648,6 +656,133 @@ public class LdapProtocolEncoder extends
 
 
     /**
+     * Compute the SearchResultEntry length
+     * 
+     * SearchResultEntry :
+     * <pre>
+     * 0x64 L1
+     *  |
+     *  +--> 0x04 L2 objectName
+     *  +--> 0x30 L3 (attributes)
+     *        |
+     *        +--> 0x30 L4-1 (partial attributes list)
+     *        |     |
+     *        |     +--> 0x04 L5-1 type
+     *        |     +--> 0x31 L6-1 (values)
+     *        |           |
+     *        |           +--> 0x04 L7-1-1 value
+     *        |           +--> ...
+     *        |           +--> 0x04 L7-1-n value
+     *        |
+     *        +--> 0x30 L4-2 (partial attributes list)
+     *        |     |
+     *        |     +--> 0x04 L5-2 type
+     *        |     +--> 0x31 L6-2 (values)
+     *        |           |
+     *        |           +--> 0x04 L7-2-1 value
+     *        |           +--> ...
+     *        |           +--> 0x04 L7-2-n value
+     *        |
+     *        +--> ...
+     *        |
+     *        +--> 0x30 L4-m (partial attributes list)
+     *              |
+     *              +--> 0x04 L5-m type
+     *              +--> 0x31 L6-m (values)
+     *                    |
+     *                    +--> 0x04 L7-m-1 value
+     *                    +--> ...
+     *                    +--> 0x04 L7-m-n value
+     * </pre>
+     */
+    private int computeSearchResultEntryLength( InternalSearchResultEntry searchResultEntry )
+    {
+        DN dn = searchResultEntry.getObjectName();
+
+        byte[] dnBytes = StringTools.getBytesUtf8( dn.getName() );
+
+        // The entry
+        int searchResultEntryLength = 1 + TLV.getNbBytes( dnBytes.length ) + dnBytes.length;
+        searchResultEntry.setObjectNameBytes( dnBytes );
+
+        // The attributes sequence
+        int attributesLength = 0;
+
+        Entry entry = searchResultEntry.getEntry();
+
+        if ( ( entry != null ) && ( entry.size() != 0 ) )
+        {
+            List<Integer> attributeLength = new LinkedList<Integer>();
+            List<Integer> valsLength = new LinkedList<Integer>();
+
+            // Store those lists in the object
+            searchResultEntry.setAttributeLength( attributeLength );
+            searchResultEntry.setValsLength( valsLength );
+
+            // Compute the attributes length
+            for ( EntryAttribute attribute : entry )
+            {
+                int localAttributeLength = 0;
+                int localValuesLength = 0;
+
+                // Get the type length
+                int idLength = attribute.getId().getBytes().length;
+                localAttributeLength = 1 + TLV.getNbBytes( idLength ) + idLength;
+
+                if ( attribute.size() != 0 )
+                {
+                    // The values
+                    if ( attribute.size() > 0 )
+                    {
+                        localValuesLength = 0;
+
+                        for ( org.apache.directory.shared.ldap.entry.Value<?> value : attribute )
+                        {
+                            byte[] binaryValue = value.getBytes();
+                            localValuesLength += 1 + TLV.getNbBytes( binaryValue.length ) + binaryValue.length;
+                        }
+
+                        localAttributeLength += 1 + TLV.getNbBytes( localValuesLength ) + localValuesLength;
+                    }
+                    else
+                    {
+                        // We have to deal with the special wase where
+                        // we don't have a value.
+                        // It will be encoded as an empty OCTETSTRING,
+                        // so it will be two byte slong (0x04 0x00)
+                        localAttributeLength += 1 + 1;
+                    }
+                }
+                else
+                {
+                    // We have no values. We will just have an empty SET OF :
+                    // 0x31 0x00
+                    localAttributeLength += 1 + 1;
+                }
+
+                // add the attribute length to the attributes length
+                attributesLength += 1 + TLV.getNbBytes( localAttributeLength ) + localAttributeLength;
+
+                // Store the lengths of the encoded attributes and values
+                attributeLength.add( localAttributeLength );
+                valsLength.add( localValuesLength );
+            }
+
+            // Store the lengths of the entry
+            searchResultEntry.setAttributesLength( attributesLength );
+        }
+
+        searchResultEntryLength += 1 + TLV.getNbBytes( attributesLength ) + attributesLength;
+
+        // Store the length of the response 
+        searchResultEntry.setSearchResultEntryLength( searchResultEntryLength );
+
+        // Return the result.
+        return 1 + TLV.getNbBytes( searchResultEntryLength ) + searchResultEntryLength;
+    }
+
+
+    /**
      * Encode the AddResponse message to a PDU.
      * 
      * @param buffer The buffer where to put the PDU
@@ -942,6 +1077,97 @@ public class LdapProtocolEncoder extends
 
 
     /**
+     * Encode the SearchResultEntry message to a PDU.
+     * 
+     * SearchResultEntry :
+     * <pre>
+     * 0x64 LL
+     *   0x04 LL objectName
+     *   0x30 LL attributes
+     *     0x30 LL partialAttributeList
+     *       0x04 LL type
+     *       0x31 LL vals
+     *         0x04 LL attributeValue
+     *         ... 
+     *         0x04 LL attributeValue
+     *     ... 
+     *     0x30 LL partialAttributeList
+     *       0x04 LL type
+     *       0x31 LL vals
+     *         0x04 LL attributeValue
+     *         ... 
+     *         0x04 LL attributeValue 
+     * </pre>
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    private void encodeSearchResultEntry( ByteBuffer buffer, SearchResultEntryImpl searchResultEntry )
+        throws EncoderException
+    {
+        try
+        {
+            // The SearchResultEntry Tag
+            buffer.put( LdapConstants.SEARCH_RESULT_ENTRY_TAG );
+            buffer.put( TLV.getBytes( searchResultEntry.getSearchResultEntryLength() ) );
+
+            // The objectName
+            Value.encode( buffer, searchResultEntry.getObjectNameBytes() );
+
+            // The attributes sequence
+            buffer.put( UniversalTag.SEQUENCE_TAG );
+            buffer.put( TLV.getBytes( searchResultEntry.getAttributesLength() ) );
+
+            // The partial attribute list
+            Entry entry = searchResultEntry.getEntry();
+
+            if ( ( entry != null ) && ( entry.size() != 0 ) )
+            {
+                int attributeNumber = 0;
+
+                // Compute the attributes length
+                for ( EntryAttribute attribute : entry )
+                {
+                    // The partial attribute list sequence
+                    buffer.put( UniversalTag.SEQUENCE_TAG );
+                    int localAttributeLength = searchResultEntry.getAttributeLength().get( attributeNumber );
+                    buffer.put( TLV.getBytes( localAttributeLength ) );
+
+                    // The attribute type
+                    Value.encode( buffer, Asn1StringUtils.asciiStringToByte( attribute.getUpId() ) );
+
+                    // The values
+                    buffer.put( UniversalTag.SET_TAG );
+                    int localValuesLength = searchResultEntry.getValsLength().get( attributeNumber );
+                    buffer.put( TLV.getBytes( localValuesLength ) );
+
+                    if ( attribute.size() > 0 )
+                    {
+                        for ( org.apache.directory.shared.ldap.entry.Value<?> value : attribute )
+                        {
+                            if ( !value.isBinary() )
+                            {
+                                Value.encode( buffer, value.getString() );
+                            }
+                            else
+                            {
+                                Value.encode( buffer, value.getBytes() );
+                            }
+                        }
+                    }
+
+                    // Go to the next attribute number;
+                    attributeNumber++;
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+        }
+    }
+
+
+    /**
      * Compute the protocolOp length 
      */
     private int computeProtocolOpLength( InternalMessage message )
@@ -975,6 +1201,9 @@ public class LdapProtocolEncoder extends
             case SEARCH_RESULT_DONE:
                 return computeSearchResultDoneLength( ( SearchResultDoneImpl ) message );
 
+            case SEARCH_RESULT_ENTRY:
+                return computeSearchResultEntryLength( ( SearchResultEntryImpl ) message );
+
             default:
                 return 0;
         }
@@ -1019,6 +1248,10 @@ public class LdapProtocolEncoder extends
 
             case SEARCH_RESULT_DONE:
                 encodeSearchResultDone( bb, ( SearchResultDoneImpl ) message );
+                break;
+
+            case SEARCH_RESULT_ENTRY:
+                encodeSearchResultEntry( bb, ( SearchResultEntryImpl ) message );
         }
     }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java?rev=985183&r1=985182&r2=985183&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java Fri Aug 13 12:54:54 2010
@@ -41,7 +41,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.search.OrFilter;
 import org.apache.directory.shared.ldap.codec.search.PresentFilter;
 import org.apache.directory.shared.ldap.codec.search.SearchRequestCodec;
-import org.apache.directory.shared.ldap.codec.search.SearchResultEntryCodec;
 import org.apache.directory.shared.ldap.codec.search.SearchResultReferenceCodec;
 import org.apache.directory.shared.ldap.codec.search.SubstringFilter;
 import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
@@ -70,7 +69,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.ModifyRequestImpl;
 import org.apache.directory.shared.ldap.message.ReferralImpl;
 import org.apache.directory.shared.ldap.message.SearchRequestImpl;
-import org.apache.directory.shared.ldap.message.SearchResultEntryImpl;
 import org.apache.directory.shared.ldap.message.SearchResultReferenceImpl;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.message.extended.GracefulShutdownRequest;
@@ -695,27 +693,6 @@ public class LdapTransformer
 
 
     /**
-     * Transform a Internal SearchResponseEntry to a Codec SearchResultEntry
-     * 
-     * @param internalMessage The incoming Internal SearchResponseEntry
-     */
-    private static LdapMessageCodec transformSearchResultEntry( InternalMessage internalMessage )
-    {
-        SearchResultEntryImpl internalSearchResultResponse = ( SearchResultEntryImpl ) internalMessage;
-        SearchResultEntryCodec searchResultEntry = new SearchResultEntryCodec();
-
-        // Internal : DN dn -> Codec : DN objectName
-        searchResultEntry.setObjectName( internalSearchResultResponse.getObjectName() );
-
-        // Internal : Attributes attributes -> Codec : ArrayList
-        // partialAttributeList
-        searchResultEntry.setEntry( internalSearchResultResponse.getEntry() );
-
-        return searchResultEntry;
-    }
-
-
-    /**
      * Transform a Internal SearchResponseReference to a Codec
      * SearchResultReference
      * 
@@ -773,10 +750,6 @@ public class LdapTransformer
 
         switch ( msg.getType() )
         {
-            case SEARCH_RESULT_ENTRY:
-                codecMessage = transformSearchResultEntry( msg );
-                break;
-
             case SEARCH_RESULT_REFERENCE:
                 codecMessage = transformSearchResultReference( msg );
                 break;

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/SearchResultAttributeValueAction.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/SearchResultAttributeValueAction.java?rev=985183&r1=985182&r2=985183&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/SearchResultAttributeValueAction.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/SearchResultAttributeValueAction.java Fri Aug 13 12:54:54 2010
@@ -24,7 +24,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
-import org.apache.directory.shared.ldap.codec.search.SearchResultEntryCodec;
+import org.apache.directory.shared.ldap.message.internal.InternalSearchResultEntry;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,18 +43,20 @@ public class SearchResultAttributeValueA
     /** Speedup for logs */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
 
+
     public SearchResultAttributeValueAction()
     {
         super( "Stores AttributeValue" );
     }
 
+
     /**
      * The initialization action
      */
     public void action( IAsn1Container container )
     {
         LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
-        SearchResultEntryCodec searchResultEntry = ldapMessageContainer.getSearchResultEntry();
+        InternalSearchResultEntry searchResultEntry = ldapMessageContainer.getInternalSearchResultEntry();
 
         TLV tlv = ldapMessageContainer.getCurrentTLV();
 
@@ -69,7 +71,7 @@ public class SearchResultAttributeValueA
         }
         else
         {
-            if ( ldapMessageContainer.isBinary( searchResultEntry.getCurrentAttributeValueType() ) )
+            if ( ldapMessageContainer.isBinary( searchResultEntry.getCurrentAttribute().getId() ) )
             {
                 value = tlv.getValue().getData();
 

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResultEntryImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResultEntryImpl.java?rev=985183&r1=985182&r2=985183&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResultEntryImpl.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResultEntryImpl.java Fri Aug 13 12:54:54 2010
@@ -20,7 +20,13 @@
 package org.apache.directory.shared.ldap.message;
 
 
+import java.util.List;
+
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
 import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.message.internal.InternalAbstractResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalSearchResultEntry;
 import org.apache.directory.shared.ldap.name.DN;
@@ -36,13 +42,30 @@ public class SearchResultEntryImpl exten
     static final long serialVersionUID = -8357316233060886637L;
 
     /** Entry returned in response to search */
-    private Entry entry;
+    private Entry entry = new DefaultEntry();
+
+    /** The current attribute being decoded */
+    private EntryAttribute currentAttribute;
+
+    /** A temporary storage for the byte[] representing the objectName */
+    private byte[] objectNameBytes;
+
+    /** The search result entry length */
+    private int searchResultEntryLength;
+
+    /** The partial attributes length */
+    private int attributesLength;
+
+    /** The list of all attributes length */
+    private List<Integer> attributeLength;
+
+    /** The list of all vals length */
+    private List<Integer> valsLength;
 
 
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
-
     /**
      * Creates a SearchResponseEntry as a reply to an SearchRequest to
      * indicate the end of a search operation.
@@ -71,6 +94,46 @@ public class SearchResultEntryImpl exten
 
 
     /**
+     * Create a new attribute
+     * 
+     * @param type The attribute's type
+     */
+    public void addAttribute( String type ) throws LdapException
+    {
+        currentAttribute = new DefaultEntryAttribute( type );
+
+        entry.put( currentAttribute );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public EntryAttribute getCurrentAttribute()
+    {
+        return currentAttribute;
+    }
+
+
+    /**
+     * Add a new value to the current attribute
+     * 
+     * @param value The added value
+     */
+    public void addAttributeValue( Object value )
+    {
+        if ( value instanceof String )
+        {
+            currentAttribute.add( ( String ) value );
+        }
+        else
+        {
+            currentAttribute.add( ( byte[] ) value );
+        }
+    }
+
+
+    /**
      * Sets the entry.
      * 
      * @param entry the entry
@@ -93,10 +156,27 @@ public class SearchResultEntryImpl exten
 
 
     /**
+     * {@inheritDoc}
+     */
+    public byte[] getObjectNameBytes()
+    {
+        return objectNameBytes;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setObjectNameBytes( byte[] objectNameBytes )
+    {
+        this.objectNameBytes = objectNameBytes;
+    }
+
+
+    /**
      * Sets the distinguished name of the entry object returned.
      * 
-     * @param objectName
-     *            the Dn of the entry returned.
+     * @param objectName the Dn of the entry returned.
      */
     public void setObjectName( DN objectName )
     {
@@ -175,4 +255,52 @@ public class SearchResultEntryImpl exten
 
         return sb.toString();
     }
+
+
+    public int getSearchResultEntryLength()
+    {
+        return searchResultEntryLength;
+    }
+
+
+    public void setSearchResultEntryLength( int searchResultEntryLength )
+    {
+        this.searchResultEntryLength = searchResultEntryLength;
+    }
+
+
+    public int getAttributesLength()
+    {
+        return attributesLength;
+    }
+
+
+    public void setAttributesLength( int attributesLength )
+    {
+        this.attributesLength = attributesLength;
+    }
+
+
+    public List<Integer> getAttributeLength()
+    {
+        return attributeLength;
+    }
+
+
+    public void setAttributeLength( List<Integer> attributeLength )
+    {
+        this.attributeLength = attributeLength;
+    }
+
+
+    public List<Integer> getValsLength()
+    {
+        return valsLength;
+    }
+
+
+    public void setValsLength( List<Integer> valsLength )
+    {
+        this.valsLength = valsLength;
+    }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalSearchResultEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalSearchResultEntry.java?rev=985183&r1=985182&r2=985183&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalSearchResultEntry.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalSearchResultEntry.java Fri Aug 13 12:54:54 2010
@@ -21,8 +21,12 @@
 package org.apache.directory.shared.ldap.message.internal;
 
 
+import java.util.List;
+
 import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
 import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.name.DN;
 
 
@@ -49,9 +53,25 @@ public interface InternalSearchResultEnt
     /**
      * Sets the distinguished name of the entry object returned.
      * 
-     * @param dn the Dn of the entry returned.
+     * @param objectName the Dn of the entry returned.
+     */
+    void setObjectName( DN objectName );
+
+
+    /**
+     * Gets the distinguished name bytes of the entry object returned.
+     * 
+     * @return the Dn bytes of the entry returned.
      */
-    void setObjectName( DN dn );
+    byte[] getObjectNameBytes();
+
+
+    /**
+     * Sets the distinguished name bytes of the entry object returned.
+     * 
+     * @param objectNameBytes the Dn bytes of the entry returned.
+     */
+    void setObjectNameBytes( byte[] objectNameBytes );
 
 
     /**
@@ -68,4 +88,78 @@ public interface InternalSearchResultEnt
      * @param entry the entry
      */
     void setEntry( Entry entry );
+
+
+    /**
+     * Create a new attribute
+     * 
+     * @param type The attribute's type
+     */
+    void addAttribute( String type ) throws LdapException;
+
+
+    /**
+     * @return Returns the currentAttribute.
+     */
+    EntryAttribute getCurrentAttribute();
+
+
+    /**
+     * Add a new value to the current attribute
+     * 
+     * @param value The added value
+     */
+    void addAttributeValue( Object value );
+
+
+    /**
+     * @return The encoded SearchResultEntry's length
+     */
+    int getSearchResultEntryLength();
+
+
+    /**
+     * Stores the encoded length for the SearchResultEntry
+     * @param searchResultEntryLength The encoded length
+     */
+    void setSearchResultEntryLength( int searchResultEntryLength );
+
+
+    /**
+     * @return The encoded PartialAttributeList's length
+     */
+    int getAttributesLength();
+
+
+    /**
+     * Stores the encoded length for the PartialAttributeList
+     * @param attributesLength The encoded length
+     */
+    void setAttributesLength( int attributesLength );
+
+
+    /**
+     * @return The list of encoded Attributes' length
+     */
+    List<Integer> getAttributeLength();
+
+
+    /**
+     * Stores the encoded length for the Attributes
+     * @param attributeLength The list of encoded lengths
+     */
+    void setAttributeLength( List<Integer> attributeLength );
+
+
+    /**
+     * @return The list of encoded values' length
+     */
+    List<Integer> getValsLength();
+
+
+    /**
+     * Stores the list of encoded length for the values 
+     * @param valsLength The list of encoded lengths
+     */
+    void setValsLength( List<Integer> valsLength );
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java?rev=985183&r1=985182&r2=985183&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java Fri Aug 13 12:54:54 2010
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
 
 import javax.naming.NamingException;
 
@@ -36,9 +36,11 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.codec.LdapProtocolEncoder;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.internal.InternalSearchResultEntry;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -53,6 +55,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class SearchResultEntryTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a SearchResultEntry
      */
@@ -66,10 +72,14 @@ public class SearchResultEntryTest
         stream.put( new byte[]
             {
 
-            0x30, 0x4e, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x49, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            0x30,
+                0x4e, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x49, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
@@ -102,7 +112,8 @@ public class SearchResultEntryTest
             fail( de.getMessage() );
         }
 
-        SearchResultEntryCodec searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer ).getSearchResultEntry();
+        InternalSearchResultEntry searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer )
+            .getInternalSearchResultEntry();
 
         assertEquals( 1, searchResultEntry.getMessageId() );
         assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
@@ -121,13 +132,13 @@ public class SearchResultEntryTest
             assertTrue( attribute.contains( "organizationalUnit" ) );
         }
 
-        // Check the length
-        assertEquals( 0x50, searchResultEntry.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = searchResultEntry.encode();
+            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+
+            // Check the length
+            assertEquals( 0x50, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -152,14 +163,20 @@ public class SearchResultEntryTest
         ByteBuffer stream = ByteBuffer.allocate( 0x7b );
 
         stream.put( new byte[]
-            { 0x30, 0x79, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x74, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            {
+                0x30,
+                0x79, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x74, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
-                'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm',
+                'e', 'k', ',', 'd', 'c', '=', 'c', 'o',
+                'm',
                 // attributes PartialAttributeList }
                 // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
                 0x30, 0x55, 0x30, 0x28,
@@ -196,7 +213,8 @@ public class SearchResultEntryTest
             fail( de.getMessage() );
         }
 
-        SearchResultEntryCodec searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer ).getSearchResultEntry();
+        InternalSearchResultEntry searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer )
+            .getInternalSearchResultEntry();
 
         assertEquals( 1, searchResultEntry.getMessageId() );
         assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
@@ -214,17 +232,17 @@ public class SearchResultEntryTest
 
             assertEquals( expectedAttributes[i].toLowerCase(), attribute.getId().toLowerCase() );
 
-            assertTrue( attribute.contains(  "top" ) );
-            assertTrue( attribute.contains(  "organizationalUnit" ) );
+            assertTrue( attribute.contains( "top" ) );
+            assertTrue( attribute.contains( "organizationalUnit" ) );
         }
 
-        // Check the length
-        assertEquals( 0x7b, searchResultEntry.computeLength() );
-
         // Check the encoding
         try
         {
-            searchResultEntry.encode();
+            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+
+            // Check the length
+            assertEquals( 0x7B, bb.limit() );
 
             // We can't compare the encodings, the order of the attributes has
             // changed
@@ -249,23 +267,34 @@ public class SearchResultEntryTest
         ByteBuffer stream = ByteBuffer.allocate( 0x66 );
 
         stream.put( new byte[]
-            { 0x30, 0x5F, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x02, // messageID MessageID
-                0x64, 0x5A, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            {
+                0x30,
+                0x5F, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x02, // messageID MessageID
+                0x64,
+                0x5A, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x13, 'u', 'i', 'd', '=', 'a', 'd', 'm', 'i', 'n', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e',
                 'm',
                 // attributes PartialAttributeList }
-                0x30, 0x43, // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30,
+                0x43, // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
                 0x30, 0x41,
                 // type AttributeDescription,
-                0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x31, 0x32, // vals
-                                                                                                // SET
-                                                                                                // OF
-                                                                                                // AttributeValue
-                                                                                                // }
+                0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l',
+                'a',
+                's',
+                's',
+                0x31,
+                0x32, // vals
+                // SET
+                // OF
+                // AttributeValue
+                // }
                 // AttributeValue ::= OCTET STRING
                 0x04, 0x0D, 'i', 'n', 'e', 't', 'O', 'r', 'g', 'P', 'e', 'r', 's', 'o', 'n',
                 // AttributeValue ::= OCTET STRING
@@ -275,7 +304,7 @@ public class SearchResultEntryTest
                 0x04, 0x06, 'p', 'e', 'r', 's', 'o', 'n',
                 // AttributeValue ::= OCTET STRING
                 0x04, 0x03, 't', 'o', 'p', 0x30, 0x45, // Start of the next
-                                                        // message
+                // message
                 0x02, 0x01, 0x02 // messageID MessageID ...
             } );
 
@@ -295,7 +324,8 @@ public class SearchResultEntryTest
             fail( de.getMessage() );
         }
 
-        SearchResultEntryCodec searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer ).getSearchResultEntry();
+        InternalSearchResultEntry searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer )
+            .getInternalSearchResultEntry();
 
         assertEquals( 2, searchResultEntry.getMessageId() );
         assertEquals( "uid=admin,ou=system", searchResultEntry.getObjectName().toString() );
@@ -316,9 +346,6 @@ public class SearchResultEntryTest
             assertTrue( attribute.contains( "inetOrgPerson" ) );
         }
 
-        // Check the length
-        assertEquals( 0x61, searchResultEntry.computeLength() );
-
         // Check that the next bytes is the first of the next PDU
         assertEquals( 0x30, stream.get( stream.position() ) );
         assertEquals( 0x45, stream.get( stream.position() + 1 ) );
@@ -329,7 +356,10 @@ public class SearchResultEntryTest
         // Check the encoding
         try
         {
-            ByteBuffer bb = searchResultEntry.encode();
+            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+
+            // Check the length
+            assertEquals( 0x61, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -363,7 +393,7 @@ public class SearchResultEntryTest
             0x30, 0x05, // LDAPMessage ::=SEQUENCE {
                 0x02, 0x01, 0x01, // messageID MessageID
                 0x64, 0x00 // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            // ...
             } );
 
         stream.flip();
@@ -399,7 +429,7 @@ public class SearchResultEntryTest
             { 0x30, 0x07, // LDAPMessage ::=SEQUENCE {
                 0x02, 0x01, 0x01, // messageID MessageID
                 0x64, 0x02, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x00
@@ -436,10 +466,14 @@ public class SearchResultEntryTest
         ByteBuffer stream = ByteBuffer.allocate( 0x24 );
 
         stream.put( new byte[]
-            { 0x30, 0x22, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x1D, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            { 0x30,
+                0x22, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x1D, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1B, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
@@ -477,10 +511,14 @@ public class SearchResultEntryTest
         ByteBuffer stream = ByteBuffer.allocate( 0x26 );
 
         stream.put( new byte[]
-            { 0x30, 0x24, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x1F, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            { 0x30,
+                0x24, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x1F, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1B, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
@@ -505,7 +543,8 @@ public class SearchResultEntryTest
             fail( de.getMessage() );
         }
 
-        SearchResultEntryCodec searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer ).getSearchResultEntry();
+        InternalSearchResultEntry searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer )
+            .getInternalSearchResultEntry();
 
         assertEquals( 1, searchResultEntry.getMessageId() );
         assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
@@ -514,13 +553,13 @@ public class SearchResultEntryTest
 
         assertEquals( 0, entry.size() );
 
-        // Check the length
-        assertEquals( 0x26, searchResultEntry.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = searchResultEntry.encode();
+            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+
+            // Check the length
+            assertEquals( 0x26, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -545,10 +584,14 @@ public class SearchResultEntryTest
         ByteBuffer stream = ByteBuffer.allocate( 0x28 );
 
         stream.put( new byte[]
-            { 0x30, 0x26, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x21, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            { 0x30,
+                0x26, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x21, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1B, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
@@ -588,25 +631,26 @@ public class SearchResultEntryTest
         ByteBuffer stream = ByteBuffer.allocate( 0x45 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x43,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x64, 0x21,               // CHOICE { ..., searchResEntry SearchResultEntry,
-                                        // ...
-                                        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
-                                        // objectName LDAPDN,
-                0x04, 0x1B, 
-                  'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 
-                  'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm',
-                                        // attributes PartialAttributeList }
-                                        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
-                0x30, 0x02, 
-                  0x30, 0x00, 
-              ( byte ) 0xA0, 0x1B,      // A control
-                0x30, 0x19, 
-                  0x04, 0x17,
-                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', 
-                    '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2' } );
+            {
+                0x30,
+                0x43, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x21, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
+                // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+                // objectName LDAPDN,
+                0x04, 0x1B, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
+                'e', 'k', ',', 'd', 'c', '=', 'c', 'o',
+                'm',
+                // attributes PartialAttributeList }
+                // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30, 0x02, 0x30, 0x00, ( byte ) 0xA0,
+                0x1B, // A control
+                0x30, 0x19, 0x04, 0x17, '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
+                '0', '.', '3', '.', '4', '.', '2' } );
 
         stream.flip();
 
@@ -640,10 +684,14 @@ public class SearchResultEntryTest
         stream.put( new byte[]
             {
 
-            0x30, 0x28, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x23, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            0x30,
+                0x28, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x23, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
@@ -686,10 +734,14 @@ public class SearchResultEntryTest
         stream.put( new byte[]
             {
 
-            0x30, 0x33, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x2E, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            0x30,
+                0x33, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x2E, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
@@ -732,10 +784,14 @@ public class SearchResultEntryTest
         stream.put( new byte[]
             {
 
-            0x30, 0x35, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x30, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            0x30,
+                0x35, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x30, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
@@ -762,7 +818,8 @@ public class SearchResultEntryTest
             fail( de.getMessage() );
         }
 
-        SearchResultEntryCodec searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer ).getSearchResultEntry();
+        InternalSearchResultEntry searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer )
+            .getInternalSearchResultEntry();
 
         assertEquals( 1, searchResultEntry.getMessageId() );
         assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
@@ -779,13 +836,13 @@ public class SearchResultEntryTest
             assertEquals( 0, attribute.size() );
         }
 
-        // Check the length
-        assertEquals( 0x37, searchResultEntry.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = searchResultEntry.encode();
+            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+
+            // Check the length
+            assertEquals( 0x37, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -812,10 +869,14 @@ public class SearchResultEntryTest
         stream.put( new byte[]
             {
 
-            0x30, 0x46, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x41, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            0x30,
+                0x46, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x41, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
@@ -844,7 +905,8 @@ public class SearchResultEntryTest
             fail( de.getMessage() );
         }
 
-        SearchResultEntryCodec searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer ).getSearchResultEntry();
+        InternalSearchResultEntry searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer )
+            .getInternalSearchResultEntry();
 
         assertEquals( 1, searchResultEntry.getMessageId() );
         assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
@@ -861,13 +923,13 @@ public class SearchResultEntryTest
         assertEquals( "objectClazz".toLowerCase(), attribute.getId().toLowerCase() );
         assertEquals( 0, attribute.size() );
 
-        // Check the length
-        assertEquals( 0x48, searchResultEntry.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = searchResultEntry.encode();
+            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+
+            // Check the length
+            assertEquals( 0x48, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -894,20 +956,26 @@ public class SearchResultEntryTest
         stream.put( new byte[]
             {
 
-            0x30, 0x52, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x30, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+                0x30,
+                0x52, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x30, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
-                'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm',
+                'e', 'k', ',', 'd', 'c', '=', 'c', 'o',
+                'm',
                 // attributes PartialAttributeList }
                 // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
                 0x30, 0x11, 0x30, 0x0F,
                 // type AttributeDescription,
-                0x04, 0x0b, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x31, 0x00, ( byte ) 0xA0, 0x1B, // A
-                                                                                                                    // control
+                0x04, 0x0b, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x31, 0x00, ( 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 } );
 
@@ -927,7 +995,8 @@ public class SearchResultEntryTest
             fail( de.getMessage() );
         }
 
-        SearchResultEntryCodec searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer ).getSearchResultEntry();
+        InternalSearchResultEntry searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer )
+            .getInternalSearchResultEntry();
 
         assertEquals( 1, searchResultEntry.getMessageId() );
         assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
@@ -946,21 +1015,21 @@ public class SearchResultEntryTest
         }
 
         // Check the Control
-        List<Control> controls = searchResultEntry.getControls();
+        Map<String, Control> controls = searchResultEntry.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = searchResultEntry.getControls( 0 );
+        Control control = controls.get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
         assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
 
-        // Check the length
-        assertEquals( 0x54, searchResultEntry.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = searchResultEntry.encode();
+            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+
+            // Check the length
+            assertEquals( 0x54, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -985,10 +1054,14 @@ public class SearchResultEntryTest
         ByteBuffer stream = ByteBuffer.allocate( 0x39 );
 
         stream.put( new byte[]
-            { 0x30, 0x37, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x32, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            { 0x30,
+                0x37, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x32, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
@@ -1019,7 +1092,8 @@ public class SearchResultEntryTest
             fail( de.getMessage() );
         }
 
-        SearchResultEntryCodec searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer ).getSearchResultEntry();
+        InternalSearchResultEntry searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer )
+            .getInternalSearchResultEntry();
 
         assertEquals( 1, searchResultEntry.getMessageId() );
         assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
@@ -1037,13 +1111,13 @@ public class SearchResultEntryTest
             assertTrue( attribute.contains( "" ) );
         }
 
-        // Check the length
-        assertEquals( 0x39, searchResultEntry.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = searchResultEntry.encode();
+            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+
+            // Check the length
+            assertEquals( 0x39, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -1069,14 +1143,20 @@ public class SearchResultEntryTest
         ByteBuffer stream = ByteBuffer.allocate( 0x56 );
 
         stream.put( new byte[]
-            { 0x30, 0x54, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x64, 0x32, // CHOICE { ..., searchResEntry SearchResultEntry,
-                            // ...
+            {
+                0x30,
+                0x54, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x64,
+                0x32, // CHOICE { ..., searchResEntry SearchResultEntry,
+                // ...
                 // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
                 // objectName LDAPDN,
                 0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't',
-                'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm',
+                'e', 'k', ',', 'd', 'c', '=', 'c', 'o',
+                'm',
                 // attributes PartialAttributeList }
                 // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
                 0x30, 0x13, 0x30, 0x11,
@@ -1085,7 +1165,8 @@ public class SearchResultEntryTest
                 // vals SET OF AttributeValue }
                 0x31, 0x02,
                 // AttributeValue ::= OCTET STRING
-                0x04, 0x00, ( byte ) 0xA0, 0x1B, // A control
+                0x04, 0x00, ( 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 } );
 
@@ -1105,7 +1186,8 @@ public class SearchResultEntryTest
             fail( de.getMessage() );
         }
 
-        SearchResultEntryCodec searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer ).getSearchResultEntry();
+        InternalSearchResultEntry searchResultEntry = ( ( LdapMessageContainer ) ldapMessageContainer )
+            .getInternalSearchResultEntry();
 
         assertEquals( 1, searchResultEntry.getMessageId() );
         assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
@@ -1124,21 +1206,21 @@ public class SearchResultEntryTest
         }
 
         // Check the Control
-        List<Control> controls = searchResultEntry.getControls();
+        Map<String, Control> controls = searchResultEntry.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = searchResultEntry.getControls( 0 );
+        Control control = controls.get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
         assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
 
-        // Check the length
-        assertEquals( 0x56, searchResultEntry.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = searchResultEntry.encode();
+            ByteBuffer bb = encoder.encodeMessage( searchResultEntry );
+
+            // Check the length
+            assertEquals( 0x56, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 



Mime
View raw message