You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/08/15 16:54:58 UTC

svn commit: r985686 [2/4] - in /directory: apacheds/branches/apacheds-codec-merge/core-api/src/main/java/org/apache/directory/server/core/ apacheds/branches/apacheds-codec-merge/core-api/src/test/java/org/apache/directory/server/core/ apacheds/branches...

Modified: directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java?rev=985686&r1=985685&r2=985686&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java (original)
+++ directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java Sun Aug 15 14:54:56 2010
@@ -61,11 +61,11 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.SearchResultEntryImpl;
 import org.apache.directory.shared.ldap.message.SearchResultReferenceImpl;
-import org.apache.directory.shared.ldap.message.internal.LdapResult;
 import org.apache.directory.shared.ldap.message.internal.InternalReferral;
-import org.apache.directory.shared.ldap.message.internal.Response;
 import org.apache.directory.shared.ldap.message.internal.InternalResultResponseRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalSearchRequest;
+import org.apache.directory.shared.ldap.message.internal.LdapResult;
+import org.apache.directory.shared.ldap.message.internal.Response;
 import org.apache.directory.shared.ldap.message.internal.SearchResultDone;
 import org.apache.directory.shared.ldap.message.internal.SearchResultEntry;
 import org.apache.directory.shared.ldap.message.internal.SearchResultReference;
@@ -94,6 +94,7 @@ public class SearchHandler extends LdapR
 
     protected ReplicationProvider replicationProvider;
 
+
     /**
      * Constructs a new filter EqualityNode asserting that a candidate
      * objectClass is a referral.
@@ -106,12 +107,12 @@ public class SearchHandler extends LdapR
     {
         if ( OBJECT_CLASS_AT == null )
         {
-            OBJECT_CLASS_AT = session.getCoreSession().getDirectoryService().
-                getSchemaManager().getAttributeType( SchemaConstants.OBJECT_CLASS_AT );
+            OBJECT_CLASS_AT = session.getCoreSession().getDirectoryService().getSchemaManager().getAttributeType(
+                SchemaConstants.OBJECT_CLASS_AT );
         }
 
-        EqualityNode<String> ocIsReferral = new EqualityNode<String>( OBJECT_CLASS_AT,
-            new StringValue( OBJECT_CLASS_AT, SchemaConstants.REFERRAL_OC ) );
+        EqualityNode<String> ocIsReferral = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
+            OBJECT_CLASS_AT, SchemaConstants.REFERRAL_OC ) );
 
         return ocIsReferral;
     }
@@ -134,7 +135,7 @@ public class SearchHandler extends LdapR
          * We want the search to complete first before we start listening to
          * events when the control does NOT specify changes ONLY mode.
          */
-        if ( ! psearchControl.isChangesOnly() )
+        if ( !psearchControl.isChangesOnly() )
         {
             SearchResultDone done = doSimpleSearch( session, req );
 
@@ -278,7 +279,8 @@ public class SearchHandler extends LdapR
      * @param session the {@link LdapSession} on which search was requested
      * @param cursor the {@link EntryFilteringCursor} over the search results
      */
-    private void setTimeLimitsOnCursor( InternalSearchRequest req, LdapSession session, final EntryFilteringCursor cursor )
+    private void setTimeLimitsOnCursor( InternalSearchRequest req, LdapSession session,
+        final EntryFilteringCursor cursor )
     {
         // Don't bother setting time limits for administrators
         if ( session.getCoreSession().isAnAdministrator() && req.getTimeLimit() == NO_TIME_LIMIT )
@@ -358,26 +360,24 @@ public class SearchHandler extends LdapR
 
 
     private void readResults( LdapSession session, InternalSearchRequest req, LdapResult ldapResult,
-    EntryFilteringCursor cursor, long sizeLimit ) throws Exception
+        EntryFilteringCursor cursor, long sizeLimit ) throws Exception
     {
         long count = 0;
 
-        while ( (count < sizeLimit ) && cursor.next() )
+        while ( ( count < sizeLimit ) && cursor.next() )
         {
             // Handle closed session
             if ( session.getIoSession().isClosing() )
             {
                 // The client has closed the connection
-                LOG.debug( "Request terminated for message {}, the client has closed the session",
-                    req.getMessageId() );
+                LOG.debug( "Request terminated for message {}, the client has closed the session", req.getMessageId() );
                 break;
             }
 
             if ( req.isAbandoned() )
             {
                 // The cursor has been closed by an abandon request.
-                LOG.debug( "Request terminated by an AbandonRequest for message {}",
-                    req.getMessageId() );
+                LOG.debug( "Request terminated by an AbandonRequest for message {}", req.getMessageId() );
                 break;
             }
 
@@ -403,8 +403,8 @@ public class SearchHandler extends LdapR
 
 
     private void readPagedResults( LdapSession session, InternalSearchRequest req, LdapResult ldapResult,
-        EntryFilteringCursor cursor, long sizeLimit, int pagedLimit,
-        PagedSearchContext pagedContext, PagedResultsControl pagedResultsControl ) throws Exception
+        EntryFilteringCursor cursor, long sizeLimit, int pagedLimit, PagedSearchContext pagedContext,
+        PagedResultsControl pagedResultsControl ) throws Exception
     {
         req.addAbandonListener( new SearchAbandonListener( ldapServer, cursor ) );
         setTimeLimitsOnCursor( req, session, cursor );
@@ -459,7 +459,7 @@ public class SearchHandler extends LdapR
             pagedResultsControl = new PagedResultsControl();
             pagedResultsControl.setCritical( true );
             pagedResultsControl.setSize( 0 );
-            req.getResultResponse().add( pagedResultsControl );
+            req.getResultResponse().addControl( pagedResultsControl );
 
             return;
         }
@@ -472,7 +472,7 @@ public class SearchHandler extends LdapR
                 // We stop here. We have to add a ResponseControl
                 // DO NOT WRITE THE RESPONSE - JUST RETURN IT
                 ldapResult.setResultCode( ResultCodeEnum.SUCCESS );
-                req.getResultResponse().add( pagedResultsControl );
+                req.getResultResponse().addControl( pagedResultsControl );
 
                 // Stores the cursor current position
                 pagedContext.incrementCurrentPosition( pageCount );
@@ -500,20 +500,19 @@ public class SearchHandler extends LdapR
      * Manage the abandoned Paged Search (when paged size = 0). We have to
      * remove the cookie and its associated cursor from the session.
      */
-    private SearchResultDone abandonPagedSearch( LdapSession session, InternalSearchRequest req )
-        throws Exception
+    private SearchResultDone abandonPagedSearch( LdapSession session, InternalSearchRequest req ) throws Exception
     {
         PagedResultsControl pagedResultsControl = null;
-        PagedResultsControl pagedSearchControl =
-            ( PagedResultsControl )req.getControls().get( PagedResultsControl.CONTROL_OID );
-        byte [] cookie = pagedSearchControl.getCookie();
+        PagedResultsControl pagedSearchControl = ( PagedResultsControl ) req.getControls().get(
+            PagedResultsControl.CONTROL_OID );
+        byte[] cookie = pagedSearchControl.getCookie();
 
         if ( !StringTools.isEmpty( cookie ) )
         {
             // If the cookie is not null, we have to destroy the associated
             // cursor stored into the session (if any)
             int cookieValue = pagedSearchControl.getCookieValue();
-            PagedSearchContext psCookie =  session.removePagedSearchContext( cookieValue );
+            PagedSearchContext psCookie = session.removePagedSearchContext( cookieValue );
             pagedResultsControl = new PagedResultsControl();
             pagedResultsControl.setCookie( psCookie.getCookie() );
             pagedResultsControl.setSize( 0 );
@@ -538,7 +537,7 @@ public class SearchHandler extends LdapR
         // DO NOT WRITE THE RESPONSE - JUST RETURN IT
         LdapResult ldapResult = req.getResultResponse().getLdapResult();
         ldapResult.setResultCode( ResultCodeEnum.SUCCESS );
-        req.getResultResponse().add( pagedResultsControl );
+        req.getResultResponse().addControl( pagedResultsControl );
         return ( SearchResultDone ) req.getResultResponse();
     }
 
@@ -572,8 +571,7 @@ public class SearchHandler extends LdapR
         // Don't bother setting size limits for administrators that don't ask for it
         long serverLimit = getServerSizeLimit( session, req );
 
-        long requestLimit = req.getSizeLimit() == 0L ?
-            Long.MAX_VALUE : req.getSizeLimit();
+        long requestLimit = req.getSizeLimit() == 0L ? Long.MAX_VALUE : req.getSizeLimit();
         long sizeLimit = min( serverLimit, requestLimit );
 
         int pagedLimit = pagedSearchControl.getSize();
@@ -602,7 +600,7 @@ public class SearchHandler extends LdapR
         }
 
         // Now, depending on the cookie, we will deal with case 2, 3, 4 and 5
-        byte [] cookie= pagedSearchControl.getCookie();
+        byte[] cookie = pagedSearchControl.getCookie();
         LdapResult ldapResult = req.getResultResponse().getLdapResult();
 
         if ( StringTools.isEmpty( cookie ) )
@@ -652,7 +650,6 @@ public class SearchHandler extends LdapR
                 pagedResultsControl.setSize( 0 );
                 pagedResultsControl.setCritical( true );
 
-
                 // No cursor : do a search.
                 cursor = session.getCoreSession().search( req );
 
@@ -725,7 +722,8 @@ public class SearchHandler extends LdapR
          */
         try
         {
-            readPagedResults( session, req, ldapResult, cursor, sizeLimit, pagedLimit, pagedContext, pagedResultsControl );
+            readPagedResults( session, req, ldapResult, cursor, sizeLimit, pagedLimit, pagedContext,
+                pagedResultsControl );
         }
         catch ( Exception e )
         {
@@ -757,8 +755,7 @@ public class SearchHandler extends LdapR
      * @return the result done
      * @throws Exception if there are failures while processing the request
      */
-    private SearchResultDone doSimpleSearch( LdapSession session, InternalSearchRequest req )
-        throws Exception
+    private SearchResultDone doSimpleSearch( LdapSession session, InternalSearchRequest req ) throws Exception
     {
         LdapResult ldapResult = req.getResultResponse().getLdapResult();
 
@@ -768,7 +765,7 @@ public class SearchHandler extends LdapR
         if ( control != null )
         {
             // Let's deal with the pagedControl
-            return doPagedSearch( session, req, (PagedResultsControl)control );
+            return doPagedSearch( session, req, ( PagedResultsControl ) control );
         }
 
         // A normal search
@@ -789,8 +786,7 @@ public class SearchHandler extends LdapR
             // Don't bother setting size limits for administrators that don't ask for it
             long serverLimit = getServerSizeLimit( session, req );
 
-            long requestLimit = req.getSizeLimit() == 0L ?
-                Long.MAX_VALUE : req.getSizeLimit();
+            long requestLimit = req.getSizeLimit() == 0L ? Long.MAX_VALUE : req.getSizeLimit();
 
             req.addAbandonListener( new SearchAbandonListener( ldapServer, cursor ) );
             setTimeLimitsOnCursor( req, session, cursor );
@@ -832,10 +828,10 @@ public class SearchHandler extends LdapR
      */
     private Response generateResponse( LdapSession session, InternalSearchRequest req, Entry entry ) throws Exception
     {
-        EntryAttribute ref = ((ClonedServerEntry)entry).getOriginalEntry().get( SchemaConstants.REF_AT );
+        EntryAttribute ref = ( ( ClonedServerEntry ) entry ).getOriginalEntry().get( SchemaConstants.REF_AT );
         boolean hasManageDsaItControl = req.getControls().containsKey( ManageDsaITControl.CONTROL_OID );
 
-        if ( ( ref != null ) && ! hasManageDsaItControl )
+        if ( ( ref != null ) && !hasManageDsaItControl )
         {
             // The entry is a referral.
             SearchResultReference respRef;
@@ -846,7 +842,7 @@ public class SearchHandler extends LdapR
             {
                 String url = val.getString();
 
-                if ( ! url.startsWith( "ldap" ) )
+                if ( !url.startsWith( "ldap" ) )
                 {
                     respRef.getReferral().addLdapUrl( url );
                 }
@@ -862,7 +858,7 @@ public class SearchHandler extends LdapR
                     LOG.error( I18n.err( I18n.ERR_165, url, entry ) );
                 }
 
-                switch( req.getScope() )
+                switch ( req.getScope() )
                 {
                     case SUBTREE:
                         ldapUrl.setScope( SearchScope.SUBTREE.getScope() );
@@ -952,8 +948,8 @@ public class SearchHandler extends LdapR
             {
                 String attribute = presenceNode.getAttribute();
 
-                if ( attribute.equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT ) ||
-                     attribute.equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT_OID ) )
+                if ( attribute.equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT )
+                    || attribute.equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT_OID ) )
                 {
                     return;
                 }
@@ -1021,8 +1017,8 @@ public class SearchHandler extends LdapR
             // Handle psearch differently
             // ===============================================================
 
-            PersistentSearchControl psearchControl = ( PersistentSearchControl )
-                req.getControls().get( PersistentSearchControl.CONTROL_OID );
+            PersistentSearchControl psearchControl = ( PersistentSearchControl ) req.getControls().get(
+                PersistentSearchControl.CONTROL_OID );
 
             if ( psearchControl != null )
             {
@@ -1159,7 +1155,7 @@ public class SearchHandler extends LdapR
                 {
                     LOG.debug( "Entry is a referral: {}", entry );
 
-                    handleReferralEntryForSearch( session, req, ((ClonedServerEntry)entry) );
+                    handleReferralEntryForSearch( session, req, ( ( ClonedServerEntry ) entry ) );
 
                     return;
                 }
@@ -1203,7 +1199,8 @@ public class SearchHandler extends LdapR
                 // if we get here then we have a valid referral ancestor
                 try
                 {
-                    InternalReferral referral = getReferralOnAncestorForSearch( session, req, ((ClonedServerEntry)referralAncestor) );
+                    InternalReferral referral = getReferralOnAncestorForSearch( session, req,
+                        ( ( ClonedServerEntry ) referralAncestor ) );
 
                     result.setResultCode( ResultCodeEnum.REFERRAL );
                     result.setReferral( referral );
@@ -1245,7 +1242,7 @@ public class SearchHandler extends LdapR
             String refstr = refval.getString();
 
             // need to add non-ldap URLs as-is
-            if ( ! refstr.startsWith( "ldap" ) )
+            if ( !refstr.startsWith( "ldap" ) )
             {
                 referral.addLdapUrl( refstr );
                 continue;
@@ -1304,7 +1301,8 @@ public class SearchHandler extends LdapR
             else
             {
                 String attribute = ( ( PresenceNode ) req.getFilter() ).getAttribute();
-                isRootDSEFilter = attribute.equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT ) || attribute.equals( SchemaConstants.OBJECT_CLASS_AT_OID );
+                isRootDSEFilter = attribute.equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT )
+                    || attribute.equals( SchemaConstants.OBJECT_CLASS_AT_OID );
             }
         }
 
@@ -1363,8 +1361,7 @@ public class SearchHandler extends LdapR
     {
         LOG.debug( "Inside getReferralOnAncestor()" );
 
-        EntryAttribute refAttr = referralAncestor.getOriginalEntry()
-            .get( SchemaConstants.REF_AT );
+        EntryAttribute refAttr = referralAncestor.getOriginalEntry().get( SchemaConstants.REF_AT );
         InternalReferral referral = new ReferralImpl();
 
         for ( Value<?> value : refAttr )
@@ -1374,7 +1371,7 @@ public class SearchHandler extends LdapR
             LOG.debug( "Calculating LdapURL for referrence value {}", ref );
 
             // need to add non-ldap URLs as-is
-            if ( ! ref.startsWith( "ldap" ) )
+            if ( !ref.startsWith( "ldap" ) )
             {
                 referral.addLdapUrl( ref );
                 continue;
@@ -1392,7 +1389,8 @@ public class SearchHandler extends LdapR
             }
 
             // Normalize the DN to check for same dn
-            DN urlDn = new DN( ldapUrl.getDn().getName(), session.getCoreSession().getDirectoryService().getSchemaManager() );
+            DN urlDn = new DN( ldapUrl.getDn().getName(), session.getCoreSession().getDirectoryService()
+                .getSchemaManager() );
 
             if ( urlDn.getNormName().equals( req.getBase().getNormName() ) )
             {
@@ -1444,8 +1442,7 @@ public class SearchHandler extends LdapR
     {
         LOG.debug( "Inside getReferralOnAncestor()" );
 
-        EntryAttribute refAttr =referralAncestor.getOriginalEntry()
-            .get( SchemaConstants.REF_AT );
+        EntryAttribute refAttr = referralAncestor.getOriginalEntry().get( SchemaConstants.REF_AT );
         InternalReferral referral = new ReferralImpl();
 
         for ( Value<?> value : refAttr )
@@ -1455,7 +1452,7 @@ public class SearchHandler extends LdapR
             LOG.debug( "Calculating LdapURL for referrence value {}", ref );
 
             // need to add non-ldap URLs as-is
-            if ( ! ref.startsWith( "ldap" ) )
+            if ( !ref.startsWith( "ldap" ) )
             {
                 referral.addLdapUrl( ref );
                 continue;
@@ -1472,7 +1469,8 @@ public class SearchHandler extends LdapR
                 LOG.error( I18n.err( I18n.ERR_165, ref, referralAncestor ) );
             }
 
-            DN urlDn = new DN( ldapUrl.getDn().getName(), session.getCoreSession().getDirectoryService().getSchemaManager() );
+            DN urlDn = new DN( ldapUrl.getDn().getName(), session.getCoreSession().getDirectoryService()
+                .getSchemaManager() );
 
             if ( urlDn.getNormName().equals( referralAncestor.getDn().getNormName() ) )
             {
@@ -1571,11 +1569,8 @@ public class SearchHandler extends LdapR
             LdapOperationException ne = ( LdapOperationException ) e;
 
             // Add the matchedDN if necessary
-            boolean setMatchedDn =
-                code == ResultCodeEnum.NO_SUCH_OBJECT             ||
-                code == ResultCodeEnum.ALIAS_PROBLEM              ||
-                code == ResultCodeEnum.INVALID_DN_SYNTAX          ||
-                code == ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM;
+            boolean setMatchedDn = code == ResultCodeEnum.NO_SUCH_OBJECT || code == ResultCodeEnum.ALIAS_PROBLEM
+                || code == ResultCodeEnum.INVALID_DN_SYNTAX || code == ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM;
 
             if ( ( ne.getResolvedDn() != null ) && setMatchedDn )
             {
@@ -1600,8 +1595,7 @@ public class SearchHandler extends LdapR
      */
     // This will suppress PMD.EmptyCatchBlock warnings in this method
     @SuppressWarnings("PMD.EmptyCatchBlock")
-    public static final Entry getFarthestReferralAncestor( LdapSession session, DN target )
-        throws Exception
+    public static final Entry getFarthestReferralAncestor( LdapSession session, DN target ) throws Exception
     {
         Entry entry;
         Entry farthestReferralAncestor = null;
@@ -1616,7 +1610,7 @@ public class SearchHandler extends LdapR
             // never thrown
         }
 
-        while ( ! dn.isEmpty() )
+        while ( !dn.isEmpty() )
         {
             LOG.debug( "Walking ancestors of {} to find referrals.", dn );
 
@@ -1624,7 +1618,8 @@ public class SearchHandler extends LdapR
             {
                 entry = session.getCoreSession().lookup( dn );
 
-                boolean isReferral = ((ClonedServerEntry)entry).getOriginalEntry().contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.REFERRAL_OC );
+                boolean isReferral = ( ( ClonedServerEntry ) entry ).getOriginalEntry().contains(
+                    SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.REFERRAL_OC );
 
                 if ( isReferral )
                 {

Modified: directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplProvider.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplProvider.java?rev=985686&r1=985685&r2=985686&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplProvider.java (original)
+++ directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplProvider.java Sun Aug 15 14:54:56 2010
@@ -78,9 +78,9 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.control.replication.SynchronizationInfoEnum;
 import org.apache.directory.shared.ldap.message.control.replication.SynchronizationModeEnum;
 import org.apache.directory.shared.ldap.message.internal.InternalIntermediateResponse;
+import org.apache.directory.shared.ldap.message.internal.InternalSearchRequest;
 import org.apache.directory.shared.ldap.message.internal.LdapResult;
 import org.apache.directory.shared.ldap.message.internal.Response;
-import org.apache.directory.shared.ldap.message.internal.InternalSearchRequest;
 import org.apache.directory.shared.ldap.message.internal.SearchResultDone;
 import org.apache.directory.shared.ldap.message.internal.SearchResultEntry;
 import org.apache.directory.shared.ldap.message.internal.SearchResultReference;
@@ -116,15 +116,16 @@ public class SyncReplProvider implements
     private Map<Integer, ReplicaEventLog> replicaLogMap = new HashMap<Integer, ReplicaEventLog>();
 
     private BrokerService brokerService;
-    
+
     private ActiveMQConnection amqConnection;
 
     private File syncReplData;
 
-    private AtomicInteger replicaCount = new AtomicInteger(0);
+    private AtomicInteger replicaCount = new AtomicInteger( 0 );
 
     private ReplicaDitStoreUtil replicaUtil;
-    
+
+
     public SyncReplProvider()
     {
     }
@@ -160,7 +161,7 @@ public class SyncReplProvider implements
 
             URI vmConnectorUri = new URI( "vm://localhost" );
             brokerService.setVmConnectorURI( vmConnectorUri );
-            
+
             brokerService.start();
             ActiveMQConnectionFactory amqFactory = new ActiveMQConnectionFactory( vmConnectorUri.toString() );
             amqFactory.setObjectMessageSerializationDefered( false );
@@ -172,15 +173,15 @@ public class SyncReplProvider implements
             ReplicaEventMessage.setSchemaManager( dirService.getSchemaManager() );
 
             replicaUtil = new ReplicaDitStoreUtil( dirService );
-            
+
             loadReplicaInfo();
-            
+
             registerPersistentSearches();
-            
+
             Thread consumerInfoUpdateThread = new Thread( createConsumerInfoUpdateTask() );
             consumerInfoUpdateThread.setDaemon( true );
             consumerInfoUpdateThread.start();
-            
+
             initialized = true;
             LOG.info( "syncrepl provider initialized successfully" );
         }
@@ -214,11 +215,11 @@ public class SyncReplProvider implements
         {
             SyncRequestValueControl syncControl = ( SyncRequestValueControl ) req.getControls().get(
                 SyncRequestValueControl.CONTROL_OID );
-            
+
             // cookie is in the format <replicaId>;<Csn value>
             byte[] cookieBytes = syncControl.getCookie();
             String cookieString = StringTools.utf8ToString( cookieBytes );
-            
+
             if ( cookieBytes == null )
             {
                 doInitialRefresh( session, req );
@@ -234,9 +235,10 @@ public class SyncReplProvider implements
                 else
                 {
                     ReplicaEventLog clientMsgLog = getReplicaEventLog( cookieString );
-                    if( clientMsgLog == null )
+                    if ( clientMsgLog == null )
                     {
-                        LOG.warn( "received a valid cookie {} but there is no event log associated with this replica", cookieString );
+                        LOG.warn( "received a valid cookie {} but there is no event log associated with this replica",
+                            cookieString );
                         sendESyncRefreshRequired( session, req );
                     }
                     else
@@ -257,8 +259,9 @@ public class SyncReplProvider implements
         }
     }
 
-    
-    private String sendContentFromLog( LdapSession session, InternalSearchRequest req, ReplicaEventLog clientMsgLog ) throws Exception
+
+    private String sendContentFromLog( LdapSession session, InternalSearchRequest req, ReplicaEventLog clientMsgLog )
+        throws Exception
     {
         // do the search from the log
         String lastSentCsn = clientMsgLog.getLastSentCsn();
@@ -269,28 +272,28 @@ public class SyncReplProvider implements
             ReplicaEventMessage message = cursor.get();
             Entry entry = message.getEntry();
             LOG.debug( "received message from the queue {}", entry );
-            
+
             lastSentCsn = entry.get( SchemaConstants.ENTRY_CSN_AT ).getString();
-            
+
             EventType event = message.getEventType();
-            
+
             // if event type is null, then it is a MODDN operation
-            if( event == null )
+            if ( event == null )
             {
                 sendSearchResultEntry( session, req, entry, message.getModDnControl() );
             }
             else
             {
                 SyncStateTypeEnum syncStateType = null;
-                if( event == EventType.ADD || event == EventType.MODIFY )
+                if ( event == EventType.ADD || event == EventType.MODIFY )
                 {
                     syncStateType = SyncStateTypeEnum.ADD;
                 }
-                else if( event == EventType.DELETE )
+                else if ( event == EventType.DELETE )
                 {
                     syncStateType = SyncStateTypeEnum.DELETE;
                 }
-                
+
                 sendSearchResultEntry( session, req, entry, syncStateType );
             }
         }
@@ -299,37 +302,37 @@ public class SyncReplProvider implements
         return lastSentCsn;
     }
 
-    
+
     private void doContentUpdate( LdapSession session, InternalSearchRequest req, ReplicaEventLog replicaLog )
         throws Exception
     {
         boolean refreshNPersist = isRefreshNPersist( req );
-        
+
         // if this method is called with refreshAndPersist  
         // means the client was offline after it initiated a persistent synch session
         // we need to update the handler's session 
-        if( refreshNPersist )
+        if ( refreshNPersist )
         {
             SyncReplSearchListener handler = replicaLog.getPersistentListener();
             handler.setReq( req );
             handler.setSession( session );
         }
-        
+
         String lastSentCsn = sendContentFromLog( session, req, replicaLog );
-        
-        byte[] cookie = StringTools.getBytesUtf8( replicaLog.getId() + REPLICA_ID_DELIM + lastSentCsn ) ;
-        
-        if( refreshNPersist )
+
+        byte[] cookie = StringTools.getBytesUtf8( replicaLog.getId() + REPLICA_ID_DELIM + lastSentCsn );
+
+        if ( refreshNPersist )
         {
             InternalIntermediateResponse intermResp = new IntermediateResponseImpl( req.getMessageId() );
             intermResp.setResponseName( SyncInfoValueControl.CONTROL_OID );
-            
+
             SyncInfoValueControl syncInfo = new SyncInfoValueControl( SynchronizationInfoEnum.NEW_COOKIE );
             syncInfo.setCookie( cookie );
             intermResp.setResponseValue( syncInfo.getValue() );
-            
+
             session.getIoSession().write( intermResp );
-            
+
             replicaLog.getPersistentListener().setPushInRealTime( refreshNPersist );
         }
         else
@@ -338,32 +341,31 @@ public class SyncReplProvider implements
             searchDoneResp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
             SyncDoneValueControl syncDone = new SyncDoneValueControl();
             syncDone.setCookie( cookie );
-            searchDoneResp.add( syncDone );
-            
+            searchDoneResp.addControl( syncDone );
+
             session.getIoSession().write( searchDoneResp );
         }
-        
+
         replicaLog.setLastSentCsn( lastSentCsn );
     }
 
 
-    private void doInitialRefresh( LdapSession session, InternalSearchRequest req )
-        throws Exception
+    private void doInitialRefresh( LdapSession session, InternalSearchRequest req ) throws Exception
     {
 
         String originalFilter = req.getFilter().toString();
-        InetSocketAddress address = ( InetSocketAddress )session.getIoSession().getRemoteAddress();
+        InetSocketAddress address = ( InetSocketAddress ) session.getIoSession().getRemoteAddress();
         String hostName = address.getAddress().getHostName();
 
         ExprNode modifiedFilter = modifyFilter( session, req );
 
         String contextCsn = dirService.getContextCsn();
-        
+
         boolean refreshNPersist = isRefreshNPersist( req );
 
         // first register a persistent search handler before starting the initial content refresh
         // this is to log all the operations happen on DIT during initial content refresh
-        
+
         ReplicaEventLog replicaLog = createRelicaEventLog( hostName, originalFilter );
 
         replicaLog.setRefreshNPersist( refreshNPersist );
@@ -372,10 +374,10 @@ public class SyncReplProvider implements
         GreaterEqNode csnGeNode = new GreaterEqNode( SchemaConstants.ENTRY_CSN_AT, new StringValue( contextCsn ) );
         ExprNode postInitContentFilter = new AndNode( modifiedFilter, csnGeNode );
         req.setFilter( postInitContentFilter );
-        
+
         // now we process entries forever as they change
         LOG.info( "starting persistent search for the client {}", replicaLog );
-        
+
         // irrespective of the sync mode set the 'isRealtimePush' to false initially so that we can
         // store the modifications in the queue and later if it is a persist mode
         // we push this queue's content and switch to realtime mode
@@ -391,12 +393,11 @@ public class SyncReplProvider implements
         criteria.setFilter( req.getFilter() );
         criteria.setScope( req.getScope() );
         criteria.setEventMask( EventType.ALL_EVENT_TYPES_MASK );
-        
+
         replicaLog.setSearchCriteria( criteria );
-        
+
         dirService.getEventService().addListener( handler, criteria );
 
-        
         // then start pushing initial content
         LessEqNode csnNode = new LessEqNode( SchemaConstants.ENTRY_CSN_AT, new StringValue( contextCsn ) );
 
@@ -405,26 +406,26 @@ public class SyncReplProvider implements
         req.setFilter( initialContentFilter );
 
         SearchResultDone searchDoneResp = doSimpleSearch( session, req );
-        
+
         if ( searchDoneResp.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
         {
             replicaLog.setLastSentCsn( contextCsn );
-            byte[] cookie = StringTools.getBytesUtf8( replicaLog.getId() + REPLICA_ID_DELIM + contextCsn ) ;
-            
-            if( refreshNPersist ) // refreshAndPersist mode
+            byte[] cookie = StringTools.getBytesUtf8( replicaLog.getId() + REPLICA_ID_DELIM + contextCsn );
+
+            if ( refreshNPersist ) // refreshAndPersist mode
             {
                 contextCsn = sendContentFromLog( session, req, replicaLog );
-                cookie = StringTools.getBytesUtf8( replicaLog.getId() + REPLICA_ID_DELIM + contextCsn ) ;
-                
+                cookie = StringTools.getBytesUtf8( replicaLog.getId() + REPLICA_ID_DELIM + contextCsn );
+
                 InternalIntermediateResponse intermResp = new IntermediateResponseImpl( req.getMessageId() );
                 intermResp.setResponseName( SyncInfoValueControl.CONTROL_OID );
-                
+
                 SyncInfoValueControl syncInfo = new SyncInfoValueControl( SynchronizationInfoEnum.NEW_COOKIE );
                 syncInfo.setCookie( cookie );
                 intermResp.setResponseValue( syncInfo.getValue() );
-                
+
                 session.getIoSession().write( intermResp );
-                
+
                 // switch the handler mode to realtime push
                 handler.setPushInRealTime( refreshNPersist );
             }
@@ -433,32 +434,33 @@ public class SyncReplProvider implements
                 // no need to send from the log, that will be done in the next refreshOnly session
                 SyncDoneValueControl syncDone = new SyncDoneValueControl();
                 syncDone.setCookie( cookie );
-                searchDoneResp.add( syncDone );
+                searchDoneResp.addControl( syncDone );
                 session.getIoSession().write( searchDoneResp );
             }
         }
-        else // if not succeeded return
+        else
+        // if not succeeded return
         {
-            LOG.warn( "initial content refresh didn't succeed due to {}", searchDoneResp.getLdapResult().getResultCode() );
+            LOG.warn( "initial content refresh didn't succeed due to {}", searchDoneResp.getLdapResult()
+                .getResultCode() );
             replicaLog.truncate();
             replicaLog = null;
-            
+
             // remove the listener
             dirService.getEventService().removeListener( handler );
-            
+
             return;
         }
-        
+
         // if all is well then store the consumer infor
         replicaUtil.addConsumerEntry( replicaLog );
-        
+
         // add to the map only after storing in the DIT, else the Replica update thread barfs
         replicaLogMap.put( replicaLog.getId(), replicaLog );
     }
 
 
-    private SearchResultDone doSimpleSearch( LdapSession session, InternalSearchRequest req )
-        throws Exception
+    private SearchResultDone doSimpleSearch( LdapSession session, InternalSearchRequest req ) throws Exception
     {
         SearchResultDone searchDoneResp = ( SearchResultDone ) req.getResultResponse();
         LdapResult ldapResult = searchDoneResp.getLdapResult();
@@ -562,15 +564,15 @@ public class SyncReplProvider implements
         syncStateControl.setSyncStateType( syncStateType );
         syncStateControl.setEntryUUID( StringTools.uuidToBytes( uuid.getString() ) );
 
-        if( syncStateType == SyncStateTypeEnum.DELETE )
+        if ( syncStateType == SyncStateTypeEnum.DELETE )
         {
             // clear the entry's all attributes except the DN and entryUUID
             entry.clear();
             entry.add( uuid );
         }
-        
+
         Response resp = generateResponse( session, req, entry );
-        resp.add( syncStateControl );
+        resp.addControl( syncStateControl );
 
         session.getIoSession().write( resp );
         LOG.debug( "Sending {}", entry.getDn() );
@@ -587,16 +589,15 @@ public class SyncReplProvider implements
         syncStateControl.setEntryUUID( StringTools.uuidToBytes( uuid.getString() ) );
 
         Response resp = generateResponse( session, req, entry );
-        resp.add( syncStateControl );
-        resp.add( modDnControl );
-        
+        resp.addControl( syncStateControl );
+        resp.addControl( modDnControl );
+
         session.getIoSession().write( resp );
         LOG.debug( "Sending {}", entry.getDn() );
     }
 
-    
-    private Response generateResponse( LdapSession session, InternalSearchRequest req, Entry entry )
-        throws Exception
+
+    private Response generateResponse( LdapSession session, InternalSearchRequest req, Entry entry ) throws Exception
     {
         EntryAttribute ref = entry.get( SchemaConstants.REF_AT );
         boolean hasManageDsaItControl = req.getControls().containsKey( ManageDsaITControl.CONTROL_OID );
@@ -809,10 +810,10 @@ public class SyncReplProvider implements
     {
         try
         {
-            for( Map.Entry<Integer, ReplicaEventLog> e : replicaLogMap.entrySet() )
+            for ( Map.Entry<Integer, ReplicaEventLog> e : replicaLogMap.entrySet() )
             {
                 ReplicaEventLog replica = e.getValue();
-                if( replica.isDirty() )
+                if ( replica.isDirty() )
                 {
                     LOG.debug( "updating the details of replica {}", replica );
                     replicaUtil.updateReplicaLastSentCsn( replica );
@@ -820,29 +821,29 @@ public class SyncReplProvider implements
                 }
             }
         }
-        catch( Exception e )
+        catch ( Exception e )
         {
             LOG.error( "Failed to store the replica information", e );
         }
     }
-    
-    
+
+
     private void loadReplicaInfo()
     {
         try
         {
 
             List<ReplicaEventLog> replicas = replicaUtil.getReplicaConsumers();
-            if( !replicas.isEmpty() )
+            if ( !replicas.isEmpty() )
             {
-                for( ReplicaEventLog r : replicas )
+                for ( ReplicaEventLog r : replicas )
                 {
                     LOG.debug( "initializing the replica log from {}", r.getId() );
                     r.configure( amqConnection, brokerService );
                     replicaLogMap.put( r.getId(), r );
-                    
+
                     // update the replicaCount's value to assign a correct value to the new replica(s) 
-                    if( replicaCount.get() < r.getId() )
+                    if ( replicaCount.get() < r.getId() )
                     {
                         replicaCount.set( r.getId() );
                     }
@@ -853,146 +854,148 @@ public class SyncReplProvider implements
                 LOG.debug( "no replica logs found to initialize" );
             }
         }
-        catch( Exception e )
+        catch ( Exception e )
         {
             LOG.error( "Failed to load the replica information", e );
         }
     }
-    
- 
+
+
     private void registerPersistentSearches() throws Exception
     {
-        for( Map.Entry<Integer, ReplicaEventLog> e : replicaLogMap.entrySet() )
+        for ( Map.Entry<Integer, ReplicaEventLog> e : replicaLogMap.entrySet() )
         {
             ReplicaEventLog log = e.getValue();
-            
-            if( log.getSearchCriteria() != null )
+
+            if ( log.getSearchCriteria() != null )
             {
                 LOG.debug( "registering peristent search for the replica {}", log.getId() );
                 SyncReplSearchListener handler = new SyncReplSearchListener( null, null, log, false );
                 log.setPersistentListener( handler );
-                
+
                 dirService.getEventService().addListener( handler, log.getSearchCriteria() );
             }
             else
             {
-                LOG.warn( "invalid peristent search criteria {} for the replica {}", log.getSearchCriteria(), log.getId() );
+                LOG.warn( "invalid peristent search criteria {} for the replica {}", log.getSearchCriteria(), log
+                    .getId() );
             }
-        }    
+        }
     }
-    
-    
+
+
     private Runnable createConsumerInfoUpdateTask()
     {
         Runnable task = new Runnable()
         {
             public void run()
             {
-                while( true )
+                while ( true )
                 {
                     storeReplicaInfo();
                     try
                     {
                         Thread.sleep( 10000 );
                     }
-                    catch( InterruptedException e )
+                    catch ( InterruptedException e )
                     {
                         LOG.warn( "thread storing the replica information was interrupted", e );
                     }
                 }
             }
         };
-        
+
         return task;
     }
-    
- 
+
+
     private boolean isValidCookie( String cookieString )
     {
-        if( cookieString == null || cookieString.trim().length() == 0 )
+        if ( cookieString == null || cookieString.trim().length() == 0 )
         {
             return false;
         }
-        
+
         int pos = cookieString.indexOf( REPLICA_ID_DELIM );
-        if( pos <= 0 ) // position should start from 1 or higher cause a cookie can be like "0;<csn>" or "11;<csn>"
+        if ( pos <= 0 ) // position should start from 1 or higher cause a cookie can be like "0;<csn>" or "11;<csn>"
         {
             return false;
         }
-        
+
         String replicaId = cookieString.substring( 0, pos );
         try
         {
             Integer.parseInt( replicaId );
         }
-        catch( NumberFormatException e )
+        catch ( NumberFormatException e )
         {
             LOG.debug( "Failed to parse the replica id {}", replicaId );
             return false;
         }
-        
-        if( pos == cookieString.length() )
+
+        if ( pos == cookieString.length() )
         {
             return false;
         }
-        
+
         String csnString = cookieString.substring( pos + 1 );
-        
+
         return Csn.isValid( csnString );
     }
-    
-    
+
+
     private int getReplicaId( String cookieString )
     {
         String replicaId = cookieString.substring( 0, cookieString.indexOf( REPLICA_ID_DELIM ) );
         return Integer.parseInt( replicaId );
     }
-    
-    
+
+
     private ReplicaEventLog getReplicaEventLog( String cookieString ) throws Exception
     {
         ReplicaEventLog replicaLog = null;
-        
-        if( isValidCookie( cookieString ) )
+
+        if ( isValidCookie( cookieString ) )
         {
             int clientId = getReplicaId( cookieString );
             replicaLog = replicaLogMap.get( clientId );
         }
-        
+
         return replicaLog;
     }
-    
-    
+
+
     private ReplicaEventLog createRelicaEventLog( String hostName, String filter ) throws Exception
     {
         int replicaId = replicaCount.incrementAndGet();
-        
+
         LOG.debug( "creating a new event log for the replica with id {}", replicaId );
-        
+
         ReplicaEventLog replicaLog = new ReplicaEventLog( replicaId );
         replicaLog.setHostName( hostName );
         replicaLog.setSearchFilter( filter );
-        
+
         replicaLog.configure( amqConnection, brokerService );
-        
+
         return replicaLog;
     }
-    
-    
+
+
     private void sendESyncRefreshRequired( LdapSession session, InternalSearchRequest req ) throws Exception
     {
         SearchResultDone searchDoneResp = ( SearchResultDone ) req.getResultResponse();
         searchDoneResp.getLdapResult().setResultCode( ResultCodeEnum.E_SYNC_REFRESH_REQUIRED );
         SyncDoneValueControl syncDone = new SyncDoneValueControl();
-        searchDoneResp.add( syncDone );
-        
+        searchDoneResp.addControl( syncDone );
+
         session.getIoSession().write( searchDoneResp );
     }
-    
-    
+
+
     private boolean isRefreshNPersist( InternalSearchRequest req )
     {
-        SyncRequestValueControl control = ( SyncRequestValueControl ) req.getControls().get( SyncRequestValueControl.CONTROL_OID );
+        SyncRequestValueControl control = ( SyncRequestValueControl ) req.getControls().get(
+            SyncRequestValueControl.CONTROL_OID );
         return ( control.getMode() == SynchronizationModeEnum.REFRESH_AND_PERSIST ? true : false );
     }
 }

Modified: directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplSearchListener.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplSearchListener.java?rev=985686&r1=985685&r2=985686&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplSearchListener.java (original)
+++ directory/apacheds/branches/apacheds-codec-merge/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/SyncReplSearchListener.java Sun Aug 15 14:54:56 2010
@@ -135,22 +135,22 @@ public class SyncReplSearchListener impl
         Entry entry = addContext.getEntry();
 
         LOG.debug( "sending added entry {}", entry.getDn() );
-        
+
         try
         {
             if ( pushInRealTime )
             {
-                
+
                 SearchResultEntry respEntry = new SearchResultEntryImpl( req.getMessageId() );
                 respEntry.setObjectName( entry.getDn() );
                 respEntry.setEntry( entry );
 
                 SyncStateValueControl syncAdd = new SyncStateValueControl();
                 syncAdd.setSyncStateType( SyncStateTypeEnum.ADD );
-                syncAdd.setEntryUUID( StringTools.uuidToBytes( entry.get( SchemaConstants.ENTRY_UUID_AT )
-                    .getString() ) );
+                syncAdd
+                    .setEntryUUID( StringTools.uuidToBytes( entry.get( SchemaConstants.ENTRY_UUID_AT ).getString() ) );
                 syncAdd.setCookie( getCookie( entry ) );
-                respEntry.add( syncAdd );
+                respEntry.addControl( syncAdd );
 
                 WriteFuture future = session.getIoSession().write( respEntry );
                 handleWriteFuture( future, entry, EventType.ADD, null );
@@ -188,13 +188,13 @@ public class SyncReplSearchListener impl
 
                 SyncStateValueControl syncDelete = new SyncStateValueControl();
                 syncDelete.setSyncStateType( SyncStateTypeEnum.DELETE );
-                syncDelete.setEntryUUID( StringTools.uuidToBytes( entry.get(
-                    SchemaConstants.ENTRY_UUID_AT ).getString() ) );
+                syncDelete.setEntryUUID( StringTools.uuidToBytes( entry.get( SchemaConstants.ENTRY_UUID_AT )
+                    .getString() ) );
                 syncDelete.setCookie( getCookie( entry ) );
-                respEntry.add( syncDelete );
+                respEntry.addControl( syncDelete );
 
                 WriteFuture future = session.getIoSession().write( respEntry );
-                
+
                 handleWriteFuture( future, entry, EventType.DELETE, null );
             }
             else
@@ -208,8 +208,8 @@ public class SyncReplSearchListener impl
             LOG.error( e.getMessage(), e );
         }
     }
-    
-    
+
+
     public void entryModified( ModifyOperationContext modifyContext )
     {
         Entry alteredEntry = modifyContext.getAlteredEntry();
@@ -220,20 +220,20 @@ public class SyncReplSearchListener impl
         {
             if ( pushInRealTime )
             {
-                
+
                 SearchResultEntry respEntry = new SearchResultEntryImpl( req.getMessageId() );
                 respEntry.setObjectName( modifyContext.getDn() );
                 respEntry.setEntry( alteredEntry );
 
                 SyncStateValueControl syncModify = new SyncStateValueControl();
                 syncModify.setSyncStateType( SyncStateTypeEnum.MODIFY );
-                syncModify.setEntryUUID( StringTools.uuidToBytes( alteredEntry.get(
-                    SchemaConstants.ENTRY_UUID_AT ).getString() ) );
+                syncModify.setEntryUUID( StringTools.uuidToBytes( alteredEntry.get( SchemaConstants.ENTRY_UUID_AT )
+                    .getString() ) );
                 syncModify.setCookie( getCookie( alteredEntry ) );
-                respEntry.add( syncModify );
+                respEntry.addControl( syncModify );
 
                 WriteFuture future = session.getIoSession().write( respEntry );
-                
+
                 // store altered entry cause that holds the updated CSN
                 handleWriteFuture( future, alteredEntry, EventType.MODIFY, null );
             }
@@ -257,12 +257,12 @@ public class SyncReplSearchListener impl
 
         try
         {
-            if( ! moveContext.getNewSuperior().isChildOf( clientMsgLog.getSearchCriteria().getBase() ) )
+            if ( !moveContext.getNewSuperior().isChildOf( clientMsgLog.getSearchCriteria().getBase() ) )
             {
                 sendDeletedEntry( moveContext.getEntry() );
                 return;
             }
-            
+
             SyncModifyDnControl modDnControl = new SyncModifyDnControl( SyncModifyDnType.MOVE );
             modDnControl.setEntryDn( moveContext.getDn().getNormName() );
             modDnControl.setNewSuperiorDn( moveContext.getNewSuperior().getNormName() );
@@ -275,14 +275,14 @@ public class SyncReplSearchListener impl
 
                 SyncStateValueControl syncModify = new SyncStateValueControl();
                 syncModify.setSyncStateType( SyncStateTypeEnum.MODDN );
-                syncModify.setEntryUUID( StringTools.uuidToBytes( entry.get(
-                    SchemaConstants.ENTRY_UUID_AT ).getString() ) );
+                syncModify.setEntryUUID( StringTools.uuidToBytes( entry.get( SchemaConstants.ENTRY_UUID_AT )
+                    .getString() ) );
                 syncModify.setCookie( getCookie( entry ) );
-                respEntry.add( syncModify );
-                respEntry.add( modDnControl );
-                
+                respEntry.addControl( syncModify );
+                respEntry.addControl( modDnControl );
+
                 WriteFuture future = session.getIoSession().write( respEntry );
-                
+
                 handleWriteFuture( future, entry, null, modDnControl );
             }
             else
@@ -299,12 +299,12 @@ public class SyncReplSearchListener impl
 
     public void entryMovedAndRenamed( MoveAndRenameOperationContext moveAndRenameContext )
     {
-        
+
         LOG.debug( "sending moveAndRenamed entry {}", moveAndRenameContext.getDn() );
 
         try
         {
-            if( ! moveAndRenameContext.getNewSuperiorDn().isChildOf( clientMsgLog.getSearchCriteria().getBase() ) )
+            if ( !moveAndRenameContext.getNewSuperiorDn().isChildOf( clientMsgLog.getSearchCriteria().getBase() ) )
             {
                 sendDeletedEntry( moveAndRenameContext.getEntry() );
                 return;
@@ -319,21 +319,21 @@ public class SyncReplSearchListener impl
             if ( pushInRealTime )
             {
                 Entry alteredEntry = moveAndRenameContext.getModifiedEntry();
-                
+
                 SearchResultEntry respEntry = new SearchResultEntryImpl( req.getMessageId() );
                 respEntry.setObjectName( moveAndRenameContext.getModifiedEntry().getDn() );
                 respEntry.setEntry( alteredEntry );
 
                 SyncStateValueControl syncModify = new SyncStateValueControl();
                 syncModify.setSyncStateType( SyncStateTypeEnum.MODDN );
-                syncModify.setEntryUUID( StringTools.uuidToBytes( alteredEntry.get(
-                    SchemaConstants.ENTRY_UUID_AT ).getString() ) );
+                syncModify.setEntryUUID( StringTools.uuidToBytes( alteredEntry.get( SchemaConstants.ENTRY_UUID_AT )
+                    .getString() ) );
                 syncModify.setCookie( getCookie( alteredEntry ) );
-                respEntry.add( syncModify );
-                respEntry.add( modDnControl );
+                respEntry.addControl( syncModify );
+                respEntry.addControl( modDnControl );
 
                 WriteFuture future = session.getIoSession().write( respEntry );
-                
+
                 handleWriteFuture( future, alteredEntry, null, modDnControl );
             }
             else
@@ -351,9 +351,9 @@ public class SyncReplSearchListener impl
     public void entryRenamed( RenameOperationContext renameContext )
     {
         Entry entry = renameContext.getEntry();
-        
+
         LOG.debug( "sending renamed entry {}", entry.getDn() );
-        
+
         try
         {
             SyncModifyDnControl modDnControl = new SyncModifyDnControl();
@@ -370,14 +370,14 @@ public class SyncReplSearchListener impl
 
                 SyncStateValueControl syncModify = new SyncStateValueControl();
                 syncModify.setSyncStateType( SyncStateTypeEnum.MODDN );
-                syncModify.setEntryUUID( StringTools.uuidToBytes( entry.get(
-                    SchemaConstants.ENTRY_UUID_AT ).getString() ) );
+                syncModify.setEntryUUID( StringTools.uuidToBytes( entry.get( SchemaConstants.ENTRY_UUID_AT )
+                    .getString() ) );
                 syncModify.setCookie( getCookie( renameContext.getModifiedEntry() ) );
-                respEntry.add( syncModify );
-                respEntry.add( modDnControl );
-                
+                respEntry.addControl( syncModify );
+                respEntry.addControl( modDnControl );
+
                 WriteFuture future = session.getIoSession().write( respEntry );
-                
+
                 handleWriteFuture( future, renameContext.getModifiedEntry(), null, modDnControl );
             }
             else
@@ -390,8 +390,8 @@ public class SyncReplSearchListener impl
             LOG.error( e.getMessage(), e );
         }
     }
-    
-    
+
+
     public boolean isPushInRealTime()
     {
         return pushInRealTime;
@@ -409,21 +409,21 @@ public class SyncReplSearchListener impl
         String csn = entry.get( SchemaConstants.ENTRY_CSN_AT ).getString();
         return StringTools.getBytesUtf8( clientMsgLog.getId() + SyncReplProvider.REPLICA_ID_DELIM + csn );
     }
-    
-    
+
+
     private void handleWriteFuture( WriteFuture future, Entry entry, EventType event, SyncModifyDnControl modDnControl )
     {
         future.awaitUninterruptibly();
-        if( !future.isWritten() )
+        if ( !future.isWritten() )
         {
             LOG.error( "Failed to write to the consumer {}", clientMsgLog.getId() );
             LOG.error( "", future.getException() );
-            
+
             // set realtime push to false, will be set back to true when the client
             // comes back and sends another request this flag will be set to true
             pushInRealTime = false;
-            
-            if( modDnControl != null )
+
+            if ( modDnControl != null )
             {
                 clientMsgLog.log( new ReplicaEventMessage( modDnControl, entry ) );
             }

Modified: directory/apacheds/branches/apacheds-codec-merge/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-codec-merge/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java?rev=985686&r1=985685&r2=985686&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-codec-merge/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java (original)
+++ directory/apacheds/branches/apacheds-codec-merge/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java Sun Aug 15 14:54:56 2010
@@ -55,14 +55,12 @@ import org.apache.directory.server.ldap.
 import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmMechanismHandler;
 import org.apache.directory.server.ldap.handlers.bind.plain.PlainMechanismHandler;
 import org.apache.directory.server.ldap.handlers.extended.StoredProcedureExtendedOperationHandler;
-import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
-import org.apache.directory.shared.ldap.codec.LdapTransformer;
 import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
 import org.apache.directory.shared.ldap.message.BindRequestImpl;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
 import org.apache.directory.shared.ldap.message.MessageDecoder;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.internal.BindResponse;
-import org.apache.directory.shared.ldap.message.internal.InternalMessage;
 import org.apache.directory.shared.ldap.message.spi.BinaryAttributeDetector;
 import org.apache.directory.shared.ldap.name.DN;
 import org.junit.Test;
@@ -484,8 +482,9 @@ public class SaslBindIT extends Abstract
             } );
 
             // Send encoded request to server
-            LdapMessageCodec ldapRequest = ( LdapMessageCodec ) LdapTransformer.transform( ( InternalMessage ) request );
-            ByteBuffer bb = ldapRequest.encode();
+            LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+            ByteBuffer bb = encoder.encodeMessage( request );
+
             bb.flip();
 
             _output_.write( bb.array() );
@@ -526,8 +525,8 @@ public class SaslBindIT extends Abstract
             } );
 
             // Send encoded request to server
-            LdapMessageCodec ldapRequest = ( LdapMessageCodec ) LdapTransformer.transform( ( InternalMessage ) request );
-            ByteBuffer bb = ldapRequest.encode();
+            LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+            ByteBuffer bb = encoder.encodeMessage( request );
             bb.flip();
 
             _output_.write( bb.array() );

Modified: directory/apacheds/branches/apacheds-codec-merge/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-codec-merge/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java?rev=985686&r1=985685&r2=985686&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-codec-merge/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java (original)
+++ directory/apacheds/branches/apacheds-codec-merge/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java Sun Aug 15 14:54:56 2010
@@ -43,10 +43,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.LdapResponseCodec;
 import org.apache.directory.shared.ldap.codec.LdapResultCodec;
 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.bind.LdapAuthentication;
-import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
-import org.apache.directory.shared.ldap.codec.del.DelRequestCodec;
 import org.apache.directory.shared.ldap.codec.modify.ModifyRequestCodec;
 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequestCodec;
 import org.apache.directory.shared.ldap.entry.Entry;
@@ -58,11 +54,15 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.ldif.ChangeType;
 import org.apache.directory.shared.ldap.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.ldif.LdifReader;
+import org.apache.directory.shared.ldap.message.BindRequestImpl;
+import org.apache.directory.shared.ldap.message.DeleteRequestImpl;
 import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.UnbindRequestImpl;
 import org.apache.directory.shared.ldap.message.internal.BindResponse;
 import org.apache.directory.shared.ldap.message.internal.ExtendedResponse;
+import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
 import org.apache.directory.shared.ldap.message.internal.InternalUnbindRequest;
 import org.apache.directory.shared.ldap.name.DN;
@@ -292,7 +292,8 @@ public class ImportCommand extends ToolC
     private int deleteEntry( LdifEntry entry, int messageId ) throws IOException, DecoderException,
         LdapInvalidDnException, EncoderException
     {
-        DelRequestCodec delRequest = new DelRequestCodec();
+        LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+        InternalDeleteRequest delRequest = new DeleteRequestImpl( messageId );
 
         String dn = entry.getDn().getName();
 
@@ -301,12 +302,10 @@ public class ImportCommand extends ToolC
             System.out.println( "Deleting entry " + dn );
         }
 
-        delRequest.setEntry( new DN( dn ) );
-
-        delRequest.setMessageId( messageId );
+        delRequest.setName( new DN( dn ) );
 
         // Encode and send the delete request
-        ByteBuffer bb = delRequest.encode();
+        ByteBuffer bb = encoder.encodeMessage( delRequest );
         bb.flip();
 
         sendMessage( bb );
@@ -503,23 +502,20 @@ public class ImportCommand extends ToolC
      */
     private void bind( int messageId ) throws LdapInvalidDnException, EncoderException, DecoderException, IOException
     {
-        BindRequestCodec bindRequest = new BindRequestCodec();
-        LdapAuthentication authentication = null;
+        InternalBindRequest bindRequest = new BindRequestImpl( messageId );
 
         if ( "simple".equals( auth ) )
         {
-            authentication = new SimpleAuthentication();
-            ( ( SimpleAuthentication ) authentication ).setSimple( StringTools.getBytesUtf8( password ) );
+            bindRequest.setCredentials( StringTools.getBytesUtf8( password ) );
+            bindRequest.setSimple( true );
         }
 
-        bindRequest.setAuthentication( authentication );
         bindRequest.setName( new DN( user ) );
-        bindRequest.setVersion( 3 );
-
-        bindRequest.setMessageId( messageId );
 
         // Encode and send the bind request
-        ByteBuffer bb = bindRequest.encode();
+        LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+        ByteBuffer bb = encoder.encodeMessage( bindRequest );
         bb.flip();
 
         connect();

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=985686&r1=985685&r2=985686&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 Sun Aug 15 14:54:56 2010
@@ -12,7 +12,6 @@ import org.apache.directory.ldap.client.
 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.AddRequest;
-import org.apache.directory.ldap.client.api.message.BindRequest;
 import org.apache.directory.ldap.client.api.message.CompareRequest;
 import org.apache.directory.ldap.client.api.message.DeleteRequest;
 import org.apache.directory.ldap.client.api.message.ExtendedRequest;
@@ -22,6 +21,7 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
 import org.apache.directory.shared.ldap.name.DN;
 
 
@@ -84,7 +84,7 @@ public interface LdapAsyncConnection ext
      * @param bindRequest The BindRequest to send
      * @return BindFuture A future
      */
-    BindFuture bindAsync( BindRequest bindRequest ) throws LdapException, IOException;
+    BindFuture bindAsync( InternalBindRequest bindRequest ) throws LdapException, IOException;
 
 
     /**
@@ -177,7 +177,7 @@ public interface LdapAsyncConnection ext
      */
     ExtendedFuture extendedAsync( ExtendedRequest extendedRequest ) throws LdapException;
 
-    
+
     /**
      * configuration of LdapNetworkConnection
      * 

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=985686&r1=985685&r2=985686&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 Sun Aug 15 14:54:56 2010
@@ -6,7 +6,6 @@ import java.util.List;
 
 import org.apache.directory.ldap.client.api.message.AbandonRequest;
 import org.apache.directory.ldap.client.api.message.AddRequest;
-import org.apache.directory.ldap.client.api.message.BindRequest;
 import org.apache.directory.ldap.client.api.message.CompareRequest;
 import org.apache.directory.ldap.client.api.message.DeleteRequest;
 import org.apache.directory.ldap.client.api.message.ExtendedRequest;
@@ -26,6 +25,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.CompareResponse;
 import org.apache.directory.shared.ldap.message.internal.DeleteResponse;
 import org.apache.directory.shared.ldap.message.internal.ExtendedResponse;
+import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
 import org.apache.directory.shared.ldap.message.internal.ModifyDnResponse;
 import org.apache.directory.shared.ldap.message.internal.ModifyResponse;
 import org.apache.directory.shared.ldap.message.internal.Response;
@@ -154,7 +154,7 @@ public interface LdapConnection
      * parameters
      * @return A LdapResponse containing the result
      */
-    public abstract BindResponse bind( BindRequest bindRequest ) throws LdapException, IOException;
+    public abstract BindResponse bind( InternalBindRequest bindRequest ) throws LdapException, IOException;
 
 
     /**
@@ -195,8 +195,8 @@ public interface LdapConnection
      * @param scope The sarch scope : OBJECT, ONELEVEL or SUBTREE
      * @return A cursor on the result.
      */
-    public abstract Cursor<Response> search( String baseDn, String filter, SearchScope scope,
-        String... attributes ) throws LdapException;
+    public abstract Cursor<Response> search( String baseDn, String filter, SearchScope scope, String... attributes )
+        throws LdapException;
 
 
     /**
@@ -291,8 +291,7 @@ public interface LdapConnection
     /**
      * @see #rename(DN, RDN, boolean)
      */
-    public abstract ModifyDnResponse rename( String entryDn, String newRdn, boolean deleteOldRdn )
-        throws LdapException;
+    public abstract ModifyDnResponse rename( String entryDn, String newRdn, boolean deleteOldRdn ) throws LdapException;
 
 
     /**
@@ -306,8 +305,7 @@ public interface LdapConnection
      * @return modifyDn operations response
      * @throws LdapException
      */
-    public abstract ModifyDnResponse rename( DN entryDn, RDN newRdn, boolean deleteOldRdn )
-        throws LdapException;
+    public abstract ModifyDnResponse rename( DN entryDn, RDN newRdn, boolean deleteOldRdn ) throws LdapException;
 
 
     /**
@@ -350,8 +348,7 @@ public interface LdapConnection
      * @param newDn The new Entry DN
      * @param deleteOldRdn Tells if the old RDN must be removed
      */
-    public abstract ModifyDnResponse moveAndRename( DN entryDn, DN newDn, boolean deleteOldRdn )
-        throws LdapException;
+    public abstract ModifyDnResponse moveAndRename( DN entryDn, DN newDn, boolean deleteOldRdn ) throws LdapException;
 
 
     /**
@@ -414,8 +411,7 @@ public interface LdapConnection
      * @return compare operation's response
      * @throws LdapException
      */
-    public abstract CompareResponse compare( String dn, String attributeName, String value )
-        throws LdapException;
+    public abstract CompareResponse compare( String dn, String attributeName, String value ) throws LdapException;
 
 
     /**
@@ -428,8 +424,7 @@ public interface LdapConnection
      * @return compare operation's response
      * @throws LdapException
      */
-    public abstract CompareResponse compare( String dn, String attributeName, byte[] value )
-        throws LdapException;
+    public abstract CompareResponse compare( String dn, String attributeName, byte[] value ) throws LdapException;
 
 
     /**
@@ -442,8 +437,7 @@ public interface LdapConnection
      * @return compare operation's response
      * @throws LdapException
      */
-    public abstract CompareResponse compare( String dn, String attributeName, Value<?> value )
-        throws LdapException;
+    public abstract CompareResponse compare( String dn, String attributeName, Value<?> value ) 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=985686&r1=985685&r2=985686&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 Sun Aug 15 14:54:56 2010
@@ -53,7 +53,6 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.ldap.client.api.listener.DeleteListener;
 import org.apache.directory.ldap.client.api.message.AbandonRequest;
 import org.apache.directory.ldap.client.api.message.AddRequest;
-import org.apache.directory.ldap.client.api.message.BindRequest;
 import org.apache.directory.ldap.client.api.message.CompareRequest;
 import org.apache.directory.ldap.client.api.message.DeleteRequest;
 import org.apache.directory.ldap.client.api.message.ExtendedRequest;
@@ -69,13 +68,8 @@ 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.add.AddRequestCodec;
-import org.apache.directory.shared.ldap.codec.bind.BindRequestCodec;
-import org.apache.directory.shared.ldap.codec.bind.LdapAuthentication;
-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.controls.ControlImpl;
-import org.apache.directory.shared.ldap.codec.del.DelRequestCodec;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec;
 import org.apache.directory.shared.ldap.codec.modify.ModifyRequestCodec;
 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequestCodec;
@@ -96,6 +90,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.message.AbandonRequestImpl;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.message.BindRequestImpl;
+import org.apache.directory.shared.ldap.message.DeleteRequestImpl;
 import org.apache.directory.shared.ldap.message.IntermediateResponseImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.UnbindRequestImpl;
@@ -106,6 +102,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.DeleteResponse;
 import org.apache.directory.shared.ldap.message.internal.ExtendedResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
+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;
 import org.apache.directory.shared.ldap.message.internal.InternalUnbindRequest;
@@ -335,7 +333,7 @@ public class LdapNetworkConnection exten
 
                 ctrl.setValue( control.getValue() );
 
-                message.add( ctrl );
+                message.addControl( ctrl );
             }
         }
     }
@@ -807,9 +805,7 @@ public class LdapNetworkConnection exten
         LOG.debug( "Anonymous Bind request" );
 
         // Create the BindRequest
-        BindRequest bindRequest = new BindRequest();
-        bindRequest.setName( StringTools.EMPTY );
-        bindRequest.setCredentials( StringTools.EMPTY_BYTES );
+        InternalBindRequest bindRequest = createBindRequest( StringTools.EMPTY, StringTools.EMPTY_BYTES );
 
         return bind( bindRequest );
     }
@@ -823,9 +819,7 @@ public class LdapNetworkConnection exten
         LOG.debug( "Anonymous Bind request" );
 
         // Create the BindRequest
-        BindRequest bindRequest = new BindRequest();
-        bindRequest.setName( StringTools.EMPTY );
-        bindRequest.setCredentials( StringTools.EMPTY_BYTES );
+        InternalBindRequest bindRequest = createBindRequest( StringTools.EMPTY, StringTools.EMPTY_BYTES );
 
         return bindAsync( bindRequest );
     }
@@ -839,9 +833,7 @@ public class LdapNetworkConnection exten
         LOG.debug( "Bind request : {}", name );
 
         // Create the BindRequest
-        BindRequest bindRequest = new BindRequest();
-        bindRequest.setName( name );
-        bindRequest.setCredentials( StringTools.getBytesUtf8( credentials ) );
+        InternalBindRequest bindRequest = createBindRequest( name, StringTools.getBytesUtf8( credentials ) );
 
         return bind( bindRequest );
     }
@@ -855,9 +847,7 @@ public class LdapNetworkConnection exten
         LOG.debug( "Bind request : {}", name );
 
         // Create the BindRequest
-        BindRequest bindRequest = new BindRequest();
-        bindRequest.setName( name );
-        bindRequest.setCredentials( StringTools.getBytesUtf8( credentials ) );
+        InternalBindRequest bindRequest = createBindRequest( name, StringTools.getBytesUtf8( credentials ) );
 
         return bindAsync( bindRequest );
     }
@@ -871,17 +861,8 @@ public class LdapNetworkConnection exten
         LOG.debug( "Bind request : {}", name );
 
         // Create the BindRequest
-        BindRequest bindRequest = new BindRequest();
-        bindRequest.setCredentials( StringTools.getBytesUtf8( credentials ) );
-
-        if ( name == null )
-        {
-            bindRequest.setName( StringTools.EMPTY );
-        }
-        else
-        {
-            bindRequest.setName( name.getName() );
-        }
+        InternalBindRequest bindRequest = createBindRequest( name, StringTools.getBytesUtf8( credentials ), null,
+            ( Control ) null );
 
         return bind( bindRequest );
     }
@@ -895,17 +876,7 @@ public class LdapNetworkConnection exten
         LOG.debug( "Bind request : {}", name );
 
         // Create the BindRequest
-        BindRequest bindRequest = new BindRequest();
-        bindRequest.setCredentials( StringTools.getBytesUtf8( credentials ) );
-
-        if ( name == null )
-        {
-            bindRequest.setName( StringTools.EMPTY );
-        }
-        else
-        {
-            bindRequest.setName( name.getName() );
-        }
+        InternalBindRequest bindRequest = createBindRequest( name, StringTools.getBytesUtf8( credentials ) );
 
         return bindAsync( bindRequest );
     }
@@ -914,7 +885,7 @@ public class LdapNetworkConnection exten
     /**
      * {@inheritDoc}
      */
-    public BindResponse bind( BindRequest bindRequest ) throws LdapException, IOException
+    public BindResponse bind( InternalBindRequest bindRequest ) throws LdapException, IOException
     {
         BindFuture bindFuture = bindAsync( bindRequest );
 
@@ -922,10 +893,8 @@ public class LdapNetworkConnection exten
         try
         {
             // Read the response, waiting for it if not available immediately
-            long timeout = getTimeout( bindRequest.getTimeout() );
-
             // Get the response, blocking
-            BindResponse bindResponse = bindFuture.get( timeout, TimeUnit.MILLISECONDS );
+            BindResponse bindResponse = bindFuture.get( timeOut, TimeUnit.MILLISECONDS );
 
             if ( bindResponse == null )
             {
@@ -1064,71 +1033,133 @@ public class LdapNetworkConnection exten
 
 
     /**
-     * Create a BindRequest ready to be sent.
+     * Create a Simple BindRequest ready to be sent.
      */
-    private BindRequestCodec createBindMessage( BindRequest bindRequest ) throws LdapException
+    private InternalBindRequest createBindRequest( String name, byte[] credentials ) throws LdapException
     {
-        // Create a new codec BindRequest object
-        BindRequestCodec bindRequestCodec = new BindRequestCodec();
+        return createBindRequest( name, credentials, null, ( Control[] ) null );
+    }
 
-        // clear the mappings if any (in case of a second call to bind() without calling unBind())
-        //clearMaps();
 
-        // Set the new messageId
-        int newId = messageId.incrementAndGet();
-        bindRequest.setMessageId( newId );
-        bindRequestCodec.setMessageId( newId );
+    /**
+     * Create a Simple BindRequest ready to be sent.
+     */
+    private InternalBindRequest createBindRequest( DN name, byte[] credentials ) throws LdapException
+    {
+        return createBindRequest( name, credentials, null, ( Control[] ) null );
+    }
+
+
+    /**
+     * Create a Simple BindRequest with controls ready to be sent.
+     */
+    private InternalBindRequest createBindRequest( String name, byte[] credentials, Control[] controls )
+        throws LdapException
+    {
+        return createBindRequest( name, credentials, null, controls );
+    }
+
+
+    /**
+     * Create a Simple BindRequest with controls ready to be sent.
+     */
+    private InternalBindRequest createBindRequest( DN name, byte[] credentials, Control[] controls )
+        throws LdapException
+    {
+        return createBindRequest( name, credentials, null, controls );
+    }
 
-        // Set the version
-        bindRequestCodec.setVersion( LdapConnectionConfig.LDAP_V3 );
 
+    /**
+     * Create a SASL BindRequest ready to be sent.
+     */
+    private InternalBindRequest createBindRequest( String name, byte[] credentials, String mechanism )
+        throws LdapException
+    {
+        return createBindRequest( name, credentials, mechanism, ( Control[] ) null );
+    }
+
+
+    /**
+     * Create a SASL BindRequest ready to be sent.
+     */
+    private InternalBindRequest createBindRequest( DN name, byte[] credentials, String mechanism ) throws LdapException
+    {
+        return createBindRequest( name, credentials, mechanism, ( Control ) null );
+    }
+
+
+    /**
+     * Create a complete BindRequest ready to be sent.
+     */
+    private InternalBindRequest createBindRequest( String name, byte[] credentials, String saslMechanism,
+        Control... controls ) throws LdapException
+    {
         // Set the name
         try
         {
-            DN dn = new DN( bindRequest.getName() );
-            bindRequestCodec.setName( dn );
+            DN dn = new DN( name );
+            return createBindRequest( dn, credentials, saslMechanism, controls );
         }
         catch ( LdapInvalidDnException ine )
         {
-            String msg = "The given dn '" + bindRequest.getName() + "' is not valid";
+            String msg = "The given dn '" + name + "' is not valid";
             LOG.error( msg );
             LdapException ldapException = new LdapException( msg );
             ldapException.initCause( ine );
 
             throw ldapException;
         }
+    }
 
-        // Set the credentials
-        LdapAuthentication authentication = null;
 
-        if ( bindRequest.isSimple() )
+    /**
+     * Create a complete BindRequest ready to be sent.
+     */
+    private InternalBindRequest createBindRequest( DN name, byte[] credentials, String saslMechanism,
+        Control... controls ) throws LdapException
+    {
+        // clear the mappings if any (in case of a second call to bind() without calling unBind())
+        //clearMaps();
+
+        // Set the new messageId
+        InternalBindRequest bindRequest = new BindRequestImpl();
+
+        // Set the version
+        bindRequest.setVersion3( true );
+
+        // Set the name
+        bindRequest.setName( name );
+
+        // Set the credentials
+        if ( StringTools.isEmpty( saslMechanism ) )
         {
             // Simple bind
-            authentication = new SimpleAuthentication();
-            ( ( SimpleAuthentication ) authentication ).setSimple( bindRequest.getCredentials() );
+            bindRequest.setSimple( true );
+            bindRequest.setCredentials( credentials );
         }
         else
         {
             // SASL bind
-            authentication = new SaslCredentials();
-            ( ( SaslCredentials ) authentication ).setCredentials( bindRequest.getCredentials() );
-            ( ( SaslCredentials ) authentication ).setMechanism( bindRequest.getSaslMechanism() );
+            bindRequest.setSimple( false );
+            bindRequest.setCredentials( credentials );
+            bindRequest.setSaslMechanism( saslMechanism );
         }
 
-        // The authentication
-        bindRequestCodec.setAuthentication( authentication );
-
         // Add the controls
-        setControls( bindRequest.getControls(), bindRequestCodec );
+        if ( ( controls != null ) && ( controls.length != 0 ) )
+        {
+            bindRequest.addAllControls( controls );
+        }
 
-        return bindRequestCodec;
+        return bindRequest;
     }
 
 
     /**
      * {@inheritDoc}
      */
-    public BindFuture bindAsync( BindRequest bindRequest ) throws LdapException, IOException
+    public BindFuture bindAsync( InternalBindRequest bindRequest ) throws LdapException, IOException
     {
         // First switch to anonymous state
         authenticated.set( false );
@@ -1139,13 +1170,12 @@ public class LdapNetworkConnection exten
         // If the session has not been establish, or is closed, we get out immediately
         checkSession();
 
-        // Create the new message and update the messageId
-        LdapMessageCodec bindMessage = createBindMessage( bindRequest );
-
-        int newId = bindMessage.getMessageId();
+        // Update the messageId
+        int newId = messageId.incrementAndGet();
+        bindRequest.setMessageId( newId );
 
         LOG.debug( "-----------------------------------------------------------------" );
-        LOG.debug( "Sending request \n{}", bindMessage );
+        LOG.debug( "Sending request \n{}", bindRequest );
 
         // Create a future for this Bind operation
         BindFuture bindFuture = new BindFuture( this, newId );
@@ -1153,7 +1183,7 @@ public class LdapNetworkConnection exten
         addToFutureMap( newId, bindFuture );
 
         // Send the request to the server
-        WriteFuture writeFuture = ldapSession.write( bindMessage );
+        WriteFuture writeFuture = ldapSession.write( bindRequest );
 
         // Wait for the message to be sent to the server
         if ( !writeFuture.awaitUninterruptibly( getTimeout( 0 ) ) )
@@ -2428,21 +2458,20 @@ public class LdapNetworkConnection exten
     {
         checkSession();
 
-        DelRequestCodec delReqCodec = new DelRequestCodec();
-
         int newId = messageId.incrementAndGet();
 
+        InternalDeleteRequest internalDelRequest = new DeleteRequestImpl( newId );
+
         delRequest.setMessageId( newId );
-        delReqCodec.setMessageId( newId );
 
-        delReqCodec.setEntry( delRequest.getTargetDn() );
-        setControls( delRequest.getControls(), delReqCodec );
+        internalDelRequest.setName( delRequest.getTargetDn() );
+        setControls( delRequest.getControls(), internalDelRequest );
 
         DeleteFuture deleteFuture = new DeleteFuture( this, newId );
         addToFutureMap( newId, deleteFuture );
 
         // Send the request to the server
-        WriteFuture writeFuture = ldapSession.write( delReqCodec );
+        WriteFuture writeFuture = ldapSession.write( internalDelRequest );
 
         // Wait for the message to be sent to the server
         if ( !writeFuture.awaitUninterruptibly( getTimeout( 0 ) ) )
@@ -3050,7 +3079,7 @@ public class LdapNetworkConnection exten
                 control.setValue( cc.getValue() );
                 control.setCritical( cc.isCritical() );
 
-                message.add( control );
+                message.addControl( control );
             }
         }
     }

Modified: directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolCodecFactory.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/protocol/LdapProtocolCodecFactory.java?rev=985686&r1=985685&r2=985686&view=diff
==============================================================================
--- directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolCodecFactory.java (original)
+++ directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolCodecFactory.java Sun Aug 15 14:54:56 2010
@@ -20,6 +20,7 @@
 package org.apache.directory.ldap.client.api.protocol;
 
 
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
 import org.apache.mina.filter.codec.ProtocolDecoder;