directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r264071 - /directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultEntry.java
Date Mon, 29 Aug 2005 05:29:07 GMT
Author: elecharny
Date: Sun Aug 28 22:29:02 2005
New Revision: 264071

URL: http://svn.apache.org/viewcvs?rev=264071&view=rev
Log:
- switched from ArrayList to Attributes for attributes
- dealt with attribute's values (which may not be OctetString, but String or byte[])
- minor cleaning

Modified:
    directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultEntry.java

Modified: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultEntry.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultEntry.java?rev=264071&r1=264070&r2=264071&view=diff
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultEntry.java
(original)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultEntry.java
Sun Aug 28 22:29:02 2005
@@ -21,21 +21,22 @@
 import org.apache.asn1new.ber.tlv.UniversalTag;
 import org.apache.asn1new.ber.tlv.Value;
 import org.apache.asn1new.primitives.OctetString;
+import org.apache.asn1new.util.StringUtils;
 import org.apache.asn1new.ldap.codec.LdapConstants;
 import org.apache.asn1new.ldap.codec.primitives.LdapDN;
 import org.apache.asn1new.ldap.codec.primitives.LdapString;
 
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
 
 
 /**
@@ -66,10 +67,7 @@
     private LdapDN objectName;
 
     /** The attributes list. It contains javax.naming.directory.Attribute */
-    private ArrayList partialAttributeList;
-
-    /** The attributes list expected length */
-    //private transient int partialAttributesListExpectedLength;
+    private Attributes partialAttributeList;
 
     /** The current attribute being decoded */
     private transient Attribute currentAttributeValue;
@@ -133,12 +131,22 @@
      *
      * @return Returns the partialAttributeList.
      */
-    public ArrayList getPartialAttributeList()
+    public Attributes getPartialAttributeList()
     {
         return partialAttributeList;
     }
 
     /**
+     * Initialize the partial Attribute list.
+     *
+     */
+    public void setPartialAttributeList(Attributes partialAttributeList)
+    {
+
+        this.partialAttributeList = (Attributes)partialAttributeList;
+    }
+
+    /**
      * Initialize the partial Attribute list if needed, otherwise add the current
      * Attribute Value to the list.
      *
@@ -148,31 +156,11 @@
 
         if ( currentAttributeValue == null )
         {
-            partialAttributeList = new ArrayList();
+            partialAttributeList = new BasicAttributes( true );
         }
     }
 
     /**
-     * Get the partial attributes list length
-     *
-     * @return Returns the 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;
-    //}
-
-    /**
      * Create a new attributeValue
      * @param type The attribute's name
      */
@@ -180,7 +168,7 @@
     {
         currentAttributeValue = new BasicAttribute( type.toString().toLowerCase() );
 
-        partialAttributeList.add( currentAttributeValue );
+        partialAttributeList.put( currentAttributeValue );
     }
 
     /**
@@ -242,14 +230,14 @@
         
         if ( ( partialAttributeList != null ) && ( partialAttributeList.size() !=
0 ) )
         {
-            Iterator attributeIterator = partialAttributeList.iterator();
+            NamingEnumeration attributes = partialAttributeList.getAll();
             attributeLength = new LinkedList();
             valsLength = new LinkedList();
             
             // Compute the attributes length
-            while ( attributeIterator.hasNext() )
+            while ( attributes.hasMoreElements() )
             {
-                Attribute attribute = (Attribute)attributeIterator.next();
+                Attribute attribute = (Attribute)attributes.nextElement();
                 int localAttributeLength = 0;
                 int localValuesLength = 0;
                 
@@ -268,9 +256,24 @@
 	                    
 		                while ( values.hasMoreElements() )
 		                {
-		                    OctetString value = (OctetString)values.next();
+		                    Object value = (Object)values.next();
+		                    
+		                    if ( value instanceof String )
+		                    {
+		                    	String stringValue = (String)value;
+	                            localValuesLength += 1 + Length.getNbBytes( stringValue.length()
) + stringValue.getBytes().length;
+		                    }
+		                    else if ( value instanceof OctetString )
+		                    {
+		                    	OctetString octetStringValue = (OctetString)value;
+	                            localValuesLength += 1 + Length.getNbBytes( octetStringValue.getValue().length
) + octetStringValue.getLength();
+		                    }
+		                    else
+		                    {
+		                    	byte[] binaryValue = (byte[])value;
+	                            localValuesLength += 1 + Length.getNbBytes( binaryValue.length
) + binaryValue.length;
+		                    }
 		                    
-                            localValuesLength += 1 + Length.getNbBytes( value.getLength()
) + value.getLength();
 		                }
 
                         localAttributeLength += 1 + Length.getNbBytes( localValuesLength
) + localValuesLength; 
@@ -344,13 +347,13 @@
             // The partial attribute list
             if ( ( partialAttributeList != null ) && ( partialAttributeList.size()
!= 0 ) )
             {
-                Iterator attributeIterator = partialAttributeList.iterator();
+                NamingEnumeration attributes = partialAttributeList.getAll();
                 int attributeNumber = 0;
                 
                 // Compute the attributes length
-                while ( attributeIterator.hasNext() )
+                while ( attributes.hasMoreElements() )
                 {
-                    Attribute attribute = (Attribute)attributeIterator.next();
+                    Attribute attribute = (Attribute)attributes.nextElement();
                     
                     // The partial attribute list sequence
                     buffer.put( UniversalTag.SEQUENCE_TAG );
@@ -373,9 +376,20 @@
                         {
                             while ( values.hasMoreElements() )
                             {
-                                OctetString value = (OctetString)values.next();
+                                Object value = values.next();
                                 
-                                Value.encode( buffer, value );
+                                if ( value instanceof String )
+                                {
+                                	Value.encode( buffer, (String)value );
+                                }
+                                else if ( value instanceof OctetString )
+                                {
+                                	Value.encode( buffer, (OctetString)value );
+                                }
+                                else
+                                {
+                                	Value.encode( buffer, (byte[])value );
+                                }
                             }
                         }
                         
@@ -419,12 +433,12 @@
         else
         {
 
-            Iterator attributesIter = partialAttributeList.iterator();
+            NamingEnumeration attributes = partialAttributeList.getAll();
 
-            while ( attributesIter.hasNext() )
+            while ( attributes.hasMoreElements() )
             {
 
-                Attribute attribute = ( Attribute ) attributesIter.next();
+                Attribute attribute = ( Attribute ) attributes.nextElement();
 
                 sb.append( "            Name : '" ).append( attribute.getID() ).append( "'\n"
);
 
@@ -439,11 +453,19 @@
 
                         while ( values.hasMore() )
                         {
+                        	Object value = values.nextElement();
+                        	sb.append( "                '" );
+                        	
+                        	if ( value instanceof String )
+                        	{
+                        		sb.append( value );
+                        	}
+                        	else
+                        	{
+                        		sb.append( StringUtils.dumpBytes( (byte[])value ) );
+                        	}
 
-                            OctetString value = ( OctetString ) values.next();
-
-                            sb.append( "                '" ).append( value.toString() ).append(
-                                "'\n" );
+                            sb.append("'\n" );
                         }
                     }
                     else



Mime
View raw message