directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r225197 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/
Date Mon, 25 Jul 2005 22:46:31 GMT
Author: elecharny
Date: Mon Jul 25 15:46:16 2005
New Revision: 225197

URL: http://svn.apache.org/viewcvs?rev=225197&view=rev
Log:
Implemented the computeLength method.

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AbandonRequest.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AddRequest.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AddResponse.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindRequest.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindResponse.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareRequest.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareResponse.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/Control.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelRequest.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelResponse.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedRequest.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedResponse.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapMessage.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapResponse.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapResult.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNResponse.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyRequest.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyResponse.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SaslCredentials.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultDone.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultReference.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SimpleAuthentication.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/UnBindRequest.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AbandonRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AbandonRequest.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AbandonRequest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AbandonRequest.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
+
 /**
  * A AbandonRequest Message. Its syntax is :
  *   AbandonRequest ::= [APPLICATION 16] MessageID
@@ -63,6 +65,20 @@
         this.messageId = messageId;
     }
 
+    /**
+     * Compute the AbandonRequest length
+     * 
+     * AbandonRequest :
+     * 
+     * 0x50 0x0(1..4) MessageId
+     * 
+     * Length(AbandonRequest) = Length(0x50) + 1 + Length(MessageId)
+     */
+    public int computeLength()
+    {
+        return 1 + 1 + Length.getNbBytes( messageId );
+    }
+    
     /**
      * Return a String representing an AbandonRequest
      * 

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AddRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AddRequest.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AddRequest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AddRequest.java Mon Jul 25 15:46:16 2005
@@ -17,6 +17,7 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
 import org.apache.asn1.primitives.OctetString;
@@ -24,7 +25,9 @@
 import org.apache.log4j.Logger;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 
+import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.BasicAttribute;
@@ -136,6 +139,106 @@
         this.entry = entry;
     }
 
+    /**
+     * Compute the AddRequest length
+     * 
+     * AddRequest :
+     * 
+     * 0x68 L1
+     *  |
+     *  +--> 0x04 L2 entry
+     *  +--> 0x30 L3 (attributes)
+     *        |
+     *        +--> 0x30 L4-1 (attribute)
+     *        |     |
+     *        |     +--> 0x04 L5-1 type
+     *        |     +--> 0x31 L6-1 (values)
+     *        |           |
+     *        |           +--> 0x04 L7-1-1 value
+     *        |           +--> ...
+     *        |           +--> 0x04 L7-1-n value
+     *        |
+     *        +--> 0x30 L4-2 (attribute)
+     *        |     |
+     *        |     +--> 0x04 L5-2 type
+     *        |     +--> 0x31 L6-2 (values)
+     *        |           |
+     *        |           +--> 0x04 L7-2-1 value
+     *        |           +--> ...
+     *        |           +--> 0x04 L7-2-n value
+     *        |
+     *        +--> ...
+     *        |
+     *        +--> 0x30 L4-m (attribute)
+     *              |
+     *              +--> 0x04 L5-m type
+     *              +--> 0x31 L6-m (values)
+     *                    |
+     *                    +--> 0x04 L7-m-1 value
+     *                    +--> ...
+     *                    +--> 0x04 L7-m-n value
+     * 
+     */
+    public int computeLength()
+    {
+        int addRequestLength = 0; // Initialized with version
+        
+        // The entry
+        addRequestLength += 1 + Length.getNbBytes( entry.getLength() ) + entry.getLength();
+        
+        // The attributes sequence
+        int attributesLength = 0;
+        
+        if ( ( attributes != null ) && ( attributes.size() != 0 ) )
+        {
+            Iterator attributeIterator = attributes.iterator();
+            
+            // Compute the attributes length
+            while ( attributeIterator.hasNext() )
+            {
+                Attribute attribute = (Attribute)attributeIterator.next();
+                int attributeLength = 0;
+                
+                // Get the type length
+                int idLength = attribute.getID().getBytes().length;
+                attributeLength = 1 + Length.getNbBytes( idLength ) + idLength;
+                
+                // The values
+                try
+                {
+	                NamingEnumeration values = attribute.getAll();
+	                
+	                if ( values.hasMoreElements() )
+	                {
+	                    int valuesLength = 0;
+	                    
+		                while ( values.hasMoreElements() )
+		                {
+		                    OctetString value = (OctetString)values.next();
+		                    
+		                    valuesLength += 1 + Length.getNbBytes( value.getLength() ) + value.getLength();
+		                }
+
+	                    attributeLength += 1 + Length.getNbBytes( valuesLength ) + valuesLength; 
+	                }
+	                
+                }
+                catch (NamingException ne)
+                {
+                    return 0;
+                }
+                
+                // add the attribute length to the attributes length
+                attributesLength += 1 + Length.getNbBytes( attributeLength ) + attributeLength;
+            }
+        }
+        
+        addRequestLength += 1 + Length.getNbBytes( attributesLength ) + attributesLength;
+
+        // Return the result.
+        return 1 + Length.getNbBytes( addRequestLength ) + addRequestLength;
+    }
+    
     /**
      * Return a String representing an AddRequest
      * 

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AddResponse.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AddResponse.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AddResponse.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/AddResponse.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
+
 /**
  * An AddResponse Message. Its syntax is :
  *   AddResponse ::= [APPLICATION 9] LDAPResult
@@ -35,6 +37,26 @@
     }
 
     //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Compute the AddResponse length
+     * 
+     * AddResponse :
+     * 
+     * 0x69 L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(AddResponse) = Length(0x69) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int ldapResponseLength = super.computeLength();
+        
+        return 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
+    }
 
     /**
      * Get a String representation of an AddResponse

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindRequest.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindRequest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindRequest.java Mon Jul 25 15:46:16 2005
@@ -17,6 +17,7 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 
 
@@ -142,6 +143,39 @@
         this.version = version;
     }
 
+    /**
+     * Compute the BindRequest length
+     * 
+     * BindRequest :
+     * 
+     * 0x60 L1
+     *  |
+     *  +--> 0x02 0x01 (1..127) version
+     *  +--> 0x04 L2 name
+     *  +--> authentication
+     * 
+     * L2 = Length(name)
+     * L3/4 = Length(authentication) 
+     * 
+     * Length(BindRequest) = Length(0x60) + Length(L1) + L1
+     *                       + Length(0x02) + 1 + 1
+     *                       + Length(0x04) + Length(L2) + L2 
+     *                       + Length(authentication)
+     */
+    public int computeLength()
+    {
+        int bindRequestLength = 1 + 1 + 1; // Initialized with version
+        
+        // The name
+        bindRequestLength += 1 + Length.getNbBytes( name.getLength() ) + name.getLength();
+        
+        // The authentication
+        bindRequestLength += authentication.computeLength();
+
+        // Return the result.
+        return 1 + Length.getNbBytes( bindRequestLength ) + bindRequestLength;
+    }
+    
     /**
      * Get a String representation of a BindRequest
      *

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindResponse.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindResponse.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindResponse.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindResponse.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,7 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.primitives.OctetString;
 
 /**
@@ -62,6 +63,33 @@
     public void setServerSaslCreds( OctetString serverSaslCreds )
     {
         this.serverSaslCreds = serverSaslCreds;
+    }
+    
+    /**
+     * Compute the BindResponse length
+     * 
+     * BindResponse :
+     * 
+     * 0x61 L1
+     *  |
+     *  +--> LdapResult
+     *  +--> [serverSaslCreds]
+     * 
+     * L1 = Length(LdapResult) [ + Length(serverSaslCreds) ]
+     * 
+     * Length(BindResponse) = Length(0x61) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int ldapResponseLength = super.computeLength();
+        int bindResponseLength = 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
+        
+        if (serverSaslCreds != null)
+        {
+            bindResponseLength += 1 + Length.getNbBytes(serverSaslCreds.getLength()) + serverSaslCreds.getLength();
+        }
+        
+        return bindResponseLength;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareRequest.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareRequest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareRequest.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,7 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
 import org.apache.asn1.primitives.OctetString;
@@ -123,18 +124,58 @@
     }
 
     /**
+     * Compute the CompareRequest length
+     * 
+     * CompareRequest :
+     * 
+     * 0x6E L1 
+     *  |
+     *  +--> 0x04 L2 entry
+     *  +--> 0x30 L3 (ava)
+     *        |
+     *        +--> 0x04 L4 attributeDesc
+     *        +--> 0x04 L5 assertionValue
+     * 
+     * L3 = Length(0x04) + Length(L4) + L4
+     *      + Length(0x04) + Length(L5) + L5
+     * 
+     * Length(CompareRequest) = Length(0x6E) + Length(L1) + L1
+     *                          + Length(0x04) + Length(L2) + L2
+     *                          + Length(0x30) + Length(L3) + L3
+     * @return DOCUMENT ME!
+    */
+    public int computeLength()
+    {
+
+        // The entry
+        int compareRequestLength = 1 + Length.getNbBytes( entry.getLength() ) + entry.getLength();
+
+        // The attribute value assertion
+        int avaLength =
+            1 + Length.getNbBytes( attributeDesc.getLength() ) + attributeDesc.getLength() +
+            1 + Length.getNbBytes( assertionValue.getLength() ) + assertionValue.getLength();
+
+        compareRequestLength += 1 + Length.getNbBytes( avaLength ) + avaLength;
+
+        return 1 + Length.getNbBytes( compareRequestLength ) + compareRequestLength;
+    }
+
+    /**
      * Get a String representation of a Compare Request
      *
      * @return A Compare Request String 
      */
     public String toString()
     {
+
         StringBuffer sb = new StringBuffer();
 
         sb.append( "    Compare request\n" );
         sb.append( "        Entry : '" ).append( entry.toString() ).append( "'\n" );
-        sb.append( "        Attribute description : '" ).append( attributeDesc.toString() ).append( "'\n" );
-        sb.append( "        Attribute value : '" ).append( assertionValue.toString() ).append( "'\n" );
+        sb.append( "        Attribute description : '" ).append( attributeDesc.toString() ).append(
+            "'\n" );
+        sb.append( "        Attribute value : '" ).append( assertionValue.toString() ).append(
+            "'\n" );
 
         return sb.toString();
     }

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareResponse.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareResponse.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareResponse.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareResponse.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
+
 /**
  * An CompareResponse Message. Its syntax is :
  *   CompareResponse ::= [APPLICATION 15] LDAPResult
@@ -35,6 +37,26 @@
     }
 
     //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Compute the CompareResponse length
+     * 
+     * CompareResponse :
+     * 
+     * 0x6F L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(CompareResponse) = Length(0x6F) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int ldapResponseLength = super.computeLength();
+        
+        return 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
+    }
 
     /**
      * Get a String representation of an CompareResponse

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/Control.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/Control.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/Control.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/Control.java Mon Jul 25 15:46:16 2005
@@ -17,6 +17,7 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.primitives.OID;
 import org.apache.asn1.primitives.OctetString;
 
@@ -99,6 +100,45 @@
     public void setCriticality( boolean criticality )
     {
         this.criticality = criticality;
+    }
+
+    /**
+     * Compute the Control length
+     * 
+     * Control :
+     * 
+     * 0x30 L1
+     *  |
+     *  +--> 0x04 L2 controlType
+     * [+--> 0x01 0x01 criticality]
+     * [+--> 0x04 L3 controlValue] 
+     * 
+     * Control length = Length(0x30) + length(L1) 
+     *                  + Length(0x04) + Length(L2) + L2
+     *                  [+ Length(0x01) + 1 + 1]
+     *                  [+ Length(0x04) + Length(L3) + L3]
+     */
+    public int computeLength()
+    {
+        int controlLength = 0;
+
+        // The controlType
+        int controlTypeLengh = controlType.getOIDLength();
+        controlLength = 1 + Length.getNbBytes( controlTypeLengh ) + controlTypeLengh;  
+        
+        // The criticality, only if true
+        if (criticality == true)
+        {
+            controlLength += 1 + 1 + 1; // Always 3 for a boolean
+        }
+        
+        // The control value, if any
+        if (controlValue != null)
+        {
+            controlLength += 1 + Length.getNbBytes( controlValue.getLength() ) + controlValue.getLength();
+        }
+        
+        return 1 + Length.getNbBytes( controlLength ) + controlLength;
     }
     
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelRequest.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelRequest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelRequest.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,7 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 
 
@@ -64,6 +65,23 @@
         this.entry = entry;
     }
 
+    /**
+     * Compute the DelRequest length
+     * 
+     * DelRequest :
+     * 
+     * 0x4A L1 entry
+     * 
+     * L1 = Length(entry)
+     * 
+     * Length(DelRequest) = Length(0x4A) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        // The entry
+        return 1 + Length.getNbBytes( entry.getLength() ) + entry.getLength();
+    }
+    
     /**
      * Return a String representing a DelRequest
      * 

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelResponse.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelResponse.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelResponse.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelResponse.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
+
 /**
  * An DelResponse Message. Its syntax is :
  *   DelResponse ::= [APPLICATION 11] LDAPResult
@@ -32,6 +34,26 @@
     public DelResponse()
     {
         super( );
+    }
+
+    /**
+     * Compute the DelResponse length
+     * 
+     * DelResponse :
+     * 
+     * 0x6B L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(DelResponse) = Length(0x6B) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int ldapResponseLength = super.computeLength();
+        
+        return 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedRequest.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedRequest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedRequest.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,7 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.primitives.OID;
 import org.apache.asn1.primitives.OctetString;
 
@@ -88,6 +89,33 @@
     public void setValue( OctetString value )
     {
         this.value = value;
+    }
+
+    /**
+     * Compute the ExtendedRequest length
+     * 
+     * ExtendedRequest :
+     * 
+     * 0x77 L1
+     *  |
+     *  +--> 0x80 L2 name
+     *  [+--> 0x81 L3 value]
+     * 
+     * L1 = Length(0x80) + Length(L2) + L2
+     *      [+ Length(0x81) + Length(L3) + L3]
+     * 
+     * Length(ExtendedRequest) = Length(0x77) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int extendedRequestLength = 1 + Length.getNbBytes( name.getOIDLength() ) + name.getOIDLength();
+        
+        if ( value != null)
+        {
+            extendedRequestLength += 1 + Length.getNbBytes( value.getLength() ) + value.getLength();
+        }
+        
+        return 1 + Length.getNbBytes( extendedRequestLength ) + extendedRequestLength;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedResponse.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedResponse.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedResponse.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedResponse.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,7 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.primitives.OID;
 import org.apache.asn1.primitives.OctetString;
 
@@ -84,13 +85,51 @@
     /**
      * Set the extended response
      *
-     * @param value The response to set.
+     * @param response The response to set.
      */
     public void setResponse( OctetString response )
     {
         this.response = response;
     }
-    
+
+    /**
+     * Compute the ExtendedResponse length
+     * 
+     * ExtendedResponse :
+     * 
+     * 0x78 L1
+     *  |
+     *  +--> LdapResult
+     * [+--> 0x8A L2 name
+     * [+--> 0x8B L3 response]]
+     * 
+     * L1 = Length(LdapResult)
+     *      [ + Length(0x8A) + Length(L2) + L2
+     *       [ + Length(0x8B) + Length(L3) + L3]]
+     * 
+     * Length(ExtendedResponse) = Length(0x78) + Length(L1) + L1
+     * @return The ExtendedResponse length
+    */
+    public int computeLength()
+    {
+
+        int extendedResponseLength = super.computeLength();
+
+        if ( name != null )
+        {
+            extendedResponseLength += 1 + Length.getNbBytes( name.getOIDLength() ) +
+                name.getOIDLength();
+
+            if ( response != null )
+            {
+                extendedResponseLength += 1 + Length.getNbBytes( response.getLength() ) +
+                    response.getLength();
+            }
+        }
+
+        return 1 + Length.getNbBytes( extendedResponseLength ) + extendedResponseLength;
+    }
+
     /**
      * Get a String representation of an ExtendedResponse
      *
@@ -103,15 +142,15 @@
 
         sb.append( "    Extended Response\n" );
         sb.append( super.toString() );
-        
+
         if ( name != null )
         {
-            sb.append( "        Response name :'").append( name.toString() ).append( "'\n" );
+            sb.append( "        Response name :'" ).append( name.toString() ).append( "'\n" );
         }
 
         if ( response != null )
         {
-            sb.append( "        Response :'").append( response.toString() ).append( "'\n" );
+            sb.append( "        Response :'" ).append( response.toString() ).append( "'\n" );
         }
 
         return sb.toString();

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapMessage.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapMessage.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapMessage.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapMessage.java Mon Jul 25 15:46:16 2005
@@ -23,7 +23,7 @@
 import java.nio.ByteBuffer;
 
 import java.util.ArrayList;
-
+import java.util.Iterator;
 
 /**
  * The main ldapObject : every Ldap Message are encapsulated in it. It contains
@@ -346,6 +346,17 @@
      * - first, we compute the length of each part and the
      *   global PDU length
      * - second, we produce the PDU.
+     * 
+     * 0x30 L1
+     *   |
+     *   +--> 0x02 L2 MessageId (L2 = Length(MessageId)
+     *   +--> ProtocolOp
+     *   +--> Controls
+     * 
+     * L1 = Length(0x02) + Length(L2) + L2 
+     *      + Length(ProtocolOp) + Length(Controls)
+     * 
+     * LdapMessageLength = Length(0x30) + Length(L1) + L1
      *   
      * @param object The encoded PDU
      * @return A ByteBuffer that contaons the PDU
@@ -353,22 +364,89 @@
      */
     public Object encode( Object object ) throws EncoderException
     {
-
-        // Compute the LdapMessage length. It will be the sum of each
-        // element, plus the length of the Length part plus 1 byte for
-        // the tag.
-        int ldapMessageLength = 0;
-
-        // The length of the MessageId.
-        ldapMessageLength += Length.getNbBytes( messageId );
-
-        int protocolOpLength = 0;
-
         // Allocate the bytes buffer.
-        ByteBuffer bb = ByteBuffer.allocate(
-                ldapMessageLength + Length.getNbBytes( protocolOpLength ) + 1 );
+        ByteBuffer bb = ByteBuffer.allocate(computeLength());
 
         return bb;
+    }
+
+    /**
+     * Compute the LdapMessage length
+     * 
+     * LdapMessage :
+     * 
+     * 0x30 L1
+     *  |
+     *  +--> 0x02 0x0(1-4) [0..2^31-1] (MessageId)
+     *  +--> protocolOp
+     * [+--> Controls]
+     * 
+     * MessageId length = Length(0x02) + length(MessageId) + MessageId.length
+     * L1 = length(ProtocolOp)
+     * LdapMessage length = Length(0x30) + Length(L1) + MessageId length + L1
+     */
+    public int computeLength()
+    {
+        // The length of the MessageId. It's the sum of
+        // - the tag (0x02), 1 byte
+        // - the length of the Id length, 1 byte
+        // - the Id length, 1 to 4 bytes
+        int ldapMessageLength = 1 + 1 + Length.getNbBytes(messageId);
+        
+        // Get the protocolOp length
+        int protocolOpLength = protocolOp.computeLength();
+
+        // Add the protocol length to the message length
+        ldapMessageLength += protocolOpLength;
+
+        // Do the same thing for Controls, if any.
+        if (controls != null)
+        {
+            // Controls :
+            // 0x90 L3
+            //  |
+            //  +--> 0x30 L4
+            //        |
+            //        +--> 0x30 L5
+            //        +--> 0x30 L6
+            //        +--> ...
+            //        +--> 0x30 Li
+            //        +--> ...
+            //        +--> 0x30 Ln
+            //
+            // L3 = Length(0x30) + Length(L4) + L4
+            // L4 = Length(0x30) + Length(L5) + L5
+            //      + Length(0x30) + Length(L6) + L6
+            //      + ...
+            //      + Length(0x30) + Length(Li) + Li
+            //      + ...
+            //      + Length(0x30) + Length(Ln) + Ln
+            //
+            // LdapMessageLength = LdapMessageLength + Length(0x90) 
+            //                     + Length(L3) + L3 
+            int controlsSequenceLength = 0;
+            
+            Iterator controlIterator = controls.iterator();
+            
+            // We may have more than one control. ControlsLength is L4.
+            while (controlIterator.hasNext())
+            {
+                controlsSequenceLength += ((Control)controlIterator.next()).computeLength();
+            }
+            
+            // Computes the controls length
+            int controlsLength = 0;
+            
+            controlsLength = 1 + Length.getNbBytes( controlsSequenceLength ) + controlsSequenceLength; 
+                
+            // Now, add the tag and the length of the controls length
+            ldapMessageLength += 1 + Length.getNbBytes( controlsLength ) + controlsLength;
+        }
+        
+        // finally, calculate the global message size :
+        // length(Tag) + Length(length) + length
+        
+        return 1 + ldapMessageLength + Length.getNbBytes(ldapMessageLength);
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapResponse.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapResponse.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapResponse.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapResponse.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,7 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+
 /**
  * A generic LdapResponse Object. It will contain the LdapResult.
  * 
@@ -58,6 +59,18 @@
     public void setLdapResult( LdapResult ldapResult )
     {
         this.ldapResult = ldapResult;
+    }
+    
+    /**
+     * Compute the LdapResponse length
+     * 
+     * LdapResponse :
+     * 
+     * LdapResult
+     */
+    public int computeLength()
+    {
+        return ldapResult.computeLength();
     }
     
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapResult.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapResult.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapResult.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapResult.java Mon Jul 25 15:46:16 2005
@@ -17,11 +17,13 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
 import org.apache.asn1.ldap.codec.primitives.LdapURL;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 
 
 /**
@@ -183,6 +185,67 @@
     public void setResultCode( int resultCode )
     {
         this.resultCode = resultCode;
+    }
+
+    /**
+     * Compute the LdapResult length
+     * 
+     * LdapResult :
+     * 
+     * 0x0A 01 resultCode 	(0..80)
+     * 0x04 L1 matchedDN 	(L1 = Length(matchedDN))
+     * 0x04 L2 errorMessage (L2 = Length(errorMessage))
+     * [0x83 L3] referrals
+     *   |
+     *   +--> 0x04 L4 referral
+     *   +--> 0x04 L5 referral
+     *   +--> ...
+     *   +--> 0x04 Li referral
+     *   +--> ...
+     *   +--> 0x04 Ln referral
+     * 
+     * L1 = Length(matchedDN)
+     * L2 = Length(errorMessage)
+     * L3 = n*Length(0x04) + sum(Length(L4) .. Length(Ln)) + sum(L4..Ln)
+     * L4..n = Length(0x04) + Length(Li) + Li
+     * 
+     * Length(LdapResult) = Length(0x0x0A) + Length(0x01) + 1
+     *                      + Length(0x04) + Length(L1) + L1
+     *                      + Length(0x04) + Length(L2) + L2
+     *                      + Length(0x83) + Length(L3) + L3
+     */
+    public int computeLength()
+    {
+        int ldapResultLength = 0;
+        
+        // The result code : always 3 bytes
+        ldapResultLength = 1 + 1 + 1;
+        
+        // The matchedDN length
+        ldapResultLength += 1 + Length.getNbBytes(matchedDN.getLength()) + matchedDN.getLength(); 
+        
+        // The errorMessage length
+        ldapResultLength += 1 + Length.getNbBytes(errorMessage.getLength()) + errorMessage.getLength(); 
+
+        if ( ( referrals != null ) && ( referrals.size() != 0 ) )
+        {
+            Iterator referralIterator = referrals.iterator();
+            
+            int referralsLength = 0;
+            
+            // Each referral
+            while (referralIterator.hasNext())
+            {
+                LdapURL referral = (LdapURL)referralIterator.next();
+                
+                referralsLength += 1 + Length.getNbBytes(referral.getLength()) + referral.getLength();
+            }
+            
+            // The referrals
+            ldapResultLength += 1 + Length.getNbBytes(referralsLength) + referralsLength;
+        }
+
+        return ldapResultLength;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java Mon Jul 25 15:46:16 2005
@@ -17,6 +17,7 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.RelativeLdapDN;
 
@@ -104,7 +105,7 @@
      */
     public String getNewRDN()
     {
-        return (newRDN == null ? "" : newRDN.toString());
+        return ( ( newRDN == null ) ? "" : newRDN.toString() );
     }
 
     /**
@@ -124,7 +125,7 @@
      */
     public String getNewSuperior()
     {
-        return (newSuperior == null ? "" : newSuperior.toString());
+        return ( ( newSuperior == null ) ? "" : newSuperior.toString() );
     }
 
     /**
@@ -136,7 +137,44 @@
     {
         this.newSuperior = newSuperior;
     }
-    
+
+    /**
+     * Compute the ModifyDNRequest length
+     * 
+     * ModifyDNRequest :
+     * 
+     * 0x6C L1
+     *  |
+     *  +--> 0x04 L2 entry
+     *  +--> 0x04 L3 newRDN
+     *  +--> 0x01 0x01 (true/false) deleteOldRDN (3 bytes)
+     * [+--> 0x80 L4 newSuperior ] 
+     * 
+     * L2 = Length(0x04) + Length(Length(entry)) + Length(entry) 
+     * L3 = Length(0x04) + Length(Length(newRDN)) + Length(newRDN) 
+     * L4 = Length(0x80) + Length(Length(newSuperior)) + Length(newSuperior)
+     * L1 = L2 + L3 + 3 [+ L4] 
+     * 
+     * Length(ModifyDNRequest) = Length(0x6C) + Length(L1) + L1
+     * @return DOCUMENT ME!
+    */
+    public int computeLength()
+    {
+
+        int modifyDNRequestLength =
+            1 + Length.getNbBytes( entry.getLength() ) + entry.getLength() +
+            1 + Length.getNbBytes( newRDN.getLength() ) + newRDN.getLength() +
+            1 + 1 + 1; // deleteOldRDN
+
+        if ( newSuperior != null )
+        {
+            modifyDNRequestLength += 1 + Length.getNbBytes( newSuperior.getLength() ) +
+                newSuperior.getLength();
+        }
+
+        return 1 + Length.getNbBytes( modifyDNRequestLength ) + modifyDNRequestLength;
+    }
+
     /**
      * Get a String representation of a ModifyDNRequest
      *
@@ -151,12 +189,13 @@
         sb.append( "        Entry : '" ).append( entry ).append( "'\n" );
         sb.append( "        New RDN : '" ).append( newRDN.toString() ).append( "'\n" );
         sb.append( "        Delete old RDN : " ).append( deleteOldRDN ).append( "\n" );
-        
+
         if ( newSuperior != null )
         {
-            sb.append( "        New superior : '" ).append( newSuperior.toString() ).append( "'\n" );
+            sb.append( "        New superior : '" ).append( newSuperior.toString() ).append(
+                "'\n" );
         }
 
         return sb.toString();
-    }    
+    }
 }

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNResponse.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNResponse.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNResponse.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNResponse.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
+
 /**
  * An ModifyDNResponse Message. Its syntax is :
  *   ModifyDNResponse ::= [APPLICATION 13] LDAPResult
@@ -32,6 +34,26 @@
     public ModifyDNResponse()
     {
         super( );
+    }
+
+    /**
+     * Compute the ModifyDNResponse length
+     * 
+     * ModifyDNResponse :
+     * 
+     * 0x6D L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(ModifyDNResponse) = Length(0x6D) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int ldapResponseLength = super.computeLength();
+        
+        return 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyRequest.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyRequest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyRequest.java Mon Jul 25 15:46:16 2005
@@ -17,6 +17,7 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
 import org.apache.asn1.primitives.OctetString;
@@ -24,7 +25,9 @@
 import org.apache.log4j.Logger;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 
+import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.BasicAttribute;
@@ -199,6 +202,109 @@
     public void setCurrentOperation( int currentOperation )
     {
         this.currentOperation = currentOperation;
+    }
+
+    /**
+     * Compute the ModifyRequest length
+     * 
+     * ModifyRequest :
+     * 
+     * 0x66 L1
+     *  |
+     *  +--> 0x04 L2 object
+     *  +--> 0x30 L3 modifications
+     *        |
+     *        +--> 0x30 L4-1 modification sequence
+     *        |     |
+     *        |     +--> 0x0A 0x01 (0..2) operation
+     *        |     +--> 0x30 L5-1 modification
+     *        |           |
+     *        |           +--> 0x04 L6-1 type
+     *        |           +--> 0x31 L7-1 vals
+     *        |                 |
+     *        |                 +--> 0x04 L8-1-1 attributeValue
+     *        |                 +--> 0x04 L8-1-2 attributeValue
+     *        |                 +--> ...
+     *        |                 +--> 0x04 L8-1-i attributeValue
+     *        |                 +--> ...
+     *        |                 +--> 0x04 L8-1-n attributeValue
+     *        |
+     *        +--> 0x30 L4-2 modification sequence
+     *        .     |
+     *        .     +--> 0x0A 0x01 (0..2) operation
+     *        .     +--> 0x30 L5-2 modification
+     *                    |
+     *                    +--> 0x04 L6-2 type
+     *                    +--> 0x31 L7-2 vals
+     *                          |
+     *                          +--> 0x04 L8-2-1 attributeValue
+     *                          +--> 0x04 L8-2-2 attributeValue
+     *                          +--> ...
+     *                          +--> 0x04 L8-2-i attributeValue
+     *                          +--> ...
+     *                          +--> 0x04 L8-2-n attributeValue
+     * 
+     * 
+     */
+    public int computeLength()
+    {
+        // Initialized with object
+        int modifyRequestLength = 1 + Length.getNbBytes( object.getLength() ) + object.getLength();
+        
+        // Modifications
+        int modificationsLength = 0;
+        
+        if ( ( modifications != null ) && ( modifications.size() != 0 ) )
+        {
+            Iterator modificationsIterator = modifications.iterator();
+            
+            while ( modificationsIterator.hasNext() )
+            {
+                // Modification sequence length initialized with the operation
+                int modificationSequenceLength = 1 + 1 + 1;
+                
+                ModificationItem modification = (ModificationItem)modificationsIterator.next();
+                
+                // Modification length initialized with the type
+                int typeLength = modification.getAttribute().getID().length();
+                int modificationLength = 1 + Length.getNbBytes( typeLength ) + typeLength;
+                
+                try
+                {
+                    int valuesLength = 0;
+                    
+                    NamingEnumeration values = modification.getAttribute().getAll();
+
+                    // Get all the values
+                    if ( values.hasMoreElements() )
+                    {
+                        while ( values.hasMore() )
+                        {
+                            OctetString value = (OctetString)values.next();
+                            
+                            valuesLength += 1 + Length.getNbBytes( value.getLength() ) + value.getLength();
+                        }
+                    }
+                    
+                    modificationLength += 1 + Length.getNbBytes( valuesLength ) + valuesLength;
+                }
+                catch (NamingException ne)
+                {
+                    continue;
+                }
+                
+                // Compute the modificationSequenceLength
+                modificationSequenceLength += 1 + Length.getNbBytes( modificationLength ) + modificationLength;
+                
+                // Add the tag and the length
+                modificationsLength += 1 + Length.getNbBytes( modificationSequenceLength ) + modificationSequenceLength;
+            }
+            
+            // Add the modifications length to the modificationRequestLength
+            modifyRequestLength += 1 + Length.getNbBytes( modificationsLength ) + modificationsLength;
+        }
+
+        return 1 + Length.getNbBytes( modifyRequestLength ) + modifyRequestLength;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyResponse.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyResponse.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyResponse.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyResponse.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
+
 /**
  * An ModifyResponse Message. Its syntax is :
  *   ModifyResponse ::= [APPLICATION 7] LDAPResult
@@ -32,6 +34,26 @@
     public ModifyResponse()
     {
         super( );
+    }
+
+    /**
+     * Compute the ModifyResponse length
+     * 
+     * ModifyResponse :
+     * 
+     * 0x67 L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(ModifyResponse) = Length(0x67) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int ldapResponseLength = super.computeLength();
+        
+        return 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SaslCredentials.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SaslCredentials.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SaslCredentials.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SaslCredentials.java Mon Jul 25 15:46:16 2005
@@ -17,6 +17,7 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
 import org.apache.asn1.primitives.OctetString;
 
@@ -84,6 +85,32 @@
         this.mechanism = mechanism;
     }
 
+    /**
+     * Compute the Sasl authentication length
+     * 
+     * Sasl authentication :
+     * 
+     * 0x83 L1 mechanism
+     * [0x04 L2 credentials]
+     * 
+     * L1 = Length(mechanism)
+     * L2 = Length(credentials)
+     * 
+     * Length(Sasl authentication) = Length(0x83) + Length(L1) + Length(mechanism)
+     *                               [+ Length(0x04) + Length(L2) + Length(credentials)]
+     */
+    public int computeLength()
+    {
+        int saslLength = 1 + Length.getNbBytes( mechanism.getLength() ) + mechanism.getLength();
+        
+        if (credentials != null)
+        {
+            saslLength += 1 + Length.getNbBytes( credentials.getLength() ) + credentials.getLength();
+        }
+        
+        return saslLength;
+    }
+    
     /**
      * Get a String representation of a SaslCredential
      *

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultDone.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultDone.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultDone.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultDone.java Mon Jul 25 15:46:16 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import org.apache.asn1.ber.tlv.Length;
+
 /**
  * A SearchResultDone Message. Its syntax is :
  *   SearchResultDone ::= [APPLICATION 5] LDAPResult
@@ -36,6 +38,26 @@
         super( );
     }
 
+    /**
+     * Compute the SearchResultDone length
+     * 
+     * SearchResultDone :
+     * 
+     * 0x65 L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(SearchResultDone) = Length(0x65) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int ldapResponseLength = super.computeLength();
+        
+        return 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
+    }
+    
     /**
      * Get a String representation of a SearchResultDone
      *

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultReference.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultReference.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultReference.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultReference.java Mon Jul 25 15:46:16 2005
@@ -17,6 +17,7 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.ldap.codec.primitives.LdapURL;
 
 import java.util.ArrayList;
@@ -65,6 +66,40 @@
     public ArrayList getSearchResultReferences()
     {
         return searchResultReferences;
+    }
+
+    /**
+     * Compute the SearchResultReference length
+     * 
+     * SearchResultReference :
+     * 
+     * 0x73 L1
+     *  |
+     *  +--> 0x04 L2 reference
+     *  +--> 0x04 L3 reference
+     *  +--> ...
+     *  +--> 0x04 Li reference
+     *  +--> ...
+     *  +--> 0x04 Ln reference
+     * 
+     * L1 = n*Length(0x04) + sum(Length(Li)) + sum(Length(reference[i]))
+     * 
+     * Length(SearchResultReference) = Length(0x73 + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int searchResultReferenceLength = 0;
+        
+        Iterator referencesIterator = searchResultReferences.iterator();
+        
+        // We may have more than one reference.
+        while (referencesIterator.hasNext())
+        {
+            int ldapUrlLength = ((LdapURL)referencesIterator.next()).getLength();
+            searchResultReferenceLength += 1 + Length.getNbBytes( ldapUrlLength ) + ldapUrlLength;
+        }
+        
+        return 1 + Length.getNbBytes( searchResultReferenceLength ) + searchResultReferenceLength;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SimpleAuthentication.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SimpleAuthentication.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SimpleAuthentication.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SimpleAuthentication.java Mon Jul 25 15:46:16 2005
@@ -17,6 +17,7 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.primitives.OctetString;
 
 
@@ -54,6 +55,22 @@
         this.simple = simple;
     }
 
+    /**
+     * Compute the Simple authentication length
+     * 
+     * Simple authentication :
+     * 
+     * 0x80 L1 simple
+     * 
+     * L1 = Length(simple)
+     * 
+     * Length(Simple authentication) = Length(0x80) + Length(L1) + Length(simple)
+     */
+    public int computeLength()
+    {
+        return 1 + Length.getNbBytes( simple.getLength() ) + simple.getLength();
+    }
+    
     /**
      * Return the simple authentication as a string
      *

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/UnBindRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/UnBindRequest.java?rev=225197&r1=225196&r2=225197&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/UnBindRequest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/UnBindRequest.java Mon Jul 25 15:46:16 2005
@@ -42,6 +42,18 @@
 
     //~ Methods ------------------------------------------------------------------------------------
     /**
+     * Compute the UnBindRequest length
+     * 
+     * UnBindRequest :
+     * 
+     * 0x42 00
+     */
+    public int computeLength()
+    {
+        return 2; // Always 2
+    }
+    
+    /**
      * Get a String representation of a UnBindRequest
      *
      * @return A UnBindRequest String 



Mime
View raw message