directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r225420 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchRequest.java
Date Tue, 26 Jul 2005 23:39:54 GMT
Author: elecharny
Date: Tue Jul 26 16:39:51 2005
New Revision: 225420

URL: http://svn.apache.org/viewcvs?rev=225420&view=rev
Log:
- added some missing JavaDoc
- added the computeLength() method

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

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchRequest.java?rev=225420&r1=225419&r2=225420&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchRequest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchRequest.java
Tue Jul 26 16:39:51 2005
@@ -17,13 +17,15 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ber.tlv.Value;
 import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
 import org.apache.asn1.ldap.pojo.filters.Filter;
 
 import java.util.ArrayList;
-
+import java.util.Iterator;
 
 /**
  * A SearchRequest ldapObject. It's a sub-class of Asn1Object, and it implements
@@ -270,6 +272,82 @@
         this.currentFilter = currentFilter;
     }
     
+    /**
+     * Compute the SearchRequest length
+     * 
+     * SearchRequest :
+     * 
+     * 0x63 L1
+     *  |
+     *  +--> 0x04 L2 baseObject
+     *  +--> 0x0A 0x01 scope
+     *  +--> 0x0A 0x01 derefAliases
+     *  +--> 0x02 0x0(1..4) sizeLimit
+     *  +--> 0x02 0x0(1..4) timeLimit
+     *  +--> 0x01 0x01 typesOnly
+     *  +--> filter.computeLength()
+     *  +--> 0x30 L3 (Attribute description list)
+     *        |
+     *        +--> 0x04 L4-1 Attribute description 
+     *        +--> 0x04 L4-2 Attribute description 
+     *        +--> ... 
+     *        +--> 0x04 L4-i Attribute description 
+     *        +--> ... 
+     *        +--> 0x04 L4-n Attribute description 
+     * 
+     */
+    public int computeLength()
+    {
+        int searchRequestLength = 0;
+        
+        // The baseObject
+        searchRequestLength += 1 + Length.getNbBytes( baseObject.getLength() ) + baseObject.getLength();
+        
+        // The scope
+        searchRequestLength += 1 + 1 + 1;
+        
+        // The derefAliases
+        searchRequestLength += 1 + 1 + 1;
+        
+        // The sizeLimit
+        searchRequestLength += 1 + 1 + Value.getNbBytes(sizeLimit);
+        
+        // The timeLimit
+        searchRequestLength += 1 + 1 + Value.getNbBytes(timeLimit);
+        
+        // The typesOnly
+        searchRequestLength += 1 + 1 + 1;
+        
+        // The filter
+        searchRequestLength += filter.computeLength();
+        
+        // The attributes description list
+        int attributesLength = 0;
+        
+        if ( ( attributes != null ) && ( attributes.size() != 0 ) )
+        {
+            Iterator attributeIterator = attributes.iterator();
+            
+            // Compute the attributes length
+            while ( attributeIterator.hasNext() )
+            {
+                LdapString attribute = (LdapString)attributeIterator.next();
+                
+                // add the attribute length to the attributes length
+                attributesLength += 1 + Length.getNbBytes( attribute.getLength() ) + attribute.getLength();
+            }
+        }
+        
+        searchRequestLength += 1 + Length.getNbBytes( attributesLength ) + attributesLength;
+
+        // Return the result.
+        return 1 + Length.getNbBytes( searchRequestLength ) + searchRequestLength;
+    }
+    
+    /**
+     * 
+     * @return A string that represent the Filter
+     */
     private String buildFilter()
     {
         if (filter == null)
@@ -288,6 +366,9 @@
         return sb.toString();
     }
     
+    /**
+     * Return a string the represent a SearchRequest
+     */
     public String toString()
     {
         StringBuffer sb = new StringBuffer();



Mime
View raw message