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/02/01 16:04:20 UTC

svn commit: r905297 [4/7] - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/event/ apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/ apacheds/trunk/core-api/src/main/java/o...

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java Mon Feb  1 15:04:10 2010
@@ -22,11 +22,11 @@
 
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.AbstractAsn1Object;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.controls.AbstractControlCodec;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 
@@ -37,8 +37,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class SyncDoneValueControlCodec extends AbstractAsn1Object
+public class SyncDoneValueControlCodec extends AbstractControlCodec
 {
+    /** This control OID */
+    public static final String CONTROL_OID = "1.3.6.1.4.1.4203.1.9.1.3";
+
     /** The Sync cookie */
     private byte[] cookie;
 
@@ -48,6 +51,16 @@
     /** The global length for this control */
     private int syncDoneValueLength;
 
+    /**
+     * Creates a new instance of SyncDoneValueControlCodec.
+     */
+    public SyncDoneValueControlCodec()
+    {
+        super( CONTROL_OID );
+
+        decoder = new SyncDoneValueControlDecoder();
+    }
+    
 
     /**
      * Compute the syncDoneValue length.
@@ -66,9 +79,15 @@
         }
 
         // the refreshDeletes flag length
-        syncDoneValueLength += 1 + 1 + 1;
+        if ( refreshDeletes )
+        {
+            syncDoneValueLength += 1 + 1 + 1;
+        }
+
+        valueLength = 1 + TLV.getNbBytes( syncDoneValueLength ) + syncDoneValueLength;
 
-        return 1 + TLV.getNbBytes( syncDoneValueLength ) + syncDoneValueLength;
+        // Call the super class to compute the global control length
+        return super.computeLength( valueLength );
     }
 
 
@@ -82,18 +101,71 @@
     @Override
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
     {
-        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
-        bb.put( UniversalTag.SEQUENCE_TAG );
-        bb.put( TLV.getBytes( syncDoneValueLength ) );
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        // Encode the Control envelop
+        super.encode( buffer );
+
+        // Encode the OCTET_STRING tag
+        buffer.put( UniversalTag.OCTET_STRING_TAG );
+        buffer.put( TLV.getBytes( valueLength ) );
+
+        // Encode the SEQ 
+        buffer.put( UniversalTag.SEQUENCE_TAG );
+        buffer.put( TLV.getBytes( syncDoneValueLength ) );
 
         if ( cookie != null )
         {
-            Value.encode( bb, cookie );
+            Value.encode( buffer, cookie );
         }
 
-        Value.encode( bb, refreshDeletes );
+        if ( refreshDeletes )
+        {  
+            Value.encode( buffer, refreshDeletes );
+        }
 
-        return bb;
+        return buffer;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public byte[] getValue()
+    {
+        if ( value == null )
+        {
+            try
+            { 
+                computeLength();
+                ByteBuffer buffer = ByteBuffer.allocate( valueLength );
+                
+                // Encode the SEQ 
+                buffer.put( UniversalTag.SEQUENCE_TAG );
+                buffer.put( TLV.getBytes( syncDoneValueLength ) );
+
+                if ( cookie != null )
+                {
+                    Value.encode( buffer, cookie );
+                }
+
+                if ( refreshDeletes )
+                {  
+                    Value.encode( buffer, refreshDeletes );
+                }
+                
+                value = buffer.array();
+            }
+            catch ( Exception e )
+            {
+                return null;
+            }
+        }
+        
+        return value;
     }
 
 
@@ -111,7 +183,16 @@
      */
     public void setCookie( byte[] cookie )
     {
-        this.cookie = cookie;
+        // Copy the bytes
+        if ( cookie != null )
+        {
+            this.cookie = new byte[cookie.length];
+            System.arraycopy( cookie, 0, this.cookie, 0, cookie.length );
+        }
+        else
+        {
+            this.cookie = null;
+        }
     }
 
 
@@ -141,6 +222,8 @@
         StringBuilder sb = new StringBuilder();
 
         sb.append( "    SyncDoneValue control :\n" );
+        sb.append( "        oid : " ).append( getOid() ).append( '\n' );
+        sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
         sb.append( "        cookie            : '" ).append( StringTools.dumpBytes( cookie ) ).append( "'\n" );
         sb.append( "        refreshDeletes : '" ).append( refreshDeletes ).append( "'\n" );
 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlDecoder.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlDecoder.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlDecoder.java Mon Feb  1 15:04:10 2010
@@ -27,8 +27,8 @@
 import org.apache.directory.shared.asn1.Asn1Object;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.ldap.codec.ControlDecoder;
-import org.apache.directory.shared.ldap.message.control.replication.SyncDoneValueControl;
+import org.apache.directory.shared.ldap.codec.controls.CodecControl;
+import org.apache.directory.shared.ldap.codec.controls.ControlDecoder;
 
 
 /**
@@ -55,21 +55,13 @@
      * @throws DecoderException If the decoding found an error
      * @throws NamingException It will never be throw by this method
      */
-    public Asn1Object decode( byte[] controlBytes ) throws DecoderException
+    public Asn1Object decode( byte[] controlBytes, CodecControl control ) throws DecoderException
     {
         ByteBuffer bb = ByteBuffer.wrap( controlBytes );
         SyncDoneValueControlContainer container = new SyncDoneValueControlContainer();
+        container.setSyncDoneValueControl( (SyncDoneValueControlCodec)control );
+
         decoder.decode( bb, container );
         return container.getSyncDoneValueControl();
     }
-
-
-    /**
-     * @return the syncDoneValueControl's OID
-     */
-    public String getControlType()
-    {
-        return SyncDoneValueControl.CONTROL_OID;
-    }
-
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java Mon Feb  1 15:04:10 2010
@@ -86,17 +86,16 @@
          */
         super.transitions[IStates.INIT_GRAMMAR_STATE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
             IStates.INIT_GRAMMAR_STATE, SyncDoneValueControlStatesEnum.SYNC_DONE_VALUE_SEQUENCE_STATE, UniversalTag.SEQUENCE_TAG,
-            new GrammarAction( "Init SyncDoneValueControl" )
+            new GrammarAction( "Initiaization" )
             {
                 public void action( IAsn1Container container ) throws DecoderException
                 {
                     SyncDoneValueControlContainer syncDoneValueContainer = ( SyncDoneValueControlContainer ) container;
-                    SyncDoneValueControlCodec control = new SyncDoneValueControlCodec();
-                    syncDoneValueContainer.setSyncDoneValueControl( control );
-                    
+
+                    // As all the values are optional or defaulted, we can end here
                     syncDoneValueContainer.grammarEndAllowed( true );
                 }
-            } );
+            }  );
 
         /**
          * transition from start to cookie

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlCodec.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlCodec.java Mon Feb  1 15:04:10 2010
@@ -23,11 +23,11 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.directory.shared.asn1.AbstractAsn1Object;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.controls.AbstractControlCodec;
 import org.apache.directory.shared.ldap.message.control.replication.SynchronizationInfoEnum;
 import org.apache.directory.shared.ldap.util.StringTools;
 
@@ -37,8 +37,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev:$, $Date: 
  */
-public class SyncInfoValueControlCodec extends AbstractAsn1Object
+public class SyncInfoValueControlCodec extends AbstractControlCodec
 {
+    /** This control OID */
+    public static final String CONTROL_OID = "1.3.6.1.4.1.4203.1.9.1.4";
+
     /** The kind of syncInfoValue we are dealing with */
     private SynchronizationInfoEnum type;
     
@@ -65,6 +68,9 @@
      */
     public SyncInfoValueControlCodec( SynchronizationInfoEnum type )
     {
+        super( CONTROL_OID );
+
+        decoder = new SyncInfoValueControlDecoder();
         this.type = type;
         
         // Initialize the arrayList if needed
@@ -168,6 +174,17 @@
     {
         this.syncUUIDs = syncUUIDs;
     }
+    
+    
+    /**
+     * @param syncUUIDs the syncUUIDs to set
+     */
+    public void addSyncUUID( byte[] syncUUID )
+    {
+        syncUUIDs.add( syncUUID );
+    }
+
+    
 
     
     /**
@@ -216,7 +233,10 @@
                     syncInfoValueLength = 1 + 1;
                 }
                 
-                return syncInfoValueLength;
+                valueLength = syncInfoValueLength;
+
+                // Call the super class to compute the global control length
+                return super.computeLength( valueLength );
                 
             case REFRESH_DELETE :
             case REFRESH_PRESENT :
@@ -225,9 +245,16 @@
                     syncInfoValueLength = 1 + TLV.getNbBytes( cookie.length ) + cookie.length;
                 }
                 
-                // The refreshDone flag
-                syncInfoValueLength += 1 + 1 + 1;
-                break;
+                // The refreshDone flag, only if not true, as it default to true
+                if ( !refreshDone )
+                {
+                    syncInfoValueLength += 1 + 1 + 1;
+                }
+                
+                valueLength = 1 + TLV.getNbBytes( syncInfoValueLength ) + syncInfoValueLength;
+                
+                // Call the super class to compute the global control length
+                return super.computeLength( valueLength );
                 
             case SYNC_ID_SET :
                 if ( cookie != null )
@@ -235,8 +262,11 @@
                     syncInfoValueLength = 1 + TLV.getNbBytes( cookie.length ) + cookie.length;
                 }
                 
-                // The refreshDeletes flag
-                syncInfoValueLength += 1 + 1 + 1;
+                // The refreshDeletes flag, default to false
+                if ( refreshDeletes )
+                {
+                    syncInfoValueLength += 1 + 1 + 1;
+                }
 
                 // The syncUUIDs if any
                 syncUUIDsLength = 0;
@@ -247,16 +277,15 @@
                     {
                         int uuidLength = 1 + TLV.getNbBytes( syncUUID.length ) + syncUUID.length;
                         
-                        syncUUIDsLength += 1 + TLV.getNbBytes( uuidLength ) + uuidLength;
+                        syncUUIDsLength += uuidLength;
                     }
-                    
-                    // Add the tag and compute the length
-                    syncUUIDsLength += 1 + TLV.getNbBytes( syncUUIDsLength ) + syncUUIDsLength;
                 }
                 
                 syncInfoValueLength += 1 + TLV.getNbBytes( syncUUIDsLength ) + syncUUIDsLength;
+                valueLength = 1 + TLV.getNbBytes( syncInfoValueLength ) + syncInfoValueLength;
 
-                break;
+                // Call the super class to compute the global control length
+                return super.computeLength( valueLength );
         }
         
         return 1 + TLV.getNbBytes( syncInfoValueLength ) + syncInfoValueLength;
@@ -270,97 +299,227 @@
      * @return A ByteBuffer that contains the encoded PDU
      * @throws EncoderException If anything goes wrong.
      */
-    public ByteBuffer encode( ByteBuffer bb ) throws EncoderException
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
     {
-        // Allocate the bytes buffer.
-        if ( bb == null )
+        if ( buffer == null )
         {
-            bb = ByteBuffer.allocate( computeLength() );
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
         }
+
+        // Encode the Control envelop
+        super.encode( buffer );
         
+        // Encode the OCTET_STRING tag
+        buffer.put( UniversalTag.OCTET_STRING_TAG );
+        buffer.put( TLV.getBytes( valueLength ) );
+
         switch ( type )
         {
             case NEW_COOKIE :
                 // The first case : newCookie
-                bb.put( (byte)SyncInfoValueTags.NEW_COOKIE_TAG.getValue() );
+                buffer.put( (byte)SyncInfoValueTags.NEW_COOKIE_TAG.getValue() );
 
                 // As the OCTET_STRING is absorbed by the Application tag,
                 // we have to store the L and V separately
                 if ( ( cookie == null ) || ( cookie.length == 0 ) )
                 {
-                    bb.put( ( byte ) 0 );
+                    buffer.put( ( byte ) 0 );
                 }
                 else
                 {
-                    bb.put( TLV.getBytes( cookie.length ) );
-                    bb.put( cookie );
+                    buffer.put( TLV.getBytes( cookie.length ) );
+                    buffer.put( cookie );
                 }
 
                 break;
                 
             case REFRESH_DELETE :
                 // The second case : refreshDelete
-                bb.put( (byte)SyncInfoValueTags.REFRESH_DELETE_TAG.getValue() );
-                bb.put( TLV.getBytes( syncInfoValueLength ) );
+                buffer.put( (byte)SyncInfoValueTags.REFRESH_DELETE_TAG.getValue() );
+                buffer.put( TLV.getBytes( syncInfoValueLength ) );
 
                 // The cookie, if any
                 if ( cookie != null )
                 {
-                    Value.encode( bb, cookie );
+                    Value.encode( buffer, cookie );
                 }
                 
                 // The refreshDone flag
-                Value.encode( bb, refreshDone );
+                if ( !refreshDone )
+                {
+                    Value.encode( buffer, refreshDone );
+                }
+                
                 break;
                 
             case REFRESH_PRESENT :
                 // The third case : refreshPresent
-                bb.put( (byte)SyncInfoValueTags.REFRESH_PRESENT_TAG.getValue() );
-                bb.put( TLV.getBytes( syncInfoValueLength ) );
+                buffer.put( (byte)SyncInfoValueTags.REFRESH_PRESENT_TAG.getValue() );
+                buffer.put( TLV.getBytes( syncInfoValueLength ) );
 
                 // The cookie, if any
                 if ( cookie != null )
                 {
-                    Value.encode( bb, cookie );
+                    Value.encode( buffer, cookie );
                 }
                 
                 // The refreshDone flag
-                Value.encode( bb, refreshDone );
+                if ( !refreshDone )
+                {
+                    Value.encode( buffer, refreshDone );
+                }
+
                 break;
                 
             case SYNC_ID_SET :
                 // The last case : syncIdSet
-                bb.put( (byte)SyncInfoValueTags.SYNC_ID_SET_TAG.getValue() );
-                bb.put( TLV.getBytes( syncInfoValueLength ) );
+                buffer.put( (byte)SyncInfoValueTags.SYNC_ID_SET_TAG.getValue() );
+                buffer.put( TLV.getBytes( syncInfoValueLength ) );
 
                 // The cookie, if any
                 if ( cookie != null )
                 {
-                    Value.encode( bb, cookie );
+                    Value.encode( buffer, cookie );
                 }
                 
-                // The refreshDeletes flag
-                Value.encode( bb, refreshDeletes );
+                // The refreshDeletes flag if not false
+                if ( refreshDeletes )
+                {
+                    Value.encode( buffer, refreshDeletes );
+                }
                 
                 // The syncUUIDs
-                bb.put( UniversalTag.SET_TAG );
-                bb.put( TLV.getBytes( syncUUIDsLength ) );
+                buffer.put( UniversalTag.SET_TAG );
+                buffer.put( TLV.getBytes( syncUUIDsLength ) );
                 
                 // Loop on the UUIDs if any
                 if ( syncUUIDs.size() != 0 )
                 {
                     for ( byte[] syncUUID:syncUUIDs )
                     {
-                        Value.encode( bb , syncUUID );
+                        Value.encode( buffer , syncUUID );
                     }
                 }
         }
 
-        return bb;
+        return buffer;
     }
     
     
     /**
+     * {@inheritDoc}
+     */
+    public byte[] getValue()
+    {
+        if ( value == null )
+        {
+            try
+            { 
+                computeLength();
+                ByteBuffer buffer = ByteBuffer.allocate( valueLength );
+                
+                switch ( type )
+                {
+                    case NEW_COOKIE :
+                        // The first case : newCookie
+                        buffer.put( (byte)SyncInfoValueTags.NEW_COOKIE_TAG.getValue() );
+
+                        // As the OCTET_STRING is absorbed by the Application tag,
+                        // we have to store the L and V separately
+                        if ( ( cookie == null ) || ( cookie.length == 0 ) )
+                        {
+                            buffer.put( ( byte ) 0 );
+                        }
+                        else
+                        {
+                            buffer.put( TLV.getBytes( cookie.length ) );
+                            buffer.put( cookie );
+                        }
+
+                        break;
+                        
+                    case REFRESH_DELETE :
+                        // The second case : refreshDelete
+                        buffer.put( (byte)SyncInfoValueTags.REFRESH_DELETE_TAG.getValue() );
+                        buffer.put( TLV.getBytes( syncInfoValueLength ) );
+
+                        // The cookie, if any
+                        if ( cookie != null )
+                        {
+                            Value.encode( buffer, cookie );
+                        }
+                        
+                        // The refreshDone flag
+                        if ( !refreshDone )
+                        {
+                            Value.encode( buffer, refreshDone );
+                        }
+                        
+                        break;
+                        
+                    case REFRESH_PRESENT :
+                        // The third case : refreshPresent
+                        buffer.put( (byte)SyncInfoValueTags.REFRESH_PRESENT_TAG.getValue() );
+                        buffer.put( TLV.getBytes( syncInfoValueLength ) );
+
+                        // The cookie, if any
+                        if ( cookie != null )
+                        {
+                            Value.encode( buffer, cookie );
+                        }
+                        
+                        // The refreshDone flag
+                        if ( !refreshDone )
+                        {
+                            Value.encode( buffer, refreshDone );
+                        }
+
+                        break;
+                        
+                    case SYNC_ID_SET :
+                        // The last case : syncIdSet
+                        buffer.put( (byte)SyncInfoValueTags.SYNC_ID_SET_TAG.getValue() );
+                        buffer.put( TLV.getBytes( syncInfoValueLength ) );
+
+                        // The cookie, if any
+                        if ( cookie != null )
+                        {
+                            Value.encode( buffer, cookie );
+                        }
+                        
+                        // The refreshDeletes flag if not false
+                        if ( refreshDeletes )
+                        {
+                            Value.encode( buffer, refreshDeletes );
+                        }
+                        
+                        // The syncUUIDs
+                        buffer.put( UniversalTag.SET_TAG );
+                        buffer.put( TLV.getBytes( syncUUIDsLength ) );
+                        
+                        // Loop on the UUIDs if any
+                        if ( syncUUIDs.size() != 0 )
+                        {
+                            for ( byte[] syncUUID:syncUUIDs )
+                            {
+                                Value.encode( buffer , syncUUID );
+                            }
+                        }
+                }
+                
+                value = buffer.array();
+            }
+            catch ( Exception e )
+            {
+                return null;
+            }
+        }
+        
+        return value;
+    }
+
+    
+    /**
      * @see Object#toString()
      */
     public String toString()
@@ -368,7 +527,9 @@
         StringBuilder sb = new StringBuilder();
         
         sb.append( "    SyncInfoValue control :\n" );
-        
+        sb.append( "        oid : " ).append( getOid() ).append( '\n' );
+        sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
+
         switch ( type )
         {
             case NEW_COOKIE :

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlDecoder.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlDecoder.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlDecoder.java Mon Feb  1 15:04:10 2010
@@ -22,11 +22,13 @@
 
 import java.nio.ByteBuffer;
 
+import javax.naming.NamingException;
+
 import org.apache.directory.shared.asn1.Asn1Object;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.ldap.codec.ControlDecoder;
-import org.apache.directory.shared.ldap.message.control.replication.SyncInfoValueControl;
+import org.apache.directory.shared.ldap.codec.controls.CodecControl;
+import org.apache.directory.shared.ldap.codec.controls.ControlDecoder;
 
 
 /**
@@ -41,16 +43,6 @@
     private static final Asn1Decoder decoder = new Asn1Decoder();
 
     /**
-     * Return the syncInfoValue OID
-     * 
-     * @see org.apache.directory.shared.ldap.codec.ControlDecoder#getControlType()
-     */
-    public String getControlType()
-    {
-        return SyncInfoValueControl.CONTROL_OID;
-    }
-
-    /**
      * Decode the syncInfoValue control
      * 
      * @param controlBytes The bytes array which contains the encoded syncInfoValue
@@ -60,10 +52,12 @@
      * @throws DecoderException If the decoding found an error
      * @throws NamingException It will never be throw by this method
      */
-    public Asn1Object decode( byte[] controlBytes ) throws DecoderException
+    public Asn1Object decode( byte[] controlBytes, CodecControl control ) throws DecoderException
     {
         ByteBuffer bb = ByteBuffer.wrap( controlBytes );
         SyncInfoValueControlContainer container = new SyncInfoValueControlContainer();
+        container.setSyncInfoValueControl( (SyncInfoValueControlCodec)control );
+
         decoder.decode( bb, container );
         return container.getSyncInfoValueControl();
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlCodec.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlCodec.java Mon Feb  1 15:04:10 2010
@@ -21,11 +21,11 @@
 
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.AbstractAsn1Object;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.controls.AbstractControlCodec;
 import org.apache.directory.shared.ldap.message.control.replication.SynchronizationModeEnum;
 import org.apache.directory.shared.ldap.util.StringTools;
 
@@ -35,8 +35,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev:$, $Date: 
  */
-public class SyncRequestValueControlCodec extends AbstractAsn1Object
+public class SyncRequestValueControlCodec  extends AbstractControlCodec
 {
+    /** This control OID */
+    public static final String CONTROL_OID = "1.3.6.1.4.1.4203.1.9.1.1";
+
     /** The synchronization type */
     private SynchronizationModeEnum mode;
     
@@ -48,6 +51,13 @@
     
     /** The global length for this control */
     private int syncRequestValueLength;
+    
+    public SyncRequestValueControlCodec()
+    {
+        super( CONTROL_OID );
+
+        decoder = new SyncRequestValueControlDecoder();
+    }
 
     /**
      * @return the mode
@@ -124,10 +134,16 @@
             syncRequestValueLength += 1 + TLV.getNbBytes( cookie.length ) + cookie.length;
         }
         
-        // The reloadHint length
-        syncRequestValueLength += 1 + 1 + 1;
+        // The reloadHint length, default to false
+        if ( reloadHint )
+        {
+            syncRequestValueLength += 1 + 1 + 1;
+        }
+
+        valueLength =  1 + TLV.getNbBytes( syncRequestValueLength ) + syncRequestValueLength;
 
-        return 1 + TLV.getNbBytes( syncRequestValueLength ) + syncRequestValueLength;
+        // Call the super class to compute the global control length
+        return super.computeLength( valueLength );
     }
     
     
@@ -140,29 +156,89 @@
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
     {
-        // Allocate the bytes buffer.
-        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
-        bb.put( UniversalTag.SEQUENCE_TAG );
-        bb.put( TLV.getBytes( syncRequestValueLength ) );
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        // Encode the Control envelop
+        super.encode( buffer );
+        
+        // Encode the OCTET_STRING tag
+        buffer.put( UniversalTag.OCTET_STRING_TAG );
+        buffer.put( TLV.getBytes( valueLength ) );
+
+        // Encode the SEQ 
+        buffer.put( UniversalTag.SEQUENCE_TAG );
+        buffer.put( TLV.getBytes( syncRequestValueLength ) );
 
         // The mode
-        bb.put(  UniversalTag.ENUMERATED_TAG );
-        bb.put( (byte)0x01 );
-        bb.put( Value.getBytes( mode.getValue() ) );
+        buffer.put(  UniversalTag.ENUMERATED_TAG );
+        buffer.put( (byte)0x01 );
+        buffer.put( Value.getBytes( mode.getValue() ) );
 
         // The cookie
         if ( cookie != null )
         {
-            Value.encode( bb, cookie );
+            Value.encode( buffer, cookie );
         }
         
-        Value.encode( bb, reloadHint );
+        // The reloadHint if not false
+        if ( reloadHint )
+        {
+            Value.encode( buffer, reloadHint );
+        }
         
-        return bb;
+        return buffer;
     }
     
     
     /**
+     * {@inheritDoc}
+     */
+    public byte[] getValue()
+    {
+        if ( value == null )
+        {
+            try
+            { 
+                computeLength();
+                ByteBuffer buffer = ByteBuffer.allocate( valueLength );
+                
+                // Encode the SEQ 
+                buffer.put( UniversalTag.SEQUENCE_TAG );
+                buffer.put( TLV.getBytes( syncRequestValueLength ) );
+
+                // The mode
+                buffer.put(  UniversalTag.ENUMERATED_TAG );
+                buffer.put( (byte)0x01 );
+                buffer.put( Value.getBytes( mode.getValue() ) );
+
+                // The cookie
+                if ( cookie != null )
+                {
+                    Value.encode( buffer, cookie );
+                }
+                
+                // The reloadHint if not false
+                if ( reloadHint )
+                {
+                    Value.encode( buffer, reloadHint );
+                }
+
+                value = buffer.array();
+            }
+            catch ( Exception e )
+            {
+                return null;
+            }
+        }
+        
+        return value;
+    }
+
+
+    /**
      * @see Object#toString()
      */
     public String toString()
@@ -170,6 +246,8 @@
         StringBuilder sb = new StringBuilder();
         
         sb.append( "    SyncRequestValue control :\n" );
+        sb.append( "        oid : " ).append( getOid() ).append( '\n' );
+        sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
         sb.append( "        mode              : '" ).append( mode ).append( "'\n" );
         sb.append( "        cookie            : '" ).
             append( StringTools.dumpBytes( cookie ) ).append( "'\n" );

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlDecoder.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlDecoder.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlDecoder.java Mon Feb  1 15:04:10 2010
@@ -22,11 +22,13 @@
 
 import java.nio.ByteBuffer;
 
+import javax.naming.NamingException;
+
 import org.apache.directory.shared.asn1.Asn1Object;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.ldap.codec.ControlDecoder;
-import org.apache.directory.shared.ldap.message.control.replication.SyncRequestValueControl;
+import org.apache.directory.shared.ldap.codec.controls.CodecControl;
+import org.apache.directory.shared.ldap.codec.controls.ControlDecoder;
 
 
 /**
@@ -41,16 +43,6 @@
     private static final Asn1Decoder decoder = new Asn1Decoder();
 
     /**
-     * Return the syncRequestValue OID
-     * 
-     * @see org.apache.directory.shared.ldap.codec.ControlDecoder#getControlType()
-     */
-    public String getControlType()
-    {
-        return SyncRequestValueControl.CONTROL_OID;
-    }
-
-    /**
      * Decode the syncRequestValue control
      * 
      * @param controlBytes The bytes array which contains the encoded syncRequestValue
@@ -60,10 +52,12 @@
      * @throws DecoderException If the decoding found an error
      * @throws NamingException It will never be throw by this method
      */
-    public Asn1Object decode( byte[] controlBytes ) throws DecoderException
+    public Asn1Object decode( byte[] controlBytes, CodecControl control ) throws DecoderException
     {
         ByteBuffer bb = ByteBuffer.wrap( controlBytes );
         SyncRequestValueControlContainer container = new SyncRequestValueControlContainer();
+        container.setSyncRequestValueControl( (SyncRequestValueControlCodec)control );
+
         decoder.decode( bb, container );
         return container.getSyncRequestValueControl();
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlGrammar.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncRequestValue/SyncRequestValueControlGrammar.java Mon Feb  1 15:04:10 2010
@@ -93,15 +93,7 @@
             new GrammarTransition( IStates.INIT_GRAMMAR_STATE, 
                                     SyncRequestValueControlStatesEnum.SYNC_REQUEST_VALUE_SEQUENCE_STATE, 
                                     UniversalTag.SEQUENCE_TAG, 
-                new GrammarAction( "Init SyncRequestValueControl" )
-            {
-                public void action( IAsn1Container container )
-                {
-                    SyncRequestValueControlContainer SyncRequestValueContainer = ( SyncRequestValueControlContainer ) container;
-                    SyncRequestValueControlCodec control = new SyncRequestValueControlCodec();
-                    SyncRequestValueContainer.setSyncRequestValueControl( control );
-                }
-            } );
+                null );
 
 
         /** 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlCodec.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlCodec.java Mon Feb  1 15:04:10 2010
@@ -22,11 +22,11 @@
 
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.AbstractAsn1Object;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.controls.AbstractControlCodec;
 import org.apache.directory.shared.ldap.message.control.replication.SyncStateTypeEnum;
 import org.apache.directory.shared.ldap.util.StringTools;
 
@@ -37,8 +37,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev:$, $Date: 
  */
-public class SyncStateValueControlCodec extends AbstractAsn1Object
+public class SyncStateValueControlCodec  extends AbstractControlCodec
 {
+    /** This control OID */
+    public static final String CONTROL_OID = "1.3.6.1.4.1.4203.1.9.1.2";
+
     /** The syncStateEnum type */
     private SyncStateTypeEnum syncStateType;
 
@@ -49,8 +52,14 @@
     private byte[] entryUUID;
 
     /** global length for the control */
-    private int syncStateValueLength;
+    private int syncStateSeqLength;
 
+    public SyncStateValueControlCodec()
+    {
+        super( CONTROL_OID );
+        
+        decoder = new SyncStateValueControlDecoder();
+    }
 
     /**
      * @return the cookie
@@ -124,17 +133,19 @@
     public int computeLength()
     {
         // The sync state type length
-        syncStateValueLength = 1 + 1 + 1;
+        syncStateSeqLength = 1 + 1 + 1;
 
-        syncStateValueLength += 1 + TLV.getNbBytes( entryUUID.length ) + entryUUID.length;
+        syncStateSeqLength += 1 + TLV.getNbBytes( entryUUID.length ) + entryUUID.length;
 
         // The cookie length, if we have a cookie
         if ( cookie != null )
         {
-            syncStateValueLength += 1 + TLV.getNbBytes( cookie.length ) + cookie.length;
+            syncStateSeqLength += 1 + TLV.getNbBytes( cookie.length ) + cookie.length;
         }
+        
+        valueLength = 1 + TLV.getNbBytes( syncStateSeqLength ) + syncStateSeqLength;
 
-        return 1 + TLV.getNbBytes( syncStateValueLength ) + syncStateValueLength;
+        return super.computeLength( valueLength );
     }
 
 
@@ -147,26 +158,79 @@
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
     {
-        // Allocate the bytes buffer.
-        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
-        bb.put( UniversalTag.SEQUENCE_TAG );
-        bb.put( TLV.getBytes( syncStateValueLength ) );
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+        
+        // Encode the Control envelop
+        super.encode( buffer );
+        
+        // Encode the OCTET_STRING tag
+        buffer.put( UniversalTag.OCTET_STRING_TAG );
+        buffer.put( TLV.getBytes( valueLength ) );
+
+        // Encode the SEQ 
+        buffer.put( UniversalTag.SEQUENCE_TAG );
+        buffer.put( TLV.getBytes( syncStateSeqLength ) );
 
         // The mode
-        bb.put( UniversalTag.ENUMERATED_TAG );
-        bb.put( ( byte ) 0x01 );
-        bb.put( Value.getBytes( syncStateType.getValue() ) );
+        buffer.put( UniversalTag.ENUMERATED_TAG );
+        buffer.put( ( byte ) 0x01 );
+        buffer.put( Value.getBytes( syncStateType.getValue() ) );
 
         // the entryUUID
-        Value.encode( bb, entryUUID );
+        Value.encode( buffer, entryUUID );
 
         // The cookie
         if ( cookie != null )
         {
-            Value.encode( bb, cookie );
+            Value.encode( buffer, cookie );
         }
 
-        return bb;
+        return buffer;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public byte[] getValue()
+    {
+        if ( value == null )
+        {
+            try
+            { 
+                computeLength();
+                ByteBuffer buffer = ByteBuffer.allocate( valueLength );
+                
+                // Encode the SEQ 
+                buffer.put( UniversalTag.SEQUENCE_TAG );
+                buffer.put( TLV.getBytes( syncStateSeqLength ) );
+
+                // The mode
+                buffer.put( UniversalTag.ENUMERATED_TAG );
+                buffer.put( ( byte ) 0x01 );
+                buffer.put( Value.getBytes( syncStateType.getValue() ) );
+
+                // the entryUUID
+                Value.encode( buffer, entryUUID );
+
+                // The cookie
+                if ( cookie != null )
+                {
+                    Value.encode( buffer, cookie );
+                }
+
+                value = buffer.array();
+            }
+            catch ( Exception e )
+            {
+                return null;
+            }
+        }
+        
+        return value;
     }
 
 
@@ -178,6 +242,8 @@
         StringBuilder sb = new StringBuilder();
 
         sb.append( "    SyncStateValue control :\n" );
+        sb.append( "        oid : " ).append( getOid() ).append( '\n' );
+        sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
         sb.append( "        syncStateType     : '" ).append( syncStateType ).append( "'\n" );
         sb.append( "        entryUUID         : '" ).append( StringTools.dumpBytes( entryUUID ) ).append( "'\n" );
         sb.append( "        cookie            : '" ).append( StringTools.dumpBytes( cookie ) ).append( "'\n" );

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlDecoder.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlDecoder.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlDecoder.java Mon Feb  1 15:04:10 2010
@@ -22,11 +22,13 @@
 
 import java.nio.ByteBuffer;
 
+import javax.naming.NamingException;
+
 import org.apache.directory.shared.asn1.Asn1Object;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.ldap.codec.ControlDecoder;
-import org.apache.directory.shared.ldap.message.control.replication.SyncStateValueControl;
+import org.apache.directory.shared.ldap.codec.controls.CodecControl;
+import org.apache.directory.shared.ldap.codec.controls.ControlDecoder;
 
 
 /**
@@ -41,16 +43,6 @@
     private static final Asn1Decoder decoder = new Asn1Decoder();
 
     /**
-     * Return the syncStateValue OID
-     * 
-     * @see org.apache.directory.shared.ldap.codec.ControlDecoder#getControlType()
-     */
-    public String getControlType()
-    {
-        return SyncStateValueControl.CONTROL_OID;
-    }
-
-    /**
      * Decode the syncStateValue control
      * 
      * @param controlBytes The bytes array which contains the encoded syncStateValue
@@ -60,10 +52,12 @@
      * @throws DecoderException If the decoding found an error
      * @throws NamingException It will never be throw by this method
      */
-    public Asn1Object decode( byte[] controlBytes ) throws DecoderException
+    public Asn1Object decode( byte[] controlBytes, CodecControl control ) throws DecoderException
     {
         ByteBuffer bb = ByteBuffer.wrap( controlBytes );
         SyncStateValueControlContainer container = new SyncStateValueControlContainer();
+        container.setSyncStateValueControl( (SyncStateValueControlCodec)control );
+
         decoder.decode( bb, container );
         return container.getSyncStateValueControl();
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlGrammar.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlGrammar.java Mon Feb  1 15:04:10 2010
@@ -89,15 +89,7 @@
          */
         super.transitions[IStates.INIT_GRAMMAR_STATE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
             IStates.INIT_GRAMMAR_STATE, SyncStateValueControlStatesEnum.SYNC_STATE_VALUE_SEQUENCE_STATE,
-            UniversalTag.SEQUENCE_TAG, new GrammarAction( "Init SyncStateValueControl" )
-            {
-                public void action( IAsn1Container container )
-                {
-                    SyncStateValueControlContainer syncStateValueContainer = ( SyncStateValueControlContainer ) container;
-                    SyncStateValueControlCodec control = new SyncStateValueControlCodec();
-                    syncStateValueContainer.setSyncStateValueControl( control );
-                }
-            } );
+            UniversalTag.SEQUENCE_TAG, null );
 
         /** 
          * Transition from SyncStateValue sequence to state type enum

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlCodec.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlCodec.java Mon Feb  1 15:04:10 2010
@@ -22,11 +22,12 @@
 
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.AbstractAsn1Object;
+import org.apache.directory.shared.asn1.Asn1Object;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.controls.AbstractControlCodec;
 import org.apache.directory.shared.ldap.codec.search.controls.ChangeType;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -80,8 +81,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$, 
  */
-public class EntryChangeControlCodec extends AbstractAsn1Object
+public class EntryChangeControlCodec extends AbstractControlCodec
 {
+    /** The EntryChange control */
+    public static final String CONTROL_OID = "2.16.840.1.113730.3.4.7";
+
     public static final int UNDEFINED_CHANGE_NUMBER = -1;
 
     private ChangeType changeType = ChangeType.ADD;
@@ -103,7 +107,9 @@
      */
     public EntryChangeControlCodec()
     {
-        super();
+        super( CONTROL_OID );
+        
+        decoder = new EntryChangeControlDecoder();
     }
 
     
@@ -135,8 +141,10 @@
         }
 
         eccSeqLength = changeTypesLength + previousDnLength + changeNumberLength;
+        valueLength = 1 + TLV.getNbBytes( eccSeqLength ) + eccSeqLength;
 
-        return 1 + TLV.getNbBytes( eccSeqLength ) + eccSeqLength;
+        // Call the super class to compute the global control length
+        return super.computeLength( valueLength );
     }
 
 
@@ -149,59 +157,94 @@
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
     {
-        // Allocate the bytes buffer.
-        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
-        bb.put( UniversalTag.SEQUENCE_TAG );
-        bb.put( TLV.getBytes( eccSeqLength ) );
-
-        bb.put( UniversalTag.ENUMERATED_TAG );
-        bb.put( ( byte ) 1 );
-        bb.put( Value.getBytes( changeType.getValue() ) );
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        // Encode the Control envelop
+        super.encode( buffer );
+        
+        // Encode the OCTET_STRING tag
+        buffer.put( UniversalTag.OCTET_STRING_TAG );
+        buffer.put( TLV.getBytes( valueLength ) );
+
+        buffer.put( UniversalTag.SEQUENCE_TAG );
+        buffer.put( TLV.getBytes( eccSeqLength ) );
+
+        buffer.put( UniversalTag.ENUMERATED_TAG );
+        buffer.put( ( byte ) 1 );
+        buffer.put( Value.getBytes( changeType.getValue() ) );
 
         if ( previousDn != null )
         {
-            Value.encode( bb, previousDnBytes );
+            Value.encode( buffer, previousDnBytes );
         }
         
         if ( changeNumber != UNDEFINED_CHANGE_NUMBER )
         {
-            Value.encode( bb, changeNumber );
+            Value.encode( buffer, changeNumber );
         }
         
-        return bb;
+        return buffer;
     }
-
-
+    
+    
     /**
-     * Return a String representing this EntryChangeControl.
+     * {@inheritDoc}
      */
-    public String toString()
+    public byte[] getValue()
     {
-        StringBuffer sb = new StringBuffer();
-
-        sb.append( "    Entry Change Control\n" );
-        sb.append( "        changeType   : '" ).append( changeType ).append( "'\n" );
-        sb.append( "        previousDN   : '" ).append( previousDn ).append( "'\n" );
-        
-        if ( changeNumber == UNDEFINED_CHANGE_NUMBER )
-        {
-            sb.append( "        changeNumber : '" ).append( "UNDEFINED" ).append( "'\n" );
-        }
-        else
+        if ( value == null )
         {
-            sb.append( "        changeNumber : '" ).append( changeNumber ).append( "'\n" );
+            try
+            { 
+                computeLength();
+                ByteBuffer buffer = ByteBuffer.allocate( valueLength );
+                
+                buffer.put( UniversalTag.SEQUENCE_TAG );
+                buffer.put( TLV.getBytes( eccSeqLength ) );
+        
+                buffer.put( UniversalTag.ENUMERATED_TAG );
+                buffer.put( ( byte ) 1 );
+                buffer.put( Value.getBytes( changeType.getValue() ) );
+        
+                if ( previousDn != null )
+                {
+                    Value.encode( buffer, previousDnBytes );
+                }
+                
+                if ( changeNumber != UNDEFINED_CHANGE_NUMBER )
+                {
+                    Value.encode( buffer, changeNumber );
+                }
+                
+                value = buffer.array();
+            }
+            catch ( Exception e )
+            {
+                return null;
+            }
         }
         
-        return sb.toString();
+        return value;
     }
 
 
+    /**
+     * @return The ChangeType
+     */
     public ChangeType getChangeType()
     {
         return changeType;
     }
 
 
+    /**
+     * Set the ChangeType
+     *
+     * @param changeType Add, Delete; Modify or ModifyDN
+     */
     public void setChangeType( ChangeType changeType )
     {
         this.changeType = changeType;
@@ -230,4 +273,30 @@
     {
         this.changeNumber = changeNumber;
     }
+
+
+    /**
+     * Return a String representing this EntryChangeControl.
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    Entry Change Control\n" );
+        sb.append( "        oid : " ).append( getOid() ).append( '\n' );
+        sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
+        sb.append( "        changeType   : '" ).append( changeType ).append( "'\n" );
+        sb.append( "        previousDN   : '" ).append( previousDn ).append( "'\n" );
+        
+        if ( changeNumber == UNDEFINED_CHANGE_NUMBER )
+        {
+            sb.append( "        changeNumber : '" ).append( "UNDEFINED" ).append( "'\n" );
+        }
+        else
+        {
+            sb.append( "        changeNumber : '" ).append( changeNumber ).append( "'\n" );
+        }
+        
+        return sb.toString();
+    }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlDecoder.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlDecoder.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlDecoder.java Mon Feb  1 15:04:10 2010
@@ -22,10 +22,13 @@
 
 import java.nio.ByteBuffer;
 
+import javax.naming.NamingException;
+
 import org.apache.directory.shared.asn1.Asn1Object;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.ldap.codec.ControlDecoder;
+import org.apache.directory.shared.ldap.codec.controls.CodecControl;
+import org.apache.directory.shared.ldap.codec.controls.ControlDecoder;
 
 
 /**
@@ -36,21 +39,10 @@
  */
 public class EntryChangeControlDecoder extends Asn1Decoder implements ControlDecoder
 {
-    /** The entry change OID */
-    private final static String CONTROL_TYPE_OID = "2.16.840.1.113730.3.4.7";
-
     /** An instance of this decoder */
     private static final Asn1Decoder decoder = new Asn1Decoder();
 
     /**
-     * @return The Entry Change controm OID
-     */
-    public String getControlType()
-    {
-        return CONTROL_TYPE_OID;
-    }
-
-    /**
      * Decode the entry change control
      * 
      * @param controlBytes The bytes array which contains the encoded entry change
@@ -61,10 +53,11 @@
      * @throws NamingException It will never be throw by this method
      */
     
-    public Asn1Object decode( byte[] controlBytes ) throws DecoderException
+    public Asn1Object decode( byte[] controlBytes, CodecControl control ) throws DecoderException
     {
         ByteBuffer bb = ByteBuffer.wrap( controlBytes );
         EntryChangeControlContainer container = new EntryChangeControlContainer();
+        container.setEntryChangeControl( (EntryChangeControlCodec)control );
         decoder.decode( bb, container );
         return container.getEntryChangeControl();
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlGrammar.java?rev=905297&r1=905296&r2=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlGrammar.java Mon Feb  1 15:04:10 2010
@@ -81,16 +81,7 @@
         super.transitions[EntryChangeControlStatesEnum.START_STATE][UniversalTag.SEQUENCE_TAG] = 
             new GrammarTransition( EntryChangeControlStatesEnum.START_STATE, 
                                     EntryChangeControlStatesEnum.EC_SEQUENCE_STATE, 
-                                    UniversalTag.SEQUENCE_TAG,
-                new GrammarAction( "Init EntryChangeControl" )
-            {
-                public void action( IAsn1Container container )
-                {
-                    EntryChangeControlContainer entryChangeContainer = ( EntryChangeControlContainer ) container;
-                    EntryChangeControlCodec control = new EntryChangeControlCodec();
-                    entryChangeContainer.setEntryChangeControl( control );
-                }
-            } );
+                                    UniversalTag.SEQUENCE_TAG, null );
 
         // ============================================================================================
         // transition from Entry Change sequence to Change Type

Copied: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlCodec.java (from r905110, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlCodec.java)
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlCodec.java?p2=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlCodec.java&p1=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlCodec.java&r1=905110&r2=905297&rev=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlCodec.java Mon Feb  1 15:04:10 2010
@@ -22,11 +22,12 @@
 
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.AbstractAsn1Object;
+import org.apache.directory.shared.asn1.Asn1Object;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.controls.AbstractControlCodec;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 
@@ -62,8 +63,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev:  $
  */
-public class PagedSearchControlCodec extends AbstractAsn1Object
+public class PagedResultsControlCodec extends AbstractControlCodec
 {
+    /** The Paged Search Control OID */
+    public static final String CONTROL_OID = "1.2.840.113556.1.4.319";
+
     /** The number of entries to return, or returned */
     private int size;
     
@@ -73,27 +77,33 @@
     /** The entry change global length */
     private int pscSeqLength;
 
-
     /**
      * @see Asn1Object#Asn1Object
      */
-    public PagedSearchControlCodec()
+    public PagedResultsControlCodec()
     {
-        super();
+        super( CONTROL_OID );
+        
+        decoder = new PagedResultsControlDecoder();
     }
 
     
     /**
-     * Compute the PagedSearchControl length 
+     * Compute the PagedSearchControl length, which is the sum
+     * of the control length and the value length.
+     * 
+     * <pre>
+     * PagedSearchControl value length :
      * 
      * 0x30 L1 
      *   | 
      *   +--> 0x02 0x0(1-4) [0..2^63-1] (size) 
-     *   +--> 0x04 L2 (cookie) 
+     *   +--> 0x04 L2 (cookie)
+     * </pre> 
      */
     public int computeLength()
     {
-        int sizeLength = 1 + 1 + Value.getNbBytes( size );;
+        int sizeLength = 1 + 1 + Value.getNbBytes( size );
 
         int cookieLength = 0;
         
@@ -107,8 +117,10 @@
         }
 
         pscSeqLength = sizeLength + cookieLength;
+        valueLength = 1 + TLV.getNbBytes( pscSeqLength ) + pscSeqLength;
 
-        return 1 + TLV.getNbBytes( pscSeqLength ) + pscSeqLength;
+        // Call the super class to compute the global control length
+        return super.computeLength( valueLength );
     }
 
 
@@ -121,30 +133,57 @@
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
     {
-        // Allocate the bytes buffer.
-        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
-        bb.put( UniversalTag.SEQUENCE_TAG );
-        bb.put( TLV.getBytes( pscSeqLength ) );
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
 
-        Value.encode( bb, size );
-        Value.encode( bb, cookie );
+        // Encode the Control envelop
+        super.encode( buffer );
         
-        return bb;
-    }
-
+        // Encode the OCTET_STRING tag
+        buffer.put( UniversalTag.OCTET_STRING_TAG );
+        buffer.put( TLV.getBytes( valueLength ) );
+        
+        // Now encode the PagedSearch specific part
+        buffer.put( UniversalTag.SEQUENCE_TAG );
+        buffer.put( TLV.getBytes( pscSeqLength ) );
 
+        Value.encode( buffer, size );
+        Value.encode( buffer, cookie );
+        
+        return buffer;
+    }
+    
+    
     /**
-     * Return a String representing this PagedSearchControl.
+     * {@inheritDoc}
      */
-    public String toString()
+    public byte[] getValue()
     {
-        StringBuffer sb = new StringBuffer();
-
-        sb.append( "    Paged Search Control\n" );
-        sb.append( "        size   : '" ).append( size ).append( "'\n" );
-        sb.append( "        cookie   : '" ).append( StringTools.dumpBytes( cookie ) ).append( "'\n" );
+        if ( value == null )
+        {
+            try
+            { 
+                computeLength();
+                ByteBuffer buffer = ByteBuffer.allocate( valueLength );
+                
+                // Now encode the PagedSearch specific part
+                buffer.put( UniversalTag.SEQUENCE_TAG );
+                buffer.put( TLV.getBytes( pscSeqLength ) );
+
+                Value.encode( buffer, size );
+                Value.encode( buffer, cookie );
+                
+                value = buffer.array();
+            }
+            catch ( Exception e )
+            {
+                return null;
+            }
+        }
         
-        return sb.toString();
+        return value;
     }
 
 
@@ -186,4 +225,32 @@
     {
         this.cookie = cookie;
     }
+
+    
+    /**
+     * @return The integer value for the current cookie
+     */
+    public int getCookieValue()
+    {
+        int value = ((cookie[0]&0x00FF)<<24) + ((cookie[1]&0x00FF)<<16) + ((cookie[2]&0x00FF)<<8) + (cookie[3]&0x00FF);
+        
+        return value;
+    }
+    
+    
+    /**
+     * Return a String representing this PagedSearchControl.
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    Paged Search Control\n" );
+        sb.append( "        oid : " ).append( getOid() ).append( '\n' );
+        sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
+        sb.append( "        size   : '" ).append( size ).append( "'\n" );
+        sb.append( "        cookie   : '" ).append( StringTools.dumpBytes( cookie ) ).append( "'\n" );
+        
+        return sb.toString();
+    }
 }

Copied: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlContainer.java (from r905110, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlContainer.java)
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlContainer.java?p2=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlContainer.java&p1=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlContainer.java&r1=905110&r2=905297&rev=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlContainer.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlContainer.java Mon Feb  1 15:04:10 2010
@@ -29,29 +29,29 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 664290 $, $Date: 2008-06-07 08:28:06 +0200 (Sat, 07 Jun 2008) $, 
  */
-public class PagedSearchControlContainer extends AbstractContainer
+public class PagedResultsControlContainer extends AbstractContainer
 {
     /** PagedSearchControl */
-    private PagedSearchControlCodec control;
+    private PagedResultsControlCodec control;
 
 
     /**
      * Creates a new PagedSearchControl container object. We will store one grammar,
      * it's enough ...
      */
-    public PagedSearchControlContainer()
+    public PagedResultsControlContainer()
     {
         super();
         stateStack = new int[1];
-        grammar = PagedSearchControlGrammar.getInstance();
-        states = PagedSearchControlStatesEnum.getInstance();
+        grammar = PagedResultsControlGrammar.getInstance();
+        states = PagedResultsControlStatesEnum.getInstance();
     }
 
 
     /**
      * @return Returns the paged search control.
      */
-    public PagedSearchControlCodec getPagedSearchControl()
+    public PagedResultsControlCodec getPagedSearchControl()
     {
 
         return control;
@@ -64,7 +64,7 @@
      * 
      * @param control the PagedSearchControl to set.
      */
-    public void setPagedSearchControl( PagedSearchControlCodec control )
+    public void setPagedSearchControl( PagedResultsControlCodec control )
     {
         this.control = control;
     }

Copied: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlDecoder.java (from r905110, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlDecoder.java)
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlDecoder.java?p2=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlDecoder.java&p1=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlDecoder.java&r1=905110&r2=905297&rev=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlDecoder.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlDecoder.java Mon Feb  1 15:04:10 2010
@@ -22,10 +22,13 @@
 
 import java.nio.ByteBuffer;
 
+import javax.naming.NamingException;
+
 import org.apache.directory.shared.asn1.Asn1Object;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.ldap.codec.ControlDecoder;
+import org.apache.directory.shared.ldap.codec.controls.CodecControl;
+import org.apache.directory.shared.ldap.codec.controls.ControlDecoder;
 
 
 /**
@@ -34,25 +37,12 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 664290 $, $Date: 2008-06-07 08:28:06 +0200 (Sat, 07 Jun 2008) $, 
  */
-public class PagedSearchControlDecoder extends Asn1Decoder implements ControlDecoder
+public class PagedResultsControlDecoder extends Asn1Decoder implements ControlDecoder
 {
-    /** The paged search OID */
-    private final static String CONTROL_TYPE_OID = "1.2.840.113556.1.4.319";
-
     /** An instance of this decoder */
     private static final Asn1Decoder decoder = new Asn1Decoder();
 
     /**
-     * Return the paged search OID
-     * 
-     * @see org.apache.directory.shared.ldap.codec.ControlDecoder#getControlType()
-     */
-    public String getControlType()
-    {
-        return CONTROL_TYPE_OID;
-    }
-
-    /**
      * Decode the paged search control
      * 
      * @param controlBytes The bytes array which contains the encoded paged search
@@ -62,10 +52,11 @@
      * @throws DecoderException If the decoding found an error
      * @throws NamingException It will never be throw by this method
      */
-    public Asn1Object decode( byte[] controlBytes ) throws DecoderException
+    public Asn1Object decode( byte[] controlBytes, CodecControl control ) throws DecoderException
     {
         ByteBuffer bb = ByteBuffer.wrap( controlBytes );
-        PagedSearchControlContainer container = new PagedSearchControlContainer();
+        PagedResultsControlContainer container = new PagedResultsControlContainer();
+        container.setPagedSearchControl( (PagedResultsControlCodec)control );
         decoder.decode( bb, container );
         return container.getPagedSearchControl();
     }

Copied: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlGrammar.java (from r905110, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlGrammar.java)
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlGrammar.java?p2=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlGrammar.java&p1=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlGrammar.java&r1=905110&r2=905297&rev=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlGrammar.java Mon Feb  1 15:04:10 2010
@@ -50,49 +50,40 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 664290 $, $Date: 2008-06-07 08:28:06 +0200 (Sat, 07 Jun 2008) $, 
  */
-public class PagedSearchControlGrammar extends AbstractGrammar
+public class PagedResultsControlGrammar extends AbstractGrammar
 {
     /** The logger */
-    static final Logger log = LoggerFactory.getLogger( PagedSearchControlGrammar.class );
+    static final Logger log = LoggerFactory.getLogger( PagedResultsControlGrammar.class );
 
     /** Speedup for logs */
     static final boolean IS_DEBUG = log.isDebugEnabled();
 
     /** The instance of grammar. PagedSearchControlGrammar is a singleton */
-    private static IGrammar instance = new PagedSearchControlGrammar();
+    private static IGrammar instance = new PagedResultsControlGrammar();
 
 
     /**
      * Creates a new PagedSearchControlGrammar object.
      */
-    private PagedSearchControlGrammar()
+    private PagedResultsControlGrammar()
     {
-        name = PagedSearchControlGrammar.class.getName();
-        statesEnum = PagedSearchControlStatesEnum.getInstance();
+        name = PagedResultsControlGrammar.class.getName();
+        statesEnum = PagedResultsControlStatesEnum.getInstance();
 
         // Create the transitions table
-        super.transitions = new GrammarTransition[PagedSearchControlStatesEnum.LAST_PAGED_SEARCH_STATE][256];
+        super.transitions = new GrammarTransition[PagedResultsControlStatesEnum.LAST_PAGED_SEARCH_STATE][256];
 
         /** 
          * Transition from initial state to PagedSearch sequence
          * realSearchControlValue ::= SEQUENCE OF {
          *     ...
          *     
-         * Initialize the persistence search object
+         * Nothing to do
          */
         super.transitions[IStates.INIT_GRAMMAR_STATE][UniversalTag.SEQUENCE_TAG] = 
             new GrammarTransition( IStates.INIT_GRAMMAR_STATE, 
-                                    PagedSearchControlStatesEnum.PAGED_SEARCH_SEQUENCE_STATE, 
-                                    UniversalTag.SEQUENCE_TAG, 
-                new GrammarAction( "Init PagedSearchControl" )
-            {
-                public void action( IAsn1Container container )
-                {
-                    PagedSearchControlContainer pagedSearchContainer = ( PagedSearchControlContainer ) container;
-                    PagedSearchControlCodec control = new PagedSearchControlCodec();
-                    pagedSearchContainer.setPagedSearchControl( control );
-                }
-            } );
+                                    PagedResultsControlStatesEnum.PAGED_SEARCH_SEQUENCE_STATE, 
+                                    UniversalTag.SEQUENCE_TAG, null );
 
 
         /** 
@@ -104,15 +95,15 @@
          *     
          * Stores the size value
          */
-        super.transitions[PagedSearchControlStatesEnum.PAGED_SEARCH_SEQUENCE_STATE][UniversalTag.INTEGER_TAG] = 
-            new GrammarTransition( PagedSearchControlStatesEnum.PAGED_SEARCH_SEQUENCE_STATE, 
-                PagedSearchControlStatesEnum.SIZE_STATE, 
+        super.transitions[PagedResultsControlStatesEnum.PAGED_SEARCH_SEQUENCE_STATE][UniversalTag.INTEGER_TAG] = 
+            new GrammarTransition( PagedResultsControlStatesEnum.PAGED_SEARCH_SEQUENCE_STATE, 
+                PagedResultsControlStatesEnum.SIZE_STATE, 
                 UniversalTag.INTEGER_TAG,
                 new GrammarAction( "Set PagedSearchControl size" )
             {
                 public void action( IAsn1Container container ) throws DecoderException
                 {
-                    PagedSearchControlContainer pagedSearchContainer = ( PagedSearchControlContainer ) container;
+                    PagedResultsControlContainer pagedSearchContainer = ( PagedResultsControlContainer ) container;
                     Value value = pagedSearchContainer.getCurrentTLV().getValue();
 
                     try
@@ -152,14 +143,14 @@
          *     
          * Stores the cookie flag
          */
-        super.transitions[PagedSearchControlStatesEnum.SIZE_STATE][UniversalTag.OCTET_STRING_TAG] = 
-            new GrammarTransition( PagedSearchControlStatesEnum.SIZE_STATE,
-                                    PagedSearchControlStatesEnum.COOKIE_STATE, UniversalTag.OCTET_STRING_TAG,
+        super.transitions[PagedResultsControlStatesEnum.SIZE_STATE][UniversalTag.OCTET_STRING_TAG] = 
+            new GrammarTransition( PagedResultsControlStatesEnum.SIZE_STATE,
+                                    PagedResultsControlStatesEnum.COOKIE_STATE, UniversalTag.OCTET_STRING_TAG,
                 new GrammarAction( "Set PagedSearchControl cookie" )
             {
                 public void action( IAsn1Container container ) throws DecoderException
                 {
-                    PagedSearchControlContainer pagedSearchContainer = ( PagedSearchControlContainer ) container;
+                    PagedResultsControlContainer pagedSearchContainer = ( PagedResultsControlContainer ) container;
                     Value value = pagedSearchContainer.getCurrentTLV().getValue();
 
                     if ( pagedSearchContainer.getCurrentTLV().getLength() == 0 )

Copied: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlStatesEnum.java (from r905110, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlStatesEnum.java)
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlStatesEnum.java?p2=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlStatesEnum.java&p1=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlStatesEnum.java&r1=905110&r2=905297&rev=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedSearchControlStatesEnum.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControlStatesEnum.java Mon Feb  1 15:04:10 2010
@@ -31,7 +31,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 664290 $, $Date: 2008-06-07 08:28:06 +0200 (Sat, 07 Jun 2008) $, 
  */
-public class PagedSearchControlStatesEnum implements IStates
+public class PagedResultsControlStatesEnum implements IStates
 {
     // ~ Static fields/initializers
     // -----------------------------------------------------------------
@@ -67,7 +67,7 @@
         };
 
     /** The instance */
-    private static PagedSearchControlStatesEnum instance = new PagedSearchControlStatesEnum();
+    private static PagedResultsControlStatesEnum instance = new PagedResultsControlStatesEnum();
 
 
     // ~ Constructors
@@ -76,7 +76,7 @@
     /**
      * This is a private constructor. This class is a singleton
      */
-    private PagedSearchControlStatesEnum()
+    private PagedResultsControlStatesEnum()
     {
     }
 
@@ -115,7 +115,7 @@
      */
     public String getGrammarName( IGrammar grammar )
     {
-        if ( grammar instanceof PagedSearchControlGrammar )
+        if ( grammar instanceof PagedResultsControlGrammar )
         {
             return "PAGEDSEARCH_GRAMMAR";
         }

Copied: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/persistentSearch/PersistentSearchControlCodec.java (from r903704, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pSearch/PSearchControlCodec.java)
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/persistentSearch/PersistentSearchControlCodec.java?p2=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/persistentSearch/PersistentSearchControlCodec.java&p1=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pSearch/PSearchControlCodec.java&r1=903704&r2=905297&rev=905297&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pSearch/PSearchControlCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/persistentSearch/PersistentSearchControlCodec.java Mon Feb  1 15:04:10 2010
@@ -17,16 +17,17 @@
  *  under the License. 
  *  
  */
-package org.apache.directory.shared.ldap.codec.search.controls.pSearch;
+package org.apache.directory.shared.ldap.codec.search.controls.persistentSearch;
 
 
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.AbstractAsn1Object;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.controls.AbstractControlCodec;
+import org.apache.directory.shared.ldap.codec.search.controls.ChangeType;
 
 
 /**
@@ -35,20 +36,23 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$, 
  */
-public class PSearchControlCodec extends AbstractAsn1Object
+public class PersistentSearchControlCodec extends AbstractControlCodec
 {
+    /** This control OID */
+    public static final String CONTROL_OID = "2.16.840.1.113730.3.4.3";
+
     /**
      * If changesOnly is TRUE, the server MUST NOT return any existing entries
      * that match the search criteria. Entries are only returned when they are
      * changed (added, modified, deleted, or subject to a modifyDN operation).
      */
-    private boolean changesOnly;
+    private boolean changesOnly = true;
 
     /**
      * If returnECs is TRUE, the server MUST return an Entry Change Notification
      * control with each entry returned as the result of changes.
      */
-    private boolean returnECs;
+    private boolean returnECs = false;
 
     /**
      * As changes are made to the server, the effected entries MUST be returned
@@ -60,7 +64,7 @@
      * modify (4), 
      * modDN  (8).
      */
-    private int changeTypes;
+    private int changeTypes = CHANGE_TYPES_MAX;
     
     /** Definition of the change types */
     public static final int CHANGE_TYPE_ADD     = 1;
@@ -79,9 +83,11 @@
      * Default constructor
      *
      */
-    public PSearchControlCodec()
+    public PersistentSearchControlCodec()
     {
-        super();
+        super( CONTROL_OID );
+        
+        decoder = new PersistentSearchControlDecoder();
     }
 
     public void setChangesOnly( boolean changesOnly )
@@ -120,12 +126,18 @@
     }
 
     /**
-     * Compute the PSearchControl length 
+     * Compute the PagedSearchControl length, which is the sum
+     * of the control length and the value length.
+     * 
+     * <pre>
+     * PersistentSearchControl value length :
+     * 
      * 0x30 L1 
      *   | 
      *   +--> 0x02 0x0(1-4) [0..2^31-1] (changeTypes) 
      *   +--> 0x01 0x01 [0x00 | 0xFF] (changeOnly) 
      *   +--> 0x01 0x01 [0x00 | 0xFF] (returnRCs)
+     * </pre> 
      */
     public int computeLength()
     {
@@ -134,8 +146,10 @@
         int returnRCsLength = 1 + 1 + 1;
 
         psearchSeqLength = changeTypesLength + changesOnlyLength + returnRCsLength;
+        int valueLength = 1 + TLV.getNbBytes( psearchSeqLength ) + psearchSeqLength;
 
-        return 1 + TLV.getNbBytes( psearchSeqLength ) + psearchSeqLength;
+        // Call the super class to compute the global control length
+        return super.computeLength( valueLength );
     }
 
 
@@ -148,15 +162,71 @@
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
     {
-        // Allocate the bytes buffer.
-        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
-        bb.put( UniversalTag.SEQUENCE_TAG );
-        bb.put( TLV.getBytes( psearchSeqLength ) );
-
-        Value.encode( bb, changeTypes );
-        Value.encode( bb, changesOnly );
-        Value.encode( bb, returnECs );
-        return bb;
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        // Encode the Control envelop
+        super.encode( buffer );
+        
+        // Encode the OCTET_STRING tag
+        buffer.put( UniversalTag.OCTET_STRING_TAG );
+        buffer.put( TLV.getBytes( valueLength ) );
+
+        // Now encode the PagedSearch specific part
+        buffer.put( UniversalTag.SEQUENCE_TAG );
+        buffer.put( TLV.getBytes( psearchSeqLength ) );
+
+        Value.encode( buffer, changeTypes );
+        Value.encode( buffer, changesOnly );
+        Value.encode( buffer, returnECs );
+        
+        return buffer;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public byte[] getValue()
+    {
+        if ( value == null )
+        {
+            try
+            { 
+                computeLength();
+                ByteBuffer buffer = ByteBuffer.allocate( valueLength );
+                
+                // Now encode the PagedSearch specific part
+                buffer.put( UniversalTag.SEQUENCE_TAG );
+                buffer.put( TLV.getBytes( psearchSeqLength ) );
+
+                Value.encode( buffer, changeTypes );
+                Value.encode( buffer, changesOnly );
+                Value.encode( buffer, returnECs );
+                
+                value = buffer.array();
+            }
+            catch ( Exception e )
+            {
+                return null;
+            }
+        }
+        
+        return value;
+    }
+
+    
+    public boolean isNotificationEnabled( ChangeType changeType )
+    {
+        return ( changeType.getValue() & changeTypes ) > 0;
+    }
+
+
+    public void enableNotification( ChangeType changeType )
+    {
+        changeTypes |= changeType.getValue();
     }
 
 
@@ -168,6 +238,8 @@
         StringBuffer sb = new StringBuffer();
 
         sb.append( "    Persistant Search Control\n" );
+        sb.append( "        oid : " ).append( getOid() ).append( '\n' );
+        sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
         sb.append( "        changeTypes : '" ).append( changeTypes ).append( "'\n" );
         sb.append( "        changesOnly : '" ).append( changesOnly ).append( "'\n" );
         sb.append( "        returnECs   : '" ).append( returnECs ).append( "'\n" );