directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r225390 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultEntry.java
Date Tue, 26 Jul 2005 20:50:38 GMT
Author: elecharny
Date: Tue Jul 26 13:50:35 2005
New Revision: 225390

URL: http://svn.apache.org/viewcvs?rev=225390&view=rev
Log:
Added the computeLength() method

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultEntry.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultEntry.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultEntry.java?rev=225390&r1=225389&r2=225390&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultEntry.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultEntry.java
Tue Jul 26 13:50:35 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;
@@ -61,7 +62,7 @@
     private ArrayList partialAttributeList;
 
     /** The attributes list expected length */
-    private transient int partialAttributesListExpectedLength;
+    //private transient int partialAttributesListExpectedLength;
 
     /** The current attribute being decoded */
     private transient Attribute currentAttributeValue;
@@ -127,20 +128,20 @@
      *
      * @return Returns the partialAttributesListExpectedLength.
      */
-    public int getPartialAttributesListExpectedLength()
-    {
-        return partialAttributesListExpectedLength;
-    }
+    //public int getPartialAttributesListExpectedLength()
+    //{
+    //    return partialAttributesListExpectedLength;
+    //}
 
     /**
      * Set the partial attributes list length
      *
      * @param partialAttributesListExpectedLength The partialAttributesListExpectedLength
to set.
      */
-    public void setPartialAttributesListExpectedLength( int partialAttributesListExpectedLength
)
-    {
-        this.partialAttributesListExpectedLength = partialAttributesListExpectedLength;
-    }
+    //public void setPartialAttributesListExpectedLength( int partialAttributesListExpectedLength
)
+    //{
+    //    this.partialAttributesListExpectedLength = partialAttributesListExpectedLength;
+    //}
 
     /**
      * Create a new attributeValue
@@ -162,6 +163,106 @@
         currentAttributeValue.add( value );
     }
 
+    /**
+     * Compute the SearchResultEntry length
+     * 
+     * SearchResultEntry :
+     * 
+     * 0x64 L1
+     *  |
+     *  +--> 0x04 L2 objectName
+     *  +--> 0x30 L3 (attributes)
+     *        |
+     *        +--> 0x30 L4-1 (partial attributes list)
+     *        |     |
+     *        |     +--> 0x04 L5-1 type
+     *        |     +--> 0x31 L6-1 (values)
+     *        |           |
+     *        |           +--> 0x04 L7-1-1 value
+     *        |           +--> ...
+     *        |           +--> 0x04 L7-1-n value
+     *        |
+     *        +--> 0x30 L4-2 (partial attributes list)
+     *        |     |
+     *        |     +--> 0x04 L5-2 type
+     *        |     +--> 0x31 L6-2 (values)
+     *        |           |
+     *        |           +--> 0x04 L7-2-1 value
+     *        |           +--> ...
+     *        |           +--> 0x04 L7-2-n value
+     *        |
+     *        +--> ...
+     *        |
+     *        +--> 0x30 L4-m (partial attributes list)
+     *              |
+     *              +--> 0x04 L5-m type
+     *              +--> 0x31 L6-m (values)
+     *                    |
+     *                    +--> 0x04 L7-m-1 value
+     *                    +--> ...
+     *                    +--> 0x04 L7-m-n value
+     * 
+     */
+    public int computeLength()
+    {
+        int searchResultEntryLength = 0;
+        
+        // The entry
+        searchResultEntryLength += 1 + Length.getNbBytes( objectName.getLength() ) + objectName.getLength();
+        
+        // The attributes sequence
+        int attributesLength = 0;
+        
+        if ( ( partialAttributeList != null ) && ( partialAttributeList.size() !=
0 ) )
+        {
+            Iterator attributeIterator = partialAttributeList.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;
+            }
+        }
+        
+        searchResultEntryLength += 1 + Length.getNbBytes( attributesLength ) + attributesLength;
+
+        // Return the result.
+        return 1 + Length.getNbBytes( searchResultEntryLength ) + searchResultEntryLength;
+    }
+    
     /**
      * Returns the Search Result Entry string
      *



Mime
View raw message