package org.apache.ldap.common.asn1.pojo.psearch;

import org.apache.asn1.ber.tlv.Length;
import org.apache.asn1.ber.tlv.Value;


public class PSearchControl
{
    /** 
     * 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;

    /**
     * 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;
    
    /**
     * As changes are made to the server, the effected entries MUST be
     * returned to the client if they match the standard search cri-
     * teria and if the operation that caused the change is included in
     * the changeTypes field.  The changeTypes field is the logical OR
     * of one or more of these values: add (1), delete (2), modify (4),
     * modDN (8).
     */
    private int changeTypes;


    /**
     * Compute the PSearchControl length
     */
    public int computeLength()
    {
        int changeTypesLength = 2 + Value.getNbBytes( changeTypes );
        return  1 + Length.getNbBytes( changeTypesLength + 6 ) +
                changeTypesLength + // for changeTypes 
                6;                  // for two boolean values 
    }

    
    public void setChangesOnly( boolean changesOnly )
    {
        this.changesOnly = changesOnly;
    }

    
    public boolean isChangesOnly()
    {
        return changesOnly;
    }


    public void setReturnECs( boolean returnECs )
    {
        this.returnECs = returnECs;
    }


    public boolean isReturnECs()
    {
        return returnECs;
    }


    public void setChangeTypes( int changeTypes )
    {
        this.changeTypes = changeTypes;
    }


    public int getChangeTypes()
    {
        return changeTypes;
    }
}

@@ -1203,17 +1203,21 @@
 ength = 
-2
+1 + 1
  + Value
@@ -1256,147 +1256,179 @@
     
-return  1 + Length.getNbBytes(
+int
  change
-Types
+sOnly
 Length 
-+ 6 ) +%0A                changeTypesLength + // for changeTypes %0A                6;
+= 1 + 1 + 1;%0A        int returRCsLength = 1 + 1 + 1;%0A%0A        int psearchSeqLength = changeTypesLength + changesOnlyLength + returRCsLength;%0A
         
     
@@ -1423,24 +1423,25 @@
         
+%0A
         
   // for
@@ -1436,36 +1436,77 @@
     
-  // for two boolean values 
+return  1 + Length.getNbBytes( psearchSeqLength ) + psearchSeqLength;
 %0A   

clarifying the code