directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r985857 - in /directory: apacheds/branches/apacheds-codec-merge/core-api/src/main/java/org/apache/directory/server/core/ apacheds/branches/apacheds-codec-merge/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations...
Date Mon, 16 Aug 2010 10:23:14 GMT
Author: elecharny
Date: Mon Aug 16 10:23:13 2010
New Revision: 985857

URL: http://svn.apache.org/viewvc?rev=985857&view=rev
Log:
o Removed unused code
o Merged the CompareRequest classes


Removed:
    directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/CompareRequest.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/
Modified:
    directory/apacheds/branches/apacheds-codec-merge/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
    directory/apacheds/branches/apacheds-codec-merge/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientCompareRequestTest.java
    directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapAsyncConnection.java
    directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
    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/actions/ValueAction.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapProtocolEncoder.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java

Modified: directory/apacheds/branches/apacheds-codec-merge/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-codec-merge/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java?rev=985857&r1=985856&r2=985857&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-codec-merge/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java (original)
+++ directory/apacheds/branches/apacheds-codec-merge/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java Mon Aug 16 10:23:13 2010
@@ -28,7 +28,6 @@ import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.message.CompareRequest;
 import org.apache.directory.ldap.client.api.message.ExtendedRequest;
 import org.apache.directory.ldap.client.api.message.ModifyDnRequest;
 import org.apache.directory.ldap.client.api.message.ModifyRequest;
@@ -57,7 +56,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.CompareResponseImpl;
 import org.apache.directory.shared.ldap.message.DeleteRequestImpl;
 import org.apache.directory.shared.ldap.message.DeleteResponseImpl;
-import org.apache.directory.shared.ldap.message.LdapResultImpl;
 import org.apache.directory.shared.ldap.message.ModifyDnRequestImpl;
 import org.apache.directory.shared.ldap.message.ModifyDnResponseImpl;
 import org.apache.directory.shared.ldap.message.ModifyRequestImpl;
@@ -164,22 +162,6 @@ public class LdapCoreSessionConnection i
     }
 
 
-    private LdapResult getDefaultResult()
-    {
-        LdapResult result = new LdapResultImpl();
-        result.setResultCode( ResultCodeEnum.SUCCESS );
-        return result;
-    }
-
-
-    private LdapResult getDefaultCompareResult()
-    {
-        LdapResult result = new LdapResultImpl();
-        result.setResultCode( ResultCodeEnum.COMPARE_TRUE );
-        return result;
-    }
-
-
     /**
      * {@inheritDoc}
      */
@@ -224,41 +206,14 @@ public class LdapCoreSessionConnection i
     /**
      * {@inheritDoc}
      */
-    public CompareResponse compare( CompareRequest compareRequest ) throws LdapException
+    public CompareResponse compare( InternalCompareRequest compareRequest ) throws LdapException
     {
         int newId = messageId.incrementAndGet();
 
         CompareResponse resp = new CompareResponseImpl( newId );
         resp.getLdapResult().setResultCode( ResultCodeEnum.COMPARE_TRUE );
 
-        InternalCompareRequest icompare = new CompareRequestImpl( newId );
-
-        try
-        {
-            Object obj = compareRequest.getValue();
-            if ( obj instanceof byte[] )
-            {
-                icompare.setAssertionValue( ( byte[] ) obj );
-            }
-            else
-            {
-                icompare.setAssertionValue( ( String ) obj );
-            }
-
-            icompare.setAttributeId( compareRequest.getAttrName() );
-            icompare.setName( compareRequest.getEntryDn() );
-
-            session.compare( icompare );
-        }
-        catch ( LdapException e )
-        {
-            LOG.warn( e.getMessage(), e );
-
-            resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
-            resp.getLdapResult().setErrorMessage( e.getMessage() );
-        }
-
-        addResponseControls( icompare, resp );
+        addResponseControls( compareRequest, resp );
         return resp;
     }
 
@@ -268,10 +223,10 @@ public class LdapCoreSessionConnection i
      */
     public CompareResponse compare( DN dn, String attributeName, byte[] value ) throws LdapException
     {
-        CompareRequest compareRequest = new CompareRequest();
-        compareRequest.setEntryDn( dn );
-        compareRequest.setAttrName( attributeName );
-        compareRequest.setValue( value );
+        InternalCompareRequest compareRequest = new CompareRequestImpl();
+        compareRequest.setName( dn );
+        compareRequest.setAttributeId( attributeName );
+        compareRequest.setAssertionValue( value );
 
         return compare( compareRequest );
     }
@@ -282,10 +237,10 @@ public class LdapCoreSessionConnection i
      */
     public CompareResponse compare( DN dn, String attributeName, String value ) throws LdapException
     {
-        CompareRequest compareRequest = new CompareRequest();
-        compareRequest.setEntryDn( dn );
-        compareRequest.setAttrName( attributeName );
-        compareRequest.setValue( value );
+        InternalCompareRequest compareRequest = new CompareRequestImpl();
+        compareRequest.setName( dn );
+        compareRequest.setAttributeId( attributeName );
+        compareRequest.setAssertionValue( value );
 
         return compare( compareRequest );
     }
@@ -314,10 +269,18 @@ public class LdapCoreSessionConnection i
      */
     public CompareResponse compare( DN dn, String attributeName, Value<?> value ) throws LdapException
     {
-        CompareRequest compareRequest = new CompareRequest();
-        compareRequest.setEntryDn( dn );
-        compareRequest.setAttrName( attributeName );
-        compareRequest.setValue( value.get() );
+        InternalCompareRequest compareRequest = new CompareRequestImpl();
+        compareRequest.setName( dn );
+        compareRequest.setAttributeId( attributeName );
+
+        if ( value.isBinary() )
+        {
+            compareRequest.setAssertionValue( value.getBytes() );
+        }
+        else
+        {
+            compareRequest.setAssertionValue( value.getString() );
+        }
 
         return compare( compareRequest );
     }

Modified: directory/apacheds/branches/apacheds-codec-merge/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientCompareRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-codec-merge/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientCompareRequestTest.java?rev=985857&r1=985856&r2=985857&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-codec-merge/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientCompareRequestTest.java (original)
+++ directory/apacheds/branches/apacheds-codec-merge/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientCompareRequestTest.java Mon Aug 16 10:23:13 2010
@@ -31,15 +31,16 @@ import java.util.concurrent.TimeoutExcep
 import org.apache.directory.ldap.client.api.LdapAsyncConnection;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.ldap.client.api.future.CompareFuture;
-import org.apache.directory.ldap.client.api.message.CompareRequest;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.message.CompareRequestImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.internal.CompareResponse;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
 import org.apache.directory.shared.ldap.name.DN;
 import org.junit.After;
 import org.junit.Before;
@@ -113,10 +114,10 @@ public class ClientCompareRequestTest ex
     {
         DN dn = new DN( "uid=admin,ou=system" );
 
-        CompareRequest compareRequest = new CompareRequest();
-        compareRequest.setEntryDn( dn );
-        compareRequest.setAttrName( SchemaConstants.UID_AT );
-        compareRequest.setValue( "admin" );
+        InternalCompareRequest compareRequest = new CompareRequestImpl();
+        compareRequest.setName( dn );
+        compareRequest.setAttributeId( SchemaConstants.UID_AT );
+        compareRequest.setAssertionValue( "admin" );
 
         connection.compare( compareRequest );
 

Modified: directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapAsyncConnection.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/LdapAsyncConnection.java?rev=985857&r1=985856&r2=985857&view=diff
==============================================================================
--- directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapAsyncConnection.java (original)
+++ directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapAsyncConnection.java Mon Aug 16 10:23:13 2010
@@ -11,7 +11,6 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.ldap.client.api.future.ModifyDnFuture;
 import org.apache.directory.ldap.client.api.future.ModifyFuture;
 import org.apache.directory.ldap.client.api.future.SearchFuture;
-import org.apache.directory.ldap.client.api.message.CompareRequest;
 import org.apache.directory.ldap.client.api.message.ExtendedRequest;
 import org.apache.directory.ldap.client.api.message.ModifyDnRequest;
 import org.apache.directory.ldap.client.api.message.ModifyRequest;
@@ -21,6 +20,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.message.internal.InternalAddRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
 import org.apache.directory.shared.ldap.name.DN;
 
@@ -165,7 +165,7 @@ public interface LdapAsyncConnection ext
      * @return compare operation's future
      * @throws LdapException
      */
-    CompareFuture compareAsync( CompareRequest compareRequest ) throws LdapException;
+    CompareFuture compareAsync( InternalCompareRequest compareRequest ) throws LdapException;
 
 
     /**

Modified: directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.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/LdapConnection.java?rev=985857&r1=985856&r2=985857&view=diff
==============================================================================
--- directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java (original)
+++ directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Mon Aug 16 10:23:13 2010
@@ -4,7 +4,6 @@ package org.apache.directory.ldap.client
 import java.io.IOException;
 import java.util.List;
 
-import org.apache.directory.ldap.client.api.message.CompareRequest;
 import org.apache.directory.ldap.client.api.message.ExtendedRequest;
 import org.apache.directory.ldap.client.api.message.ModifyDnRequest;
 import org.apache.directory.ldap.client.api.message.ModifyRequest;
@@ -25,6 +24,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalAddRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
 import org.apache.directory.shared.ldap.message.internal.ModifyDnResponse;
 import org.apache.directory.shared.ldap.message.internal.ModifyResponse;
@@ -486,7 +486,7 @@ public interface LdapConnection
      * @return compare operation's response
      * @throws LdapException
      */
-    public abstract CompareResponse compare( CompareRequest compareRequest ) throws LdapException;
+    public abstract CompareResponse compare( InternalCompareRequest compareRequest ) throws LdapException;
 
 
     /**

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=985857&r1=985856&r2=985857&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 Mon Aug 16 10:23:13 2010
@@ -51,7 +51,6 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.ldap.client.api.future.ResponseFuture;
 import org.apache.directory.ldap.client.api.future.SearchFuture;
 import org.apache.directory.ldap.client.api.listener.DeleteListener;
-import org.apache.directory.ldap.client.api.message.CompareRequest;
 import org.apache.directory.ldap.client.api.message.ExtendedRequest;
 import org.apache.directory.ldap.client.api.message.ModifyDnRequest;
 import org.apache.directory.ldap.client.api.message.ModifyRequest;
@@ -64,7 +63,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.LdapTransformer;
 import org.apache.directory.shared.ldap.codec.MessageEncoderException;
-import org.apache.directory.shared.ldap.codec.compare.CompareRequestCodec;
 import org.apache.directory.shared.ldap.codec.controls.ControlImpl;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec;
 import org.apache.directory.shared.ldap.codec.modify.ModifyRequestCodec;
@@ -88,6 +86,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.AddRequestImpl;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.message.BindRequestImpl;
+import org.apache.directory.shared.ldap.message.CompareRequestImpl;
 import org.apache.directory.shared.ldap.message.DeleteRequestImpl;
 import org.apache.directory.shared.ldap.message.IntermediateResponseImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
@@ -101,6 +100,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalAddRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalIntermediateResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
@@ -318,26 +318,6 @@ public class LdapNetworkConnection exten
 
 
     /**
-     * Inject the client Controls into the message
-     */
-    private void setControls( Map<String, Control> controls, InternalMessage message )
-    {
-        // Add the controls
-        if ( controls != null )
-        {
-            for ( Control control : controls.values() )
-            {
-                ControlImpl ctrl = new ControlImpl( control.getOid() );
-
-                ctrl.setValue( control.getValue() );
-
-                message.addControl( ctrl );
-            }
-        }
-    }
-
-
-    /**
      * Get the smallest timeout from the client timeout and the connection
      * timeout.
      */
@@ -747,12 +727,6 @@ public class LdapNetworkConnection exten
      */
     private void abandonInternal( InternalAbandonRequest abandonRequest )
     {
-        // Todo : The Abandon messageID is always 0
-        int newId = messageId.incrementAndGet();
-
-        // Inject the controls
-        setControls( abandonRequest.getControls(), abandonRequest );
-
         LOG.debug( "-----------------------------------------------------------------" );
         LOG.debug( "Sending request \n{}", abandonRequest );
 
@@ -2505,10 +2479,10 @@ public class LdapNetworkConnection exten
      */
     public CompareResponse compare( DN dn, String attributeName, String value ) throws LdapException
     {
-        CompareRequest compareRequest = new CompareRequest();
-        compareRequest.setEntryDn( dn );
-        compareRequest.setAttrName( attributeName );
-        compareRequest.setValue( value );
+        InternalCompareRequest compareRequest = new CompareRequestImpl();
+        compareRequest.setName( dn );
+        compareRequest.setAttributeId( attributeName );
+        compareRequest.setAssertionValue( value );
 
         return compare( compareRequest );
     }
@@ -2519,10 +2493,10 @@ public class LdapNetworkConnection exten
      */
     public CompareResponse compare( DN dn, String attributeName, byte[] value ) throws LdapException
     {
-        CompareRequest compareRequest = new CompareRequest();
-        compareRequest.setEntryDn( dn );
-        compareRequest.setAttrName( attributeName );
-        compareRequest.setValue( value );
+        InternalCompareRequest compareRequest = new CompareRequestImpl();
+        compareRequest.setName( dn );
+        compareRequest.setAttributeId( attributeName );
+        compareRequest.setAssertionValue( value );
 
         return compare( compareRequest );
     }
@@ -2533,10 +2507,18 @@ public class LdapNetworkConnection exten
      */
     public CompareResponse compare( DN dn, String attributeName, Value<?> value ) throws LdapException
     {
-        CompareRequest compareRequest = new CompareRequest();
-        compareRequest.setEntryDn( dn );
-        compareRequest.setAttrName( attributeName );
-        compareRequest.setValue( value.get() );
+        InternalCompareRequest compareRequest = new CompareRequestImpl();
+        compareRequest.setName( dn );
+        compareRequest.setAttributeId( attributeName );
+
+        if ( value.isBinary() )
+        {
+            compareRequest.setAssertionValue( value.getBytes() );
+        }
+        else
+        {
+            compareRequest.setAssertionValue( value.getString() );
+        }
 
         return compare( compareRequest );
     }
@@ -2545,7 +2527,7 @@ public class LdapNetworkConnection exten
     /**
      * {@inheritDoc}
      */
-    public CompareResponse compare( CompareRequest compareRequest ) throws LdapException
+    public CompareResponse compare( InternalCompareRequest compareRequest ) throws LdapException
     {
         CompareFuture compareFuture = compareAsync( compareRequest );
 
@@ -2553,10 +2535,8 @@ public class LdapNetworkConnection exten
         try
         {
             // Read the response, waiting for it if not available immediately
-            long timeout = getTimeout( compareRequest.getTimeout() );
-
             // Get the response, blocking
-            CompareResponse compareResponse = compareFuture.get( timeout, TimeUnit.MILLISECONDS );
+            CompareResponse compareResponse = compareFuture.get( timeOut, TimeUnit.MILLISECONDS );
 
             if ( compareResponse == null )
             {
@@ -2611,27 +2591,19 @@ public class LdapNetworkConnection exten
     /**
      * {@inheritDoc}
      */
-    public CompareFuture compareAsync( CompareRequest compareRequest ) throws LdapException
+    public CompareFuture compareAsync( InternalCompareRequest compareRequest ) throws LdapException
     {
         checkSession();
 
-        CompareRequestCodec compareReqCodec = new CompareRequestCodec();
-
         int newId = messageId.incrementAndGet();
 
         compareRequest.setMessageId( newId );
-        compareReqCodec.setMessageId( newId );
-
-        compareReqCodec.setEntry( compareRequest.getEntryDn() );
-        compareReqCodec.setAttributeDesc( compareRequest.getAttrName() );
-        compareReqCodec.setAssertionValue( compareRequest.getValue() );
-        setControls( compareRequest.getControls(), compareReqCodec );
 
         CompareFuture compareFuture = new CompareFuture( this, newId );
         addToFutureMap( newId, compareFuture );
 
         // Send the request to the server
-        WriteFuture writeFuture = ldapSession.write( compareReqCodec );
+        WriteFuture writeFuture = ldapSession.write( compareRequest );
 
         // Wait for the message to be sent to the server
         if ( !writeFuture.awaitUninterruptibly( getTimeout( 0 ) ) )

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=985857&r1=985856&r2=985857&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 Mon Aug 16 10:23:13 2010
@@ -21,7 +21,6 @@ package org.apache.directory.shared.ldap
 
 
 import org.apache.directory.shared.asn1.ber.AbstractContainer;
-import org.apache.directory.shared.ldap.codec.compare.CompareRequestCodec;
 import org.apache.directory.shared.ldap.codec.controls.AbstractControl;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec;
 import org.apache.directory.shared.ldap.codec.modify.ModifyRequestCodec;
@@ -150,9 +149,9 @@ public class LdapMessageContainer extend
 
 
     /**
-     * @return Returns the InternalAddRequest stored in the container
+     * @return Returns the AddRequest stored in the container
      */
-    public InternalAddRequest getInternalAddRequest()
+    public InternalAddRequest getAddRequest()
     {
         return ( InternalAddRequest ) internalMessage;
     }
@@ -188,16 +187,7 @@ public class LdapMessageContainer extend
     /**
      * @return Returns the CompareRequest stored in the container
      */
-    public CompareRequestCodec getCompareRequest()
-    {
-        return ( CompareRequestCodec ) ldapMessage;
-    }
-
-
-    /**
-     * @return Returns the CompareRequest stored in the container
-     */
-    public InternalCompareRequest getInternalCompareRequest()
+    public InternalCompareRequest getCompareRequest()
     {
         return ( InternalCompareRequest ) 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=985857&r1=985856&r2=985857&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 Mon Aug 16 10:23:13 2010
@@ -1880,7 +1880,7 @@ public class LdapMessageGrammar extends 
                 {
 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
-                    InternalAddRequest addRequest = ldapMessageContainer.getInternalAddRequest();
+                    InternalAddRequest addRequest = ldapMessageContainer.getAddRequest();
 
                     TLV tlv = ldapMessageContainer.getCurrentTLV();
 
@@ -1965,7 +1965,7 @@ public class LdapMessageGrammar extends 
                 {
 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
-                    InternalAddRequest addRequest = ldapMessageContainer.getInternalAddRequest();
+                    InternalAddRequest addRequest = ldapMessageContainer.getAddRequest();
 
                     TLV tlv = ldapMessageContainer.getCurrentTLV();
 
@@ -2534,7 +2534,7 @@ public class LdapMessageGrammar extends 
                 {
 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
-                    InternalCompareRequest compareRequest = ldapMessageContainer.getInternalCompareRequest();
+                    InternalCompareRequest compareRequest = ldapMessageContainer.getCompareRequest();
 
                     // Get the Value and store it in the CompareRequest
                     TLV tlv = ldapMessageContainer.getCurrentTLV();
@@ -2610,7 +2610,7 @@ public class LdapMessageGrammar extends 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
 
                     // Get the CompareRequest Object
-                    InternalCompareRequest compareRequest = ldapMessageContainer.getInternalCompareRequest();
+                    InternalCompareRequest compareRequest = ldapMessageContainer.getCompareRequest();
 
                     // Get the Value and store it in the CompareRequest
                     TLV tlv = ldapMessageContainer.getCurrentTLV();
@@ -2657,7 +2657,7 @@ public class LdapMessageGrammar extends 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
 
                     // Get the CompareRequest Object
-                    InternalCompareRequest compareRequest = ldapMessageContainer.getInternalCompareRequest();
+                    InternalCompareRequest compareRequest = ldapMessageContainer.getCompareRequest();
 
                     // Get the Value and store it in the CompareRequest
                     TLV tlv = ldapMessageContainer.getCurrentTLV();
@@ -3220,8 +3220,7 @@ public class LdapMessageGrammar extends 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
 
                     // We can get the IntermediateResponse Object
-                    InternalIntermediateResponse intermediateResponse = ldapMessageContainer
-                        .getIntermediateResponse();
+                    InternalIntermediateResponse intermediateResponse = ldapMessageContainer.getIntermediateResponse();
 
                     // Get the Value and store it in the IntermediateResponse
                     TLV tlv = ldapMessageContainer.getCurrentTLV();
@@ -3285,8 +3284,7 @@ public class LdapMessageGrammar extends 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
 
                     // We can get the IntermediateResponse Object
-                    InternalIntermediateResponse intermediateResponse = ldapMessageContainer
-                        .getIntermediateResponse();
+                    InternalIntermediateResponse intermediateResponse = ldapMessageContainer.getIntermediateResponse();
 
                     // Get the Value and store it in the IntermediateResponse
                     TLV tlv = ldapMessageContainer.getCurrentTLV();
@@ -3329,8 +3327,7 @@ public class LdapMessageGrammar extends 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
 
                     // We can allocate the ExtendedRequest Object
-                    InternalIntermediateResponse intermediateResponse = ldapMessageContainer
-                        .getIntermediateResponse();
+                    InternalIntermediateResponse intermediateResponse = ldapMessageContainer.getIntermediateResponse();
 
                     // Get the Value and store it in the IntermediateResponse
                     TLV tlv = ldapMessageContainer.getCurrentTLV();

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ValueAction.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ValueAction.java?rev=985857&r1=985856&r2=985857&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ValueAction.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ValueAction.java Mon Aug 16 10:23:13 2010
@@ -57,7 +57,7 @@ public class ValueAction extends Grammar
     {
 
         LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
-        InternalAddRequest addRequest = ldapMessageContainer.getInternalAddRequest();
+        InternalAddRequest addRequest = ldapMessageContainer.getAddRequest();
 
         TLV tlv = ldapMessageContainer.getCurrentTLV();
 

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java?rev=985857&r1=985856&r2=985857&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java Mon Aug 16 10:23:13 2010
@@ -24,8 +24,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.BinaryValue;
 import org.apache.directory.shared.ldap.entry.StringValue;
 import org.apache.directory.shared.ldap.entry.Value;
-import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
 import org.apache.directory.shared.ldap.message.internal.CompareResponse;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
 import org.apache.directory.shared.ldap.message.internal.ResultResponse;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -46,22 +46,45 @@ public class CompareRequestImpl extends 
     /** The id of the attribute used in the comparison */
     private String attrId;
 
+    /** The bytes of the attribute id used in the comparison */
+    private byte[] attrIdBytes;
+
     /** The value of the attribute used in the comparison */
     private Value<?> attrVal;
 
+    /** The bytes of the attribute value used in the comparison */
+    private byte[] attrValBytes;
+
+    /** The associated response */
     private CompareResponse response;
 
+    /** The compare request length */
+    private int compareRequestLength;
+
+    /** The attribute value assertion length */
+    private int avaLength;
+
 
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
+    /**
+     * Creates an CompareRequest implementation to compare a named entry with an
+     * attribute value assertion pair.
+     * 
+     * @param id the sequence identifier of the CompareRequest message.
+     */
+    public CompareRequestImpl()
+    {
+        super( -1, TYPE );
+    }
+
 
     /**
      * Creates an CompareRequest implementation to compare a named entry with an
      * attribute value assertion pair.
      * 
-     * @param id
-     *            the sequence identifier of the CompareRequest message.
+     * @param id the sequence identifier of the CompareRequest message.
      */
     public CompareRequestImpl( final int id )
     {
@@ -89,8 +112,7 @@ public class CompareRequestImpl extends 
      * Sets the distinguished name of the entry to be compared using the
      * attribute value assertion.
      * 
-     * @param name
-     *            the DN of the compared entry.
+     * @param name the DN of the compared entry.
      */
     public void setName( DN name )
     {
@@ -112,8 +134,7 @@ public class CompareRequestImpl extends 
     /**
      * Sets the attribute value to use in the comparison.
      * 
-     * @param attrVal
-     *            the attribute value used in comparison.
+     * @param attrVal the attribute value used in comparison.
      */
     public void setAssertionValue( String attrVal )
     {
@@ -124,8 +145,7 @@ public class CompareRequestImpl extends 
     /**
      * Sets the attribute value to use in the comparison.
      * 
-     * @param attrVal
-     *            the attribute value used in comparison.
+     * @param attrVal the attribute value used in comparison.
      */
     public void setAssertionValue( byte[] attrVal )
     {
@@ -154,8 +174,7 @@ public class CompareRequestImpl extends 
     /**
      * Sets the attribute id used in the comparison.
      * 
-     * @param attrId
-     *            the attribute id used in comparison.
+     * @param attrId the attribute id used in comparison.
      */
     public void setAttributeId( String attrId )
     {
@@ -163,6 +182,50 @@ public class CompareRequestImpl extends 
     }
 
 
+    /**
+     * Gets the attribute id bytes use in making the comparison.
+     * 
+     * @return the attribute id bytes used in comparison.
+     */
+    /*No qualifier*/byte[] getAttrIdBytes()
+    {
+        return attrIdBytes;
+    }
+
+
+    /**
+     * Sets the attribute id bytes used in the comparison.
+     * 
+     * @param attrIdBytes the attribute id bytes used in comparison.
+     */
+    /*No qualifier*/void setAttrIdBytes( byte[] attrIdBytes )
+    {
+        this.attrIdBytes = attrIdBytes;
+    }
+
+
+    /**
+     * Gets the attribute value bytes use in making the comparison.
+     * 
+     * @return the attribute value bytes used in comparison.
+     */
+    /*No qualifier*/byte[] getAttrValBytes()
+    {
+        return attrValBytes;
+    }
+
+
+    /**
+     * Sets the attribute value bytes used in the comparison.
+     * 
+     * @param attrValBytes the attribute value bytes used in comparison.
+     */
+    /*No qualifier*/void setAttrValBytes( byte[] attrValBytes )
+    {
+        this.attrValBytes = attrValBytes;
+    }
+
+
     // ------------------------------------------------------------------------
     // SingleReplyRequest Interface Method Implementations
     // ------------------------------------------------------------------------
@@ -196,6 +259,44 @@ public class CompareRequestImpl extends 
 
 
     /**
+     * Stores the encoded length for the CompareRequest
+     * @param compareRequestLength The encoded length
+     */
+    /* No qualifier*/void setCompareRequestLength( int compareRequestLength )
+    {
+        this.compareRequestLength = compareRequestLength;
+    }
+
+
+    /**
+     * @return The encoded CompareRequest length
+     */
+    /* No qualifier */int getCompareRequestLength()
+    {
+        return compareRequestLength;
+    }
+
+
+    /**
+     * Stores the encoded length for the ava
+     * @param avaLength The encoded length
+     */
+    /* No qualifier*/void setAvaLength( int avaLength )
+    {
+        this.avaLength = avaLength;
+    }
+
+
+    /**
+     * @return The encoded ava length
+     */
+    /* No qualifier */int getAvaLength()
+    {
+        return avaLength;
+    }
+
+
+    /**
      * {@inheritDoc}
      */
     @Override
@@ -323,6 +424,9 @@ public class CompareRequestImpl extends 
                 .append( "'\n" );
         }
 
+        // The controls
+        sb.append( super.toString() );
+
         return sb.toString();
     }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapProtocolEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapProtocolEncoder.java?rev=985857&r1=985856&r2=985857&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapProtocolEncoder.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapProtocolEncoder.java Mon Aug 16 10:23:13 2010
@@ -38,6 +38,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.LdapTransformer;
 import org.apache.directory.shared.ldap.codec.MessageEncoderException;
 import org.apache.directory.shared.ldap.codec.controls.CodecControl;
+import org.apache.directory.shared.ldap.entry.BinaryValue;
 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;
@@ -49,6 +50,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalAddRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalIntermediateResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
@@ -128,7 +130,8 @@ public class LdapProtocolEncoder extends
             || ( message instanceof SearchResultDone ) || ( message instanceof SearchResultEntry )
             || ( message instanceof SearchResultReference ) || ( message instanceof InternalAbandonRequest )
             || ( message instanceof InternalDeleteRequest ) || ( message instanceof InternalUnbindRequest )
-            || ( message instanceof InternalBindRequest ) || ( message instanceof InternalAddRequest ) )
+            || ( message instanceof InternalBindRequest ) || ( message instanceof InternalAddRequest )
+            || ( message instanceof InternalCompareRequest ) )
         {
             try
             {
@@ -638,6 +641,59 @@ public class LdapProtocolEncoder extends
 
 
     /**
+     * Compute the CompareRequest length 
+     * 
+     * CompareRequest : 
+     * 0x6E L1 
+     *   | 
+     *   +--> 0x04 L2 entry 
+     *   +--> 0x30 L3 (ava) 
+     *         | 
+     *         +--> 0x04 L4 attributeDesc 
+     *         +--> 0x04 L5 assertionValue 
+     *         
+     * L3 = Length(0x04) + Length(L4) + L4 + Length(0x04) +
+     *      Length(L5) + L5 
+     * Length(CompareRequest) = Length(0x6E) + Length(L1) + L1 +
+     *      Length(0x04) + Length(L2) + L2 + Length(0x30) + Length(L3) + L3
+     * 
+     * @return The CompareRequest PDU's length
+     */
+    private int computeCompareRequestLength( CompareRequestImpl compareRequest )
+    {
+        // The entry DN
+        DN entry = compareRequest.getName();
+        int compareRequestLength = 1 + TLV.getNbBytes( DN.getNbBytes( entry ) ) + DN.getNbBytes( entry );
+
+        // The attribute value assertion
+        byte[] attributeIdBytes = StringTools.getBytesUtf8( compareRequest.getAttributeId() );
+        int avaLength = 1 + TLV.getNbBytes( attributeIdBytes.length ) + attributeIdBytes.length;
+        compareRequest.setAttrIdBytes( attributeIdBytes );
+
+        if ( compareRequest.getAssertionValue() instanceof BinaryValue )
+        {
+            byte[] value = compareRequest.getAssertionValue().getBytes();
+            avaLength += 1 + TLV.getNbBytes( value.length ) + value.length;
+            compareRequest.setAttrValBytes( value );
+        }
+        else
+        {
+            byte[] value = StringTools.getBytesUtf8( compareRequest.getAssertionValue().getString() );
+            int assertionValueLength = value.length;
+            avaLength += 1 + TLV.getNbBytes( value.length ) + value.length;
+            compareRequest.setAttrValBytes( value );
+        }
+
+        compareRequest.setAvaLength( avaLength );
+        compareRequestLength += 1 + TLV.getNbBytes( avaLength ) + avaLength;
+        compareRequest.setCompareRequestLength( compareRequestLength );
+
+        return 1 + TLV.getNbBytes( compareRequestLength ) + compareRequestLength;
+
+    }
+
+
+    /**
      * Compute the CompareResponse length 
      * 
      * CompareResponse :
@@ -1352,6 +1408,46 @@ public class LdapProtocolEncoder extends
 
 
     /**
+     * Encode the CompareRequest message to a PDU. 
+     * 
+     * CompareRequest : 
+     *   0x6E LL 
+     *     0x04 LL entry 
+     *     0x30 LL attributeValueAssertion 
+     *       0x04 LL attributeDesc 
+     *       0x04 LL assertionValue
+     * 
+     * @param buffer The buffer where to put the PDU
+     */
+    private void encodeCompareRequest( ByteBuffer buffer, CompareRequestImpl compareRequest ) throws EncoderException
+    {
+        try
+        {
+            // The CompareRequest Tag
+            buffer.put( LdapConstants.COMPARE_REQUEST_TAG );
+            buffer.put( TLV.getBytes( compareRequest.getCompareRequestLength() ) );
+
+            // The entry
+            Value.encode( buffer, DN.getBytes( compareRequest.getName() ) );
+
+            // The attributeValueAssertion sequence Tag
+            buffer.put( UniversalTag.SEQUENCE_TAG );
+            buffer.put( TLV.getBytes( compareRequest.getAvaLength() ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+        }
+
+        // The attributeDesc
+        Value.encode( buffer, compareRequest.getAttrIdBytes() );
+
+        // The assertionValue
+        Value.encode( buffer, ( byte[] ) compareRequest.getAttrValBytes() );
+    }
+
+
+    /**
      * Encode the CompareResponse message to a PDU.
      * 
      * @param buffer The buffer where to put the PDU
@@ -1778,6 +1874,9 @@ public class LdapProtocolEncoder extends
             case BIND_RESPONSE:
                 return computeBindResponseLength( ( BindResponseImpl ) message );
 
+            case COMPARE_REQUEST:
+                return computeCompareRequestLength( ( CompareRequestImpl ) message );
+
             case COMPARE_RESPONSE:
                 return computeCompareResponseLength( ( CompareResponseImpl ) message );
 
@@ -1841,6 +1940,10 @@ public class LdapProtocolEncoder extends
                 encodeBindResponse( bb, ( BindResponseImpl ) message );
                 break;
 
+            case COMPARE_REQUEST:
+                encodeCompareRequest( bb, ( CompareRequestImpl ) message );
+                break;
+
             case COMPARE_RESPONSE:
                 encodeCompareResponse( bb, ( CompareResponseImpl ) message );
                 break;

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java?rev=985857&r1=985856&r2=985857&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java Mon Aug 16 10:23:13 2010
@@ -131,7 +131,7 @@ public class AddRequestTest
             fail( de.getMessage() );
         }
 
-        InternalAddRequest addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getInternalAddRequest();
+        InternalAddRequest addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddRequest();
 
         // Check the decoded message
         assertEquals( 1, addRequest.getMessageId() );
@@ -204,7 +204,7 @@ public class AddRequestTest
                 fail( de.getMessage() );
             }
 
-            InternalAddRequest addRequest2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getInternalAddRequest();
+            InternalAddRequest addRequest2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddRequest();
             assertEquals( addRequest, addRequest2 );
         }
         catch ( EncoderException ee )
@@ -670,7 +670,7 @@ public class AddRequestTest
             fail( de.getMessage() );
         }
 
-        InternalAddRequest addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getInternalAddRequest();
+        InternalAddRequest addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddRequest();
 
         // Check the decoded message
         assertEquals( 1, addRequest.getMessageId() );
@@ -762,7 +762,7 @@ public class AddRequestTest
             fail( de.getMessage() );
         }
 
-        InternalAddRequest addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getInternalAddRequest();
+        InternalAddRequest addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddRequest();
 
         // Check the decoded message
         assertEquals( 1, addRequest.getMessageId() );

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java?rev=985857&r1=985856&r2=985857&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java Mon Aug 16 10:23:13 2010
@@ -36,6 +36,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
 import org.apache.directory.shared.ldap.message.CompareResponseImpl;
+import org.apache.directory.shared.ldap.message.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.InternalCompareRequest;
@@ -54,6 +55,9 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class CompareRequestTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
 
     /**
      * Test the decoding of a full CompareRequest
@@ -101,27 +105,20 @@ public class CompareRequestTest
         }
 
         // Ceck the decoded CompareRequest PDU
-        InternalCompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
-            .getInternalCompareRequest();
+        InternalCompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
 
         assertEquals( 1, compareRequest.getMessageId() );
         assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getName().toString() );
         assertEquals( "test", compareRequest.getAttributeId() );
         assertEquals( "value", compareRequest.getAssertionValue().toString() );
 
-        // Check the length
-        CompareRequestCodec compareRequestCodec = new CompareRequestCodec();
-        compareRequestCodec.setMessageId( compareRequest.getMessageId() );
-        compareRequestCodec.setEntry( compareRequest.getName() );
-        compareRequestCodec.setAttributeDesc( compareRequest.getAttributeId() );
-        compareRequestCodec.setAssertionValue( compareRequest.getAssertionValue().get() );
-
-        assertEquals( 0x38, compareRequestCodec.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = compareRequestCodec.encode();
+            ByteBuffer bb = encoder.encodeMessage( compareRequest );
+
+            // Check the length
+            assertEquals( 0x38, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -396,27 +393,20 @@ public class CompareRequestTest
         }
 
         // Check the decoded CompareRequest PDU
-        InternalCompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
-            .getInternalCompareRequest();
+        InternalCompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
 
         assertEquals( 1, compareRequest.getMessageId() );
         assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getName().toString() );
         assertEquals( "test", compareRequest.getAttributeId() );
         assertEquals( "", compareRequest.getAssertionValue().toString() );
 
-        // Check the length
-        CompareRequestCodec compareRequestCodec = new CompareRequestCodec();
-        compareRequestCodec.setMessageId( compareRequest.getMessageId() );
-        compareRequestCodec.setEntry( compareRequest.getName() );
-        compareRequestCodec.setAttributeDesc( compareRequest.getAttributeId() );
-        compareRequestCodec.setAssertionValue( compareRequest.getAssertionValue().get() );
-
-        assertEquals( 0x33, compareRequestCodec.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = compareRequestCodec.encode();
+            ByteBuffer bb = encoder.encodeMessage( compareRequest );
+
+            // Check the length
+            assertEquals( 0x33, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -482,8 +472,7 @@ public class CompareRequestTest
         }
 
         // Ceck the decoded CompareRequest PDU
-        InternalCompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
-            .getInternalCompareRequest();
+        InternalCompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
 
         assertEquals( 1, compareRequest.getMessageId() );
         assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getName().toString() );
@@ -499,20 +488,13 @@ public class CompareRequestTest
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
         assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
 
-        // Check the length
-        CompareRequestCodec compareRequestCodec = new CompareRequestCodec();
-        compareRequestCodec.setMessageId( compareRequest.getMessageId() );
-        compareRequestCodec.setEntry( compareRequest.getName() );
-        compareRequestCodec.setAttributeDesc( compareRequest.getAttributeId() );
-        compareRequestCodec.setAssertionValue( compareRequest.getAssertionValue().get() );
-        compareRequestCodec.addControl( control );
-
-        assertEquals( 0x55, compareRequestCodec.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = compareRequestCodec.encode();
+            ByteBuffer bb = encoder.encodeMessage( compareRequest );
+
+            // Check the length
+            assertEquals( 0x55, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 



Mime
View raw message