directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r984675 - 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 Thu, 12 Aug 2010 07:59:50 GMT
Author: elecharny
Date: Thu Aug 12 07:59:49 2010
New Revision: 984675

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

Removed:
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareResponseCodec.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/message/CompareResponseImpl.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalCompareResponse.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareResponseTest.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=984675&r1=984674&r2=984675&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
Thu Aug 12 07:59:49 2010
@@ -94,7 +94,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.bind.SaslCredentials;
 import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
 import org.apache.directory.shared.ldap.codec.compare.CompareRequestCodec;
-import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec;
 import org.apache.directory.shared.ldap.codec.controls.ControlImpl;
 import org.apache.directory.shared.ldap.codec.del.DelRequestCodec;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec;
@@ -128,6 +127,7 @@ import org.apache.directory.shared.ldap.
 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;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalLdapResult;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
@@ -1591,6 +1591,41 @@ public class LdapNetworkConnection exten
 
             switch ( response.getType() )
             {
+                case ADD_RESPONSE:
+                    // Transform the response
+                    AddResponse addResponse = convert( ( InternalAddResponse ) response );
+
+                    AddFuture addFuture = ( AddFuture ) responseFuture;
+
+                    if ( addFuture == null )
+                    {
+                        LOG.error( "AddFuture is null" );
+                        throw new LdapException( "AddFuture is null" );
+                    }
+
+                    // remove the listener from the listener map
+                    if ( LOG.isDebugEnabled() )
+                    {
+                        if ( addResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS
)
+                        {
+                            // Everything is fine, return the response
+                            LOG.debug( "Add successful : {}", addResponse );
+                        }
+                        else
+                        {
+                            // We have had an error
+                            LOG.debug( "Add failed : {}", addResponse );
+                        }
+                    }
+
+                    // Store the response into the future
+                    addFuture.set( addResponse );
+
+                    // Remove the future from the map
+                    removeFromFutureMaps( messageId );
+
+                    break;
+
                 case BIND_RESPONSE:
                     // Transform the response
                     BindResponse bindResponse = convert( ( InternalBindResponse ) response
);
@@ -1625,69 +1660,69 @@ public class LdapNetworkConnection exten
 
                     break;
 
-                case DEL_RESPONSE:
+                case COMPARE_RESPONSE:
                     // Transform the response
-                    DeleteResponse deleteResponse = convert( ( InternalDeleteResponse ) response
);
+                    CompareResponse compareResponse = convert( ( InternalCompareResponse
) response );
 
-                    DeleteFuture deleteFuture = ( DeleteFuture ) responseFuture;
+                    CompareFuture compareFuture = ( CompareFuture ) responseFuture;
 
-                    if ( deleteFuture == null )
+                    if ( compareFuture == null )
                     {
-                        LOG.error( "DeleteFuture is null" );
-                        throw new LdapException( "DeleteFuture is null" );
+                        LOG.error( "CompareFuture is null" );
+                        throw new LdapException( "CompareFuture is null" );
                     }
 
+                    // remove the listener from the listener map
                     if ( LOG.isDebugEnabled() )
                     {
-                        if ( deleteResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS
)
+                        if ( compareResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS
)
                         {
                             // Everything is fine, return the response
-                            LOG.debug( "Delete successful : {}", deleteResponse );
+                            LOG.debug( "Compare successful : {}", compareResponse );
                         }
                         else
                         {
                             // We have had an error
-                            LOG.debug( "Delete failed : {}", deleteResponse );
+                            LOG.debug( "Compare failed : {}", compareResponse );
                         }
                     }
 
                     // Store the response into the future
-                    deleteFuture.set( deleteResponse );
+                    compareFuture.set( compareResponse );
 
                     // Remove the future from the map
                     removeFromFutureMaps( messageId );
 
                     break;
 
-                case ADD_RESPONSE:
+                case DEL_RESPONSE:
                     // Transform the response
-                    AddResponse addResponse = convert( ( InternalAddResponse ) response );
+                    DeleteResponse deleteResponse = convert( ( InternalDeleteResponse ) response
);
 
-                    AddFuture addFuture = ( AddFuture ) responseFuture;
+                    DeleteFuture deleteFuture = ( DeleteFuture ) responseFuture;
 
-                    if ( addFuture == null )
+                    if ( deleteFuture == null )
                     {
-                        LOG.error( "AddFuture is null" );
-                        throw new LdapException( "AddFuture is null" );
+                        LOG.error( "DeleteFuture is null" );
+                        throw new LdapException( "DeleteFuture is null" );
                     }
 
-                    // remove the listener from the listener map
                     if ( LOG.isDebugEnabled() )
                     {
-                        if ( addResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS
)
+                        if ( deleteResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS
)
                         {
                             // Everything is fine, return the response
-                            LOG.debug( "Add successful : {}", addResponse );
+                            LOG.debug( "Delete successful : {}", deleteResponse );
                         }
                         else
                         {
                             // We have had an error
-                            LOG.debug( "Add failed : {}", addResponse );
+                            LOG.debug( "Delete failed : {}", deleteResponse );
                         }
                     }
 
                     // Store the response into the future
-                    addFuture.set( addResponse );
+                    deleteFuture.set( deleteResponse );
 
                     // Remove the future from the map
                     removeFromFutureMaps( messageId );
@@ -1714,45 +1749,6 @@ public class LdapNetworkConnection exten
 
             switch ( response.getMessageType() )
             {
-                case COMPARE_RESPONSE:
-                    // Transform the response
-                    CompareResponseCodec compResCodec = ( CompareResponseCodec ) response;
-                    compResCodec.setMessageId( messageId );
-                    compResCodec.addControls( response.getControls() );
-
-                    CompareResponse compareResponse = convert( compResCodec );
-
-                    CompareFuture compareFuture = ( CompareFuture ) responseFuture;
-
-                    if ( compareFuture == null )
-                    {
-                        LOG.error( "CompareFuture is null" );
-                        throw new LdapException( "CompareFuture is null" );
-                    }
-
-                    // remove the listener from the listener map
-                    if ( LOG.isDebugEnabled() )
-                    {
-                        if ( compareResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS
)
-                        {
-                            // Everything is fine, return the response
-                            LOG.debug( "Compare successful : {}", compareResponse );
-                        }
-                        else
-                        {
-                            // We have had an error
-                            LOG.debug( "Compare failed : {}", compareResponse );
-                        }
-                    }
-
-                    // Store the response into the future
-                    compareFuture.set( compareResponse );
-
-                    // Remove the future from the map
-                    removeFromFutureMaps( messageId );
-
-                    break;
-
                 case EXTENDED_RESPONSE:
                     // Transform the response
                     ExtendedResponseCodec extResCodec = ( ExtendedResponseCodec ) response;
@@ -2875,17 +2871,17 @@ public class LdapNetworkConnection exten
 
 
     /**
-     * converts the CompareResponseCodec to CompareResponse.
+     * converts the InternalCompareResponse to CompareResponse object.
      */
-    private CompareResponse convert( CompareResponseCodec compareRespCodec )
+    private CompareResponse convert( InternalCompareResponse internalCompareResponse )
     {
-        CompareResponse compareResponse = new CompareResponse();
+        CompareResponse response = new CompareResponse();
 
-        compareResponse.setMessageId( compareRespCodec.getMessageId() );
-        compareResponse.setLdapResult( convert( compareRespCodec.getLdapResult() ) );
-        addControls( compareRespCodec, compareResponse );
+        response.setMessageId( internalCompareResponse.getMessageId() );
+        response.setLdapResult( convert( internalCompareResponse.getLdapResult() ) );
+        addControls( internalCompareResponse, response );
 
-        return compareResponse;
+        return response;
     }
 
 

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=984675&r1=984674&r2=984675&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
Thu Aug 12 07:59:49 2010
@@ -25,7 +25,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.add.AddRequestCodec;
 import org.apache.directory.shared.ldap.codec.bind.BindRequestCodec;
 import org.apache.directory.shared.ldap.codec.compare.CompareRequestCodec;
-import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec;
 import org.apache.directory.shared.ldap.codec.controls.AbstractControl;
 import org.apache.directory.shared.ldap.codec.del.DelRequestCodec;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec;
@@ -46,6 +45,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalBindResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
@@ -238,9 +238,9 @@ public class LdapMessageContainer extend
     /**
      * @return Returns the CompareResponse stored in the container
      */
-    public CompareResponseCodec getCompareResponse()
+    public InternalCompareResponse getInternalCompareResponse()
     {
-        return ( CompareResponseCodec ) ldapMessage;
+        return ( InternalCompareResponse ) 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=984675&r1=984674&r2=984675&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
Thu Aug 12 07:59:49 2010
@@ -70,7 +70,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.actions.StoreReferenceAction;
 import org.apache.directory.shared.ldap.codec.actions.StoreTypeMatchingRuleAction;
 import org.apache.directory.shared.ldap.codec.actions.ValueAction;
-import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec;
 import org.apache.directory.shared.ldap.codec.controls.ControlEnum;
 import org.apache.directory.shared.ldap.codec.controls.ControlImpl;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec;
@@ -111,6 +110,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalBindResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalLdapResult;
@@ -2713,9 +2713,9 @@ public class LdapMessageGrammar extends 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
container;
 
                     // Now, we can allocate the CompareResponse Object
-                    CompareResponseCodec compareResponse = new CompareResponseCodec();
-                    compareResponse.setMessageId( ldapMessageContainer.getMessageId() );
-                    ldapMessageContainer.setLdapMessage( compareResponse );
+                    InternalCompareResponse compareResponse = new CompareResponseImpl( ldapMessageContainer
+                        .getMessageId() );
+                    ldapMessageContainer.setInternalMessage( compareResponse );
 
                     // We will check that the request is not null
                     TLV tlv = ldapMessageContainer.getCurrentTLV();

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=984675&r1=984674&r2=984675&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
Thu Aug 12 07:59:49 2010
@@ -33,10 +33,12 @@ import org.apache.directory.shared.i18n.
 import org.apache.directory.shared.ldap.codec.controls.CodecControl;
 import org.apache.directory.shared.ldap.message.AddResponseImpl;
 import org.apache.directory.shared.ldap.message.BindResponseImpl;
+import org.apache.directory.shared.ldap.message.CompareResponseImpl;
 import org.apache.directory.shared.ldap.message.DeleteResponseImpl;
 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;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalLdapResult;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
@@ -102,7 +104,7 @@ public class LdapProtocolEncoder extends
         ByteBuffer buffer = ByteBuffer.allocate( length );
 
         if ( ( message instanceof InternalBindResponse ) || ( message instanceof InternalDeleteResponse
)
-            || ( message instanceof InternalAddResponse ) )
+            || ( message instanceof InternalAddResponse ) || ( message instanceof InternalCompareResponse
) )
         {
             try
             {
@@ -427,6 +429,29 @@ public class LdapProtocolEncoder extends
 
 
     /**
+     * Compute the CompareResponse length 
+     * 
+     * CompareResponse :
+     * 
+     * 0x6F L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(CompareResponse) = Length(0x6F) + Length(L1) + L1
+     */
+    private int computeCompareResponseLength( CompareResponseImpl compareResponse )
+    {
+        int compareResponseLength = computeLdapResultLength( compareResponse.getLdapResult()
);
+
+        compareResponse.setCompareResponseLength( compareResponseLength );
+
+        return 1 + TLV.getNbBytes( compareResponseLength ) + compareResponseLength;
+    }
+
+
+    /**
      * Compute the DelResponse length 
      * 
      * DelResponse :
@@ -518,6 +543,30 @@ public class LdapProtocolEncoder extends
 
 
     /**
+     * Encode the CompareResponse message to a PDU.
+     * 
+     * @param buffer The buffer where to put the PDU
+     */
+    private void encodeCompareResponse( ByteBuffer buffer, CompareResponseImpl compareResponse
)
+        throws EncoderException
+    {
+        try
+        {
+            // The CompareResponse Tag
+            buffer.put( LdapConstants.COMPARE_RESPONSE_TAG );
+            buffer.put( TLV.getBytes( compareResponse.getCompareResponseLength() ) );
+
+            // The LdapResult
+            encodeLdapResult( buffer, compareResponse.getLdapResult() );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+        }
+    }
+
+
+    /**
      * Encode the DelResponse message to a PDU.
      * 
      * @param buffer The buffer where to put the PDU
@@ -553,6 +602,9 @@ public class LdapProtocolEncoder extends
             case BIND_RESPONSE:
                 return computeBindResponseLength( ( BindResponseImpl ) message );
 
+            case COMPARE_RESPONSE:
+                return computeCompareResponseLength( ( CompareResponseImpl ) message );
+
             case DEL_RESPONSE:
                 return computeDeleteResponseLength( ( DeleteResponseImpl ) message );
 
@@ -574,6 +626,10 @@ public class LdapProtocolEncoder extends
                 encodeBindResponse( bb, ( BindResponseImpl ) message );
                 break;
 
+            case COMPARE_RESPONSE:
+                encodeCompareResponse( bb, ( CompareResponseImpl ) message );
+                break;
+
             case DEL_RESPONSE:
                 encodeDeleteResponse( bb, ( DeleteResponseImpl ) message );
                 break;

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=984675&r1=984674&r2=984675&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
Thu Aug 12 07:59:49 2010
@@ -30,7 +30,6 @@ import org.apache.directory.shared.i18n.
 import org.apache.directory.shared.ldap.codec.bind.BindRequestCodec;
 import org.apache.directory.shared.ldap.codec.bind.SaslCredentials;
 import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
-import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedResponseCodec;
 import org.apache.directory.shared.ldap.codec.intermediate.IntermediateResponseCodec;
@@ -71,7 +70,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.filter.SubstringNode;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.message.BindRequestImpl;
-import org.apache.directory.shared.ldap.message.CompareResponseImpl;
 import org.apache.directory.shared.ldap.message.ExtendedRequestImpl;
 import org.apache.directory.shared.ldap.message.ExtendedResponseImpl;
 import org.apache.directory.shared.ldap.message.IntermediateResponseImpl;
@@ -708,26 +706,6 @@ public class LdapTransformer
 
 
     /**
-     * Transform a Internal CompareResponse to a Codec CompareResponse
-     * 
-     * @param internalMessage The incoming Internal CompareResponse
-     * @return The CompareResponseCodec instance
-     */
-    private static LdapMessageCodec transformCompareResponse( InternalMessage internalMessage
)
-    {
-        CompareResponseImpl internalCompareResponse = ( CompareResponseImpl ) internalMessage;
-
-        CompareResponseCodec compareResponse = new CompareResponseCodec();
-
-        // Transform the ldapResult
-        compareResponse
-            .setLdapResult( transformLdapResult( ( LdapResultImpl ) internalCompareResponse.getLdapResult()
) );
-
-        return compareResponse;
-    }
-
-
-    /**
      * Transform a Internal ExtendedResponse to a Codec ExtendedResponse
      * 
      * @param internalMessage The incoming Internal ExtendedResponse
@@ -947,10 +925,6 @@ public class LdapTransformer
                 codecMessage = transformBindRequest( msg );
                 break;
 
-            case COMPARE_RESPONSE:
-                codecMessage = transformCompareResponse( msg );
-                break;
-
             case MODIFY_RESPONSE:
                 codecMessage = transformModifyResponse( msg );
                 break;

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareResponseImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareResponseImpl.java?rev=984675&r1=984674&r2=984675&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareResponseImpl.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareResponseImpl.java
Thu Aug 12 07:59:49 2010
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.shared.ldap.message;
 
+
 import org.apache.directory.shared.ldap.message.internal.InternalAbstractResultResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalCompareResponse;
 
@@ -30,6 +31,8 @@ import org.apache.directory.shared.ldap.
  */
 public class CompareResponseImpl extends InternalAbstractResultResponse implements InternalCompareResponse
 {
+    /** The encoded compareResponse length */
+    private int compareResponseLength;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -44,8 +47,27 @@ public class CompareResponseImpl extends
      * @param id
      *            the session unique message id
      */
-    public CompareResponseImpl(final int id)
+    public CompareResponseImpl( final int id )
     {
         super( id, TYPE );
     }
+
+
+    /**
+     * Stores the encoded length for the CompareResponse
+     * @param compareResponseLength The encoded length
+     */
+    public void setCompareResponseLength( int compareResponseLength )
+    {
+        this.compareResponseLength = compareResponseLength;
+    }
+
+
+    /**
+     * @return The encoded CompareResponse's length
+     */
+    public int getCompareResponseLength()
+    {
+        return compareResponseLength;
+    }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalCompareResponse.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalCompareResponse.java?rev=984675&r1=984674&r2=984675&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalCompareResponse.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalCompareResponse.java
Thu Aug 12 07:59:49 2010
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.shared.ldap.message.internal;
 
+
 import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
 
 
@@ -32,4 +33,17 @@ public interface InternalCompareResponse
 {
     /** Compare response message type enumeration value */
     MessageTypeEnum TYPE = MessageTypeEnum.COMPARE_RESPONSE;
+
+
+    /**
+     * Stores the encoded length for the CompareResponse
+     * @param compareResponseLength The encoded length
+     */
+    void setCompareResponseLength( int compareResponseLength );
+
+
+    /**
+     * @return The encoded CompareResponse's length
+     */
+    int getCompareResponseLength();
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareResponseTest.java?rev=984675&r1=984674&r2=984675&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareResponseTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareResponseTest.java
Thu Aug 12 07:59:49 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 org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -34,8 +34,10 @@ 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.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareResponse;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -50,6 +52,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class CompareResponseTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a CompareResponse
      */
@@ -64,7 +70,7 @@ public class CompareResponseTest
             { 0x30, 0x0C, // LDAPMessage ::=SEQUENCE {
                 0x02, 0x01, 0x01, // messageID MessageID
                 0x6F, 0x07, // CHOICE { ..., compareResponse CompareResponse,
-                            // ...
+                // ...
                 // CompareResponse ::= [APPLICATION 15] LDAPResult
                 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
                 // resultCode ENUMERATED {
@@ -94,20 +100,21 @@ public class CompareResponseTest
         }
 
         // Check the decoded CompareResponse PDU
-        CompareResponseCodec compareResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getCompareResponse();
+        InternalCompareResponse compareResponse = ( ( LdapMessageContainer ) ldapMessageContainer
)
+            .getInternalCompareResponse();
 
         assertEquals( 1, compareResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, compareResponse.getLdapResult().getResultCode()
);
-        assertEquals( "", compareResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", compareResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", compareResponse.getLdapResult().getErrorMessage() );
 
-        // Check the length
-        assertEquals( 0x0E, compareResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = compareResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( compareResponse );
+
+            // Check the length
+            assertEquals( 0x0E, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -132,20 +139,29 @@ public class CompareResponseTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2B );
 
         stream.put( new byte[]
-            { 0x30, 0x29, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x6F, 0x07, // CHOICE { ..., compareResponse CompareResponse,
-                            // ...
+            { 0x30,
+                0x29, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x6F,
+                0x07, // CHOICE { ..., compareResponse CompareResponse,
+                // ...
                 // CompareResponse ::= [APPLICATION 15] LDAPResult
-                0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+                0x0A,
+                0x01,
+                0x00, // LDAPResult ::= SEQUENCE {
                 // resultCode ENUMERATED {
                 // success (0), ...
                 // },
-                0x04, 0x00, // matchedDN LDAPDN,
-                0x04, 0x00, // errorMessage LDAPString,
+                0x04,
+                0x00, // matchedDN LDAPDN,
+                0x04,
+                0x00, // errorMessage LDAPString,
                 // referral [3] Referral OPTIONAL }
                 // }
-                ( byte ) 0xA0, 0x1B, // A control
+                ( 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 } );
 
@@ -167,29 +183,30 @@ public class CompareResponseTest
         }
 
         // Check the decoded CompareResponse PDU
-        CompareResponseCodec compareResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getCompareResponse();
+        InternalCompareResponse compareResponse = ( ( LdapMessageContainer ) ldapMessageContainer
)
+            .getInternalCompareResponse();
 
         assertEquals( 1, compareResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, compareResponse.getLdapResult().getResultCode()
);
-        assertEquals( "", compareResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", compareResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", compareResponse.getLdapResult().getErrorMessage() );
 
         // Check the Control
-        List<Control> controls = compareResponse.getControls();
+        Map<String, Control> controls = compareResponse.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = compareResponse.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( 0x2B, compareResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = compareResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( compareResponse );
+
+            // Check the length
+            assertEquals( 0x2B, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -217,7 +234,7 @@ public class CompareResponseTest
             { 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
                 0x02, 0x01, 0x01, // messageID MessageID
                 0x6F, 0x00 // CHOICE { ..., compareResponse CompareResponse,
-                            // ...
+            // ...
             } );
 
         stream.flip();



Mime
View raw message