directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r409424 [1/3] - in /directory/trunks: apacheds/core-unit/src/main/java/org/apache/directory/server/core/unit/ apacheds/core/src/main/java/org/apache/directory/server/core/ apacheds/core/src/main/java/org/apache/directory/server/core/configu...
Date Thu, 25 May 2006 18:41:05 GMT
Author: elecharny
Date: Thu May 25 11:41:03 2006
New Revision: 409424

URL: http://svn.apache.org/viewvc?rev=409424&view=rev
Log:
Added Ldif operation and fixed some related pieces of code

Added:
    directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
      - copied unchanged from r409419, directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
Removed:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifIterator.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifIteratorMonitor.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifIteratorMonitorAdapter.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifParser.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifParserImpl.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifParserImplTest.java
Modified:
    directory/trunks/apacheds/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/StartupConfiguration.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java
    directory/trunks/apacheds/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/AbstractBackingStoreTest.java
    directory/trunks/apacheds/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java
    directory/trunks/apacheds/server-main/log4j.properties
    directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
    directory/trunks/apacheds/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixDecoder.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequest.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequest.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/PropertiesUtils.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java

Modified: directory/trunks/apacheds/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/apacheds/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java (original)
+++ directory/trunks/apacheds/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java Thu May 25 11:41:03 2006
@@ -24,6 +24,7 @@
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Hashtable;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.naming.Context;
@@ -36,13 +37,11 @@
 import junit.framework.TestCase;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.exception.NestableRuntimeException;
 import org.apache.directory.server.core.configuration.Configuration;
 import org.apache.directory.server.core.configuration.MutableStartupConfiguration;
 import org.apache.directory.server.core.configuration.ShutdownConfiguration;
-import org.apache.directory.shared.ldap.ldif.LdifIterator;
-import org.apache.directory.shared.ldap.ldif.LdifParserImpl;
-import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
+import org.apache.directory.shared.ldap.ldif.Entry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
 
 
 /**
@@ -53,12 +52,24 @@
  */
 public abstract class AbstractTestCase extends TestCase
 {
-    public static final String LDIF = "dn: uid=akarasulu,ou=users,ou=system\n" + "cn: Alex Karasulu\n"
-        + "sn: Karasulu\n" + "givenname: Alex\n" + "objectclass: top\n" + "objectclass: person\n"
-        + "objectclass: organizationalPerson\n" + "objectclass: inetOrgPerson\n" + "ou: Engineering\n" + "ou: People\n"
-        + "l: Bogusville\n" + "uid: akarasulu\n" + "mail: akarasulu@apache.org\n"
-        + "telephonenumber: +1 408 555 4798\n" + "facsimiletelephonenumber: +1 408 555 9751\n" + "roomnumber: 4612\n"
-        + "userpassword: test\n";
+    public static final String LDIF = 
+    	"dn: uid=akarasulu,ou=users,ou=system\n" + 
+    	"cn: Alex Karasulu\n" +
+        "sn: Karasulu\n" + 
+        "givenname: Alex\n" + 
+        "objectclass: top\n" + 
+        "objectclass: person\n" +
+        "objectclass: organizationalPerson\n" + 
+        "objectclass: inetOrgPerson\n" + 
+        "ou: Engineering\n" + 
+        "ou: People\n" +
+        "l: Bogusville\n" + 
+        "uid: akarasulu\n" + 
+        "mail: akarasulu@apache.org\n" +
+        "telephonenumber: +1 408 555 4798\n" + 
+        "facsimiletelephonenumber: +1 408 555 9751\n" + 
+        "roomnumber: 4612\n" +
+        "userpassword: test\n";
 
     private final String username;
 
@@ -136,17 +147,13 @@
         // Add a single test entry
         // -------------------------------------------------------------------
 
-        Attributes attributes = new LockableAttributesImpl();
-        LdifParserImpl parser = new LdifParserImpl();
-        try
-        {
-            parser.parse( attributes, LDIF );
-        }
-        catch ( NamingException e )
-        {
-            throw new NestableRuntimeException( e );
-        }
-        testEntries.add( attributes );
+        LdifReader reader = new LdifReader();
+        
+    	List entries = reader.parseLdif( LDIF );
+        
+        Entry entry = (Entry)entries.get(0);
+
+        testEntries.add( entry );
 
         // -------------------------------------------------------------------
         // Add more from an optional LDIF file if they exist
@@ -177,13 +184,13 @@
 
         if ( in != null )
         {
-            LdifIterator list = new LdifIterator( in );
+            Iterator list = new LdifReader( in );
+            
             while ( list.hasNext() )
             {
-                String ldif = ( String ) list.next();
-                attributes = new LockableAttributesImpl();
-                parser.parse( attributes, ldif );
-                testEntries.add( attributes );
+                entry = ( Entry ) list.next();
+                
+                testEntries.add( entry );
             }
         }
 

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Thu May 25 11:41:03 2006
@@ -48,6 +48,7 @@
 import org.apache.directory.shared.ldap.exception.LdapAuthenticationNotSupportedException;
 import org.apache.directory.shared.ldap.exception.LdapConfigurationException;
 import org.apache.directory.shared.ldap.exception.LdapNoPermissionException;
+import org.apache.directory.shared.ldap.ldif.Entry;
 import org.apache.directory.shared.ldap.message.LockableAttributeImpl;
 import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
@@ -670,17 +671,25 @@
         Iterator i = startupConfiguration.getTestEntries().iterator();
         while ( i.hasNext() )
         {
-            Attributes entry = ( Attributes ) ( ( Attributes ) i.next() ).clone();
-            String dn = ( String ) entry.remove( "dn" ).get();
-
-            try
-            {
-                ctx.createSubcontext( dn, entry );
-            }
-            catch ( Exception e )
-            {
-                log.warn( dn + " test entry already exists.", e );
-            }
+        	try
+        	{
+	        	Entry entry =  (Entry)( ( Entry ) i.next() ).clone();
+	            Attributes attributes = entry.getAttributes();
+	            String dn = entry.getDn();
+
+	            try
+	            {
+	                ctx.createSubcontext( dn, attributes );
+	            }
+	            catch ( Exception e )
+	            {
+	                log.warn( dn + " test entry already exists.", e );
+	            }
+        	}
+        	catch ( CloneNotSupportedException cnse )
+        	{
+                log.warn( "Cannot clone the entry ", cnse );
+        	}
         }
     }
 

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java Thu May 25 11:41:03 2006
@@ -18,9 +18,11 @@
  */
 package org.apache.directory.server.core.configuration;
 
-
 import java.beans.PropertyEditor;
 import java.beans.PropertyEditorSupport;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
 import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
@@ -35,17 +37,16 @@
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.shared.ldap.ldif.LdifComposer;
 import org.apache.directory.shared.ldap.ldif.LdifComposerImpl;
-import org.apache.directory.shared.ldap.ldif.LdifParser;
-import org.apache.directory.shared.ldap.ldif.LdifParserImpl;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.util.MultiMap;
-
+import org.apache.directory.shared.ldap.util.StringTools;
 
 /**
- * A JavaBeans {@link PropertyEditor} that can convert {@link Attributes}
- * to LDIF string and vice versa.  This class is useful when you're going
- * to configure a {@link DirectoryService} with 3rd party containers
- * such as <a href="http://www.springframework.org/">Spring Framework</a>.
- *
+ * A JavaBeans {@link PropertyEditor} that can convert {@link Attributes} to
+ * LDIF string and vice versa. This class is useful when you're going to
+ * configure a {@link DirectoryService} with 3rd party containers such as <a
+ * href="http://www.springframework.org/">Spring Framework</a>.
+ * 
  * @author The Apache Directory Project
  * @version $Rev$, $Date$
  */
@@ -60,16 +61,14 @@
         super();
     }
 
-
     /**
      * Creates a new instance with source object.
      */
-    public AttributesPropertyEditor(Object source)
+    public AttributesPropertyEditor( Object source )
     {
         super( source );
     }
 
-
     /**
      * Returns LDIF string of {@link Attributes} object.
      */
@@ -81,92 +80,79 @@
             // FIXME Stop forking commons-collections.
             private final MultiHashMap map = new MultiHashMap();
 
-
             public Object remove( Object arg0, Object arg1 )
             {
                 return map.remove( arg0, arg1 );
             }
 
-
             public int size()
             {
                 return map.size();
             }
 
-
             public Object get( Object arg0 )
             {
                 return map.get( arg0 );
             }
 
-
             public boolean containsValue( Object arg0 )
             {
                 return map.containsValue( arg0 );
             }
 
-
             public Object put( Object arg0, Object arg1 )
             {
                 return map.put( arg0, arg1 );
             }
 
-
             public Object remove( Object arg0 )
             {
                 return map.remove( arg0 );
             }
 
-
             public Collection values()
             {
                 return map.values();
             }
 
-
             public boolean isEmpty()
             {
                 return map.isEmpty();
             }
 
-
             public boolean containsKey( Object key )
             {
                 return map.containsKey( key );
             }
 
-
             public void putAll( Map arg0 )
             {
                 map.putAll( arg0 );
             }
 
-
             public void clear()
             {
                 map.clear();
             }
 
-
             public Set keySet()
             {
                 return map.keySet();
             }
 
-
             public Set entrySet()
             {
                 return map.entrySet();
             }
         };
 
-        Attributes attrs = ( Attributes ) getValue();
+        Attributes attrs = (Attributes) getValue();
         try
         {
             NamingEnumeration e = attrs.getAll();
             while ( e.hasMore() )
             {
-                Attribute attr = ( Attribute ) e.next();
+                Attribute attr = (Attribute) e.next();
                 NamingEnumeration e2 = attr.getAll();
                 while ( e2.hasMoreElements() )
                 {
@@ -177,12 +163,71 @@
 
             return composer.compose( map );
         }
-        catch ( Exception e )
+        catch (Exception e)
         {
             throw new ConfigurationException( e );
         }
     }
 
+    /**
+     * Read an entry (without DN)
+     * 
+     * @param text
+     *            The ldif format file
+     * @return An Attributes.
+     */
+    private Attributes readEntry( String text )
+    {
+        StringReader strIn = new StringReader( text );
+        BufferedReader in = new BufferedReader( strIn );
+
+        String line = null;
+        Attributes attributes = new BasicAttributes( true );
+
+        try
+        {
+            while ( ( line = ( (BufferedReader) in ).readLine() ) != null )
+            {
+                if ( line.length() == 0 )
+                {
+                    continue;
+                }
+
+                String addedLine = line.trim();
+
+                if ( StringTools.isEmpty( addedLine ) )
+                {
+                    continue;
+                }
+
+                Attribute attribute = LdifReader.parseAttributeValue( addedLine );
+                Attribute oldAttribute = attributes.get( attribute.getID() );
+
+                if ( oldAttribute != null )
+                {
+                    try
+                    {
+                        oldAttribute.add( attribute.get() );
+                        attributes.put( oldAttribute );
+                    }
+                    catch (NamingException ne)
+                    {
+                        // Do nothing
+                    }
+                }
+                else
+                {
+                    attributes.put( attribute );
+                }
+            }
+        }
+        catch (IOException ioe)
+        {
+            // Do nothing : we can't reach this point !
+        }
+
+        return attributes;
+    }
 
     /**
      * Converts the specified LDIF string into {@link Attributes}.
@@ -194,16 +239,6 @@
             text = "";
         }
 
-        Attributes attrs = new BasicAttributes( true );
-        LdifParser parser = new LdifParserImpl();
-        try
-        {
-            parser.parse( attrs, text.trim() );
-            setValue( attrs );
-        }
-        catch ( NamingException e )
-        {
-            throw ( IllegalArgumentException ) new IllegalArgumentException().initCause( e );
-        }
+        setValue( readEntry( text ) );
     }
 }

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java Thu May 25 11:41:03 2006
@@ -28,6 +28,8 @@
 
 import javax.naming.directory.Attributes;
 
+import org.apache.directory.shared.ldap.ldif.Entry;
+
 
 /**
  * A utility class that provides common functionality while validating configuration.
@@ -105,13 +107,14 @@
     /**
      * Returns the deep clone of the specified {@link Attributes} list.
      */
-    public static List getClonedAttributesList( List list )
+    public static List getClonedAttributesList( List list ) throws CloneNotSupportedException
     {
         List newList = new ArrayList();
         Iterator i = list.iterator();
+        
         while ( i.hasNext() )
         {
-            newList.add( ( ( Attributes ) i.next() ).clone() );
+            newList.add( ( ( Entry ) i.next() ).clone() );
         }
         return newList;
     }

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/StartupConfiguration.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/StartupConfiguration.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/StartupConfiguration.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/StartupConfiguration.java Thu May 25 11:41:03 2006
@@ -44,6 +44,7 @@
 import org.apache.directory.server.core.schema.bootstrap.*;
 import org.apache.directory.server.core.subtree.SubentryService;
 import org.apache.directory.server.core.trigger.TriggerService;
+import org.apache.directory.shared.ldap.ldif.Entry;
 
 
 /**
@@ -372,7 +373,14 @@
      */
     public List getTestEntries()
     {
-        return ConfigurationUtil.getClonedAttributesList( testEntries );
+    	try
+    	{
+    		return ConfigurationUtil.getClonedAttributesList( testEntries );
+    	}
+    	catch ( CloneNotSupportedException cnse )
+    	{
+    		return null;
+    	}
     }
 
 
@@ -382,20 +390,17 @@
      */
     protected void setTestEntries( List testEntries )
     {
-        testEntries = ConfigurationUtil.getClonedAttributesList( ConfigurationUtil.getTypeSafeList( testEntries,
-            Attributes.class ) );
-
-        Iterator i = testEntries.iterator();
-        while ( i.hasNext() )
-        {
-            Attributes entry = ( Attributes ) i.next();
-            if ( entry.get( "dn" ) == null )
-            {
-                throw new ConfigurationException( "Test entries must have DN attributes" );
-            }
-        }
-
-        this.testEntries = testEntries;
+    	try
+    	{
+	        testEntries = ConfigurationUtil.getClonedAttributesList( ConfigurationUtil.getTypeSafeList( testEntries,
+	            Entry.class ) );
+	
+	        this.testEntries = testEntries;
+    	}
+    	catch ( CloneNotSupportedException cnse )
+    	{
+    		this.testEntries = null;
+    	}
     }
 
 

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java Thu May 25 11:41:03 2006
@@ -26,7 +26,6 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
-import java.io.IOException;
 import java.math.BigInteger;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -67,11 +66,9 @@
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.FilterParser;
 import org.apache.directory.shared.ldap.filter.FilterParserImpl;
-import org.apache.directory.shared.ldap.ldif.LdifIterator;
-import org.apache.directory.shared.ldap.ldif.LdifParser;
-import org.apache.directory.shared.ldap.ldif.LdifParserImpl;
+import org.apache.directory.shared.ldap.ldif.Entry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.message.DerefAliasesEnum;
-import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
 import org.apache.directory.shared.ldap.name.LdapName;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -427,8 +424,6 @@
     public void doImport()
     {
         FileReader in = null;
-        LdifIterator list = null;
-        LdifParser parser = new LdifParserImpl();
         JFileChooser chooser = new JFileChooser();
         int choice = chooser.showOpenDialog( this );
         File selected = chooser.getSelectedFile();
@@ -441,16 +436,15 @@
         try
         {
             in = new FileReader( selected );
-            list = new LdifIterator( in );
+            Iterator list = new LdifReader( in );
 
             while ( list.hasNext() )
             {
-                String dif = ( String ) list.next();
-                LockableAttributesImpl attrs = new LockableAttributesImpl();
-                parser.parse( attrs, dif );
-                String updn = ( String ) attrs.get( "dn" ).get();
+                Entry entry = ( Entry ) list.next();
+                String updn = entry.getDn();
+                Attributes attrs = entry.getAttributes();
+                
                 LdapName ndn = new LdapName( StringTools.deepTrimToLower( updn ) );
-                attrs.remove( "dn" );
 
                 if ( null == partition.getEntryId( ndn.toString() ) )
                 {
@@ -466,12 +460,6 @@
             return;
         }
         catch ( FileNotFoundException e )
-        {
-            // @todo display popup with error here!
-            e.printStackTrace();
-            return;
-        }
-        catch ( IOException e )
         {
             // @todo display popup with error here!
             e.printStackTrace();

Modified: directory/trunks/apacheds/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/AbstractBackingStoreTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/AbstractBackingStoreTest.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/AbstractBackingStoreTest.java (original)
+++ directory/trunks/apacheds/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/AbstractBackingStoreTest.java Thu May 25 11:41:03 2006
@@ -26,6 +26,7 @@
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Hashtable;
+import java.util.Iterator;
 import java.util.Properties;
 import java.util.Set;
 
@@ -56,9 +57,8 @@
 import org.apache.directory.server.core.schema.bootstrap.Krb5kdcSchema;
 import org.apache.directory.server.core.schema.bootstrap.SystemSchema;
 import org.apache.directory.server.protocol.shared.store.KerberosAttribute;
-import org.apache.directory.shared.ldap.ldif.LdifIterator;
-import org.apache.directory.shared.ldap.ldif.LdifParser;
-import org.apache.directory.shared.ldap.ldif.LdifParserImpl;
+import org.apache.directory.shared.ldap.ldif.Entry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.message.LockableAttributeImpl;
 import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
 import org.slf4j.Logger;
@@ -298,18 +298,14 @@
         {
             InputStream in = getLdifStream( ldifPath );
 
-            LdifIterator iterator = new LdifIterator( in );
-
-            LdifParser ldifParser = new LdifParserImpl();
+            Iterator iterator = new LdifReader( in );
 
             while ( iterator.hasNext() )
             {
-                String ldif = ( String ) iterator.next();
-
-                Attributes attributes = new LockableAttributesImpl();
-                ldifParser.parse( attributes, ldif );
+                Entry entry = ( Entry ) iterator.next();
 
-                String dn = ( String ) attributes.remove( "dn" ).get();
+                String dn = entry.getDn();
+                Attributes attributes = entry.getAttributes();
 
                 if ( attributes.get( "objectClass" ).contains( "krb5KDCEntry" ) )
                 {
@@ -347,11 +343,6 @@
             log.error( "LDIF file does not exist." );
             return;
         }
-        catch ( IOException ioe )
-        {
-            log.error( "Failed to import LDIF into backing store.", ioe );
-            return;
-        }
         catch ( NamingException ne )
         {
             log.error( "Failed to import LDIF into backing store.", ne );
@@ -362,19 +353,13 @@
         {
             InputStream in = getLdifStream( ldifPath );
 
-            LdifIterator iterator = new LdifIterator( in );
-
-            LdifParser ldifParser = new LdifParserImpl();
+            Iterator iterator = new LdifReader( in );
 
             while ( iterator.hasNext() )
             {
-                String ldif = ( String ) iterator.next();
-
-                Attributes attributes = new LockableAttributesImpl();
-
-                ldifParser.parse( attributes, ldif );
+                Entry entry = ( Entry ) iterator.next();
 
-                String dn = ( String ) attributes.remove( "dn" ).get();
+                String dn = entry.getDn();
 
                 rdn = getRelativeName( ctx.getNameInNamespace(), dn );
 

Modified: directory/trunks/apacheds/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java (original)
+++ directory/trunks/apacheds/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java Thu May 25 11:41:03 2006
@@ -17,10 +17,12 @@
 package org.apache.directory.server.protocol.shared.store;
 
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
@@ -31,10 +33,9 @@
 import javax.naming.directory.Attributes;
 import javax.naming.directory.DirContext;
 
-import org.apache.directory.shared.ldap.ldif.LdifIterator;
-import org.apache.directory.shared.ldap.ldif.LdifParser;
-import org.apache.directory.shared.ldap.ldif.LdifParserImpl;
-import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
+import org.apache.directory.shared.ldap.ldif.Entry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,7 +44,6 @@
  * Support for commands to load an LDIF file into a DirContext.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
  */
 public class LdifFileLoader
 {
@@ -146,16 +146,21 @@
         try
         {
             in = getLdifStream();
-            LdifIterator iterator = new LdifIterator( in );
-            LdifParser ldifParser = new LdifParserImpl();
+            LdifReader ldifIterator = new LdifReader( new BufferedReader( new InputStreamReader( in ) ) );
 
-            while ( iterator.hasNext() )
+            while ( ldifIterator.hasNext() )
             {
-                String ldif = ( String ) iterator.next();
-                Attributes attributes = new LockableAttributesImpl();
-                ldifParser.parse( attributes, ldif );
-                String dn = ( String ) attributes.remove( "dn" ).get();
+                Entry entry = ( Entry ) ldifIterator.next();
+                
+                String dn = entry.getDn();
+                
+                if ( entry.isEntry() == false)
+                {
+                	// If the entry is a modification, just skip it
+                	continue;
+                }
 
+                Attributes attributes = entry.getAttributes();
                 boolean filterAccepted = applyFilters( dn, attributes );
 
                 if ( !filterAccepted )

Modified: directory/trunks/apacheds/server-main/log4j.properties
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-main/log4j.properties?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/apacheds/server-main/log4j.properties (original)
+++ directory/trunks/apacheds/server-main/log4j.properties Thu May 25 11:41:03 2006
@@ -1,12 +1,11 @@
-log4j.rootCategory=WARN, stdout
+log4j.rootCategory=DEBUG, stdout
 
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
 
 # with these we'll not get innundated when switching to DEBUG
-log4j.logger.org.apache.directory.shared.ldap.name=WARN
+#log4j.logger.org.apache.directory.shared.ldap.name=WARN
 log4j.logger.org.springframework=WARN
-log4j.logger.org.apache.directory.shared.codec=WARN
-log4j.logger.org.apache.directory.shared.asn1=WARN
+log4j.logger.org.apache.directory.shared.ldap.codec.TwixDecoder=DEBUG
 

Modified: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java (original)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java Thu May 25 11:41:03 2006
@@ -16,19 +16,23 @@
  */
 package org.apache.directory.server.tools;
 
-
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.cli.AlreadySelectedException;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.MissingArgumentException;
+import org.apache.commons.cli.MissingOptionException;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
-
+import org.apache.commons.cli.UnrecognizedOptionException;
 
 /**
  * The primary command base class.
@@ -39,31 +43,49 @@
 public class BaseCommand
 {
     private Map commands = new HashMap();
+
+    private List commandsOrdered = new ArrayList();
+
     private Options global = new Options();
+
     private String productCommand;
+
     private String productVersion;
+
     private String productDisplayName;
+
     private String productUrl;
+
     private String productBanner;
-    
-    
+
     public BaseCommand()
     {
         init();
     }
-    
-    
+
     protected void init()
     {
         ToolCommand command;
+
+        command = new DiagnosticCommand();
+        commands.put( command.getName(), command );
+        commandsOrdered.add( command.getName() );
+
         command = new DumpCommand();
-        getCommands().put( command.getName(), command );
+        commands.put( command.getName(), command );
+        commandsOrdered.add( command.getName() );
+
         command = new GracefulShutdownCommand();
-        getCommands().put( command.getName(), command );
-        command = new DiagnosticCommand();
-        getCommands().put( command.getName(), command );
+        commands.put( command.getName(), command );
+        commandsOrdered.add( command.getName() );
+
+        command = new ImportCommand();
+        commands.put( command.getName(), command );
+        commandsOrdered.add( command.getName() );
+
         command = new DisconnectNotificationCommand();
-        getCommands().put( command.getName(), command );
+        commands.put( command.getName(), command );
+        commandsOrdered.add( command.getName() );
 
         Option op = new Option( "i", "install-path", true, "path to installation directory" );
         getGlobal().addOption( op );
@@ -80,8 +102,7 @@
         op = new Option( "version", false, "print the version information and exit" );
         getGlobal().addOption( op );
     }
-    
-    
+
     public static boolean hasBannerOption( String[] args )
     {
         for ( int ii = 0; ii < args.length; ii++ )
@@ -94,7 +115,6 @@
         return false;
     }
 
-
     public CommandLine getCommandLine( String command, String[] args )
     {
         Options all = allOptions( command );
@@ -104,15 +124,38 @@
         {
             cmdline = parser.parse( all, args );
         }
-        catch ( ParseException e )
+        catch (AlreadySelectedException ase)
+        {
+            System.err.println( "Command line parsing failed for " + command + ".  Reason: already selected "
+                    + ase.getMessage() );
+            System.exit( 1 );
+        }
+        catch (MissingArgumentException mae)
+        {
+            System.err.println( "Command line parsing failed for " + command + ".  Reason: missing argument "
+                    + mae.getMessage() );
+            System.exit( 1 );
+        }
+        catch (MissingOptionException moe)
+        {
+            System.err.println( "Command line parsing failed for " + command + ".  Reason: missing option " + moe.getMessage() );
+            System.exit( 1 );
+        }
+        catch (UnrecognizedOptionException uoe)
         {
-            System.err.println( "Command line parsing failed for " + command + ".  Reason: " + e.getMessage() );
+            System.err.println( "Command line parsing failed for " + command + ".  Reason: unrecognized option"
+                    + uoe.getMessage() );
             System.exit( 1 );
         }
+        catch (ParseException pe)
+        {
+            System.err.println( "Command line parsing failed for " + command + ".  Reason: " + pe.getClass() );
+            System.exit( 1 );
+        }
+
         return cmdline;
     }
 
-
     public Options allOptions( String command )
     {
         if ( command.equals( "help" ) )
@@ -121,20 +164,20 @@
         }
 
         Options all = new Options();
-        ToolCommand cmd = ( ToolCommand ) getCommands().get( command );
+        ToolCommand cmd = (ToolCommand) getCommands().get( command );
+
         for ( Iterator ii = getGlobal().getOptions().iterator(); ii.hasNext(); )
         {
-            all.addOption( ( Option ) ii.next() );
+            all.addOption( (Option) ii.next() );
         }
 
         for ( Iterator ii = cmd.getOptions().getOptions().iterator(); ii.hasNext(); )
         {
-            all.addOption( ( Option ) ii.next() );
+            all.addOption( (Option) ii.next() );
         }
         return all;
     }
 
-
     public static void dumpArgs( String msg, String[] args )
     {
         if ( args.length == 0 )
@@ -146,6 +189,7 @@
 
         StringBuffer buf = new StringBuffer();
         buf.append( msg ).append( "\n" );
+
         for ( int ii = 0; ii < args.length; ii++ )
         {
             buf.append( "\targs[" + ii + "] = " ).append( args[ii] ).append( "\n" );
@@ -153,7 +197,6 @@
         System.out.println( buf );
     }
 
-
     public void helpOnCommand( String command )
     {
         if ( command.equals( "help" ) )
@@ -161,11 +204,12 @@
             printUsage();
             System.exit( 0 );
         }
+
         if ( getCommands().containsKey( command ) )
         {
-            ToolCommand cmd = ( ToolCommand ) getCommands().get( command );
+            ToolCommand cmd = (ToolCommand) getCommands().get( command );
             HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(  getProductCommand() + " " + cmd + " [options]", cmd.getOptions() );
+            formatter.printHelp( getProductCommand() + " " + cmd + " [options]", cmd.getOptions() );
         }
         else
         {
@@ -174,15 +218,16 @@
         }
     }
 
-
     public void printUsage()
     {
         HelpFormatter formatter = new HelpFormatter();
-        formatter.printHelp( getProductCommand() + " <command> [options]", "\nGlobal options:", getGlobal(),
-            "\nType \"" + getProductCommand() + " help <command>\" for help on a command." );
-        System.out.println( "\nAvalable commands:" );
-        Iterator it = getCommands().values().iterator();
+        formatter.printHelp( getProductCommand() + " <command> [options]", "\nGlobal options:", getGlobal(), "\nType \""
+                + getProductCommand() + " help <command>\" for help on a command." );
+        System.out.println( "\nAvailable commands:" );
+
+        Iterator it = commandsOrdered.iterator();
         System.out.println( "\thelp" );
+
         while ( it.hasNext() )
         {
             System.out.println( "\t" + it.next() );
@@ -193,96 +238,81 @@
     }
 
     static final String BANNER = "       _                     _          ____  ____    _____           _      \n"
-        + "      / \\   _ __   __ _  ___| |__   ___|  _ \\/ ___|  |_   _|__   ___ | |___  \n"
-        + "     / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ | | \\___ \\    | |/ _ \\ / _ \\| / __| \n"
-        + "    / ___ \\| |_) | (_| | (__| | | |  __/ |_| |___) |   | | (_) | (_) | \\__ \\ \n"
-        + "   /_/   \\_\\ .__/ \\__,_|\\___|_| |_|\\___|____/|____/    |_|\\___/ \\___/|_|___/ \n"
-        + "           |_|                                                               \n";
-
+            + "      / \\   _ __   __ _  ___| |__   ___|  _ \\/ ___|  |_   _|__   ___ | |___  \n"
+            + "     / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ | | \\___ \\    | |/ _ \\ / _ \\| / __| \n"
+            + "    / ___ \\| |_) | (_| | (__| | | |  __/ |_| |___) |   | | (_) | (_) | \\__ \\ \n"
+            + "   /_/   \\_\\ .__/ \\__,_|\\___|_| |_|\\___|____/|____/    |_|\\___/ \\___/|_|___/ \n"
+            + "           |_|                                                               \n";
 
     public void printBanner()
     {
         System.out.println( getProductBanner() );
     }
 
-
     public void setProductCommand( String productCommand )
     {
         this.productCommand = productCommand;
     }
 
-
     public String getProductCommand()
     {
         return productCommand;
     }
 
-
     public void setProductVersion( String productVersion )
     {
         this.productVersion = productVersion;
     }
 
-
     public String getProductVersion()
     {
         return productVersion;
     }
 
-
     public void setProductDisplayName( String productDisplayName )
     {
         this.productDisplayName = productDisplayName;
     }
 
-
     public String getProductDisplayName()
     {
         return productDisplayName;
     }
 
-
     public void setProductUrl( String productUrl )
     {
         this.productUrl = productUrl;
     }
 
-
     public String getProductUrl()
     {
         return productUrl;
     }
 
-
     public void setProductBanner( String productBanner )
     {
         this.productBanner = productBanner;
     }
 
-
     public String getProductBanner()
     {
         return productBanner;
     }
 
-
     public void setCommands( Map commands )
     {
         this.commands = commands;
     }
 
-
     public Map getCommands()
     {
         return commands;
     }
 
-
     public void setGlobal( Options global )
     {
         this.global = global;
     }
-
 
     public Options getGlobal()
     {

Modified: directory/trunks/apacheds/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/apacheds/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java (original)
+++ directory/trunks/apacheds/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java Thu May 25 11:41:03 2006
@@ -21,12 +21,12 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Hashtable;
+import java.util.Iterator;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.Name;
 import javax.naming.NamingException;
-import javax.naming.directory.Attributes;
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 
@@ -37,10 +37,8 @@
 import org.apache.directory.server.core.configuration.ShutdownConfiguration;
 import org.apache.directory.server.jndi.ServerContextFactory;
 import org.apache.directory.shared.ldap.exception.LdapConfigurationException;
-import org.apache.directory.shared.ldap.ldif.LdifIterator;
-import org.apache.directory.shared.ldap.ldif.LdifParser;
-import org.apache.directory.shared.ldap.ldif.LdifParserImpl;
-import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
+import org.apache.directory.shared.ldap.ldif.Entry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.name.LdapName;
 import org.apache.mina.util.AvailablePortFinder;
 
@@ -181,19 +179,19 @@
         Hashtable env = new Hashtable();
         env.putAll( sysRoot.getEnvironment() );
         LdapContext ctx = new InitialLdapContext( env, null );
-        LdifParser parser = new LdifParserImpl();
 
         try
         {
-            LdifIterator iterator = new LdifIterator( in );
+            Iterator iterator = new LdifReader( in );
+            
             while ( iterator.hasNext() )
             {
-                Attributes attributes = new LockableAttributesImpl();
-                String ldif = ( String ) iterator.next();
-                parser.parse( attributes, ldif );
-                Name dn = new LdapName( ( String ) attributes.remove( "dn" ).get() );
+                Entry entry = ( Entry) iterator.next();
+
+                Name dn = new LdapName( entry.getDn() );
                 dn.remove( 0 );
-                ctx.createSubcontext( dn, attributes );
+
+                ctx.createSubcontext( dn, entry.getAttributes() );
             }
         }
         catch ( Exception e )

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixDecoder.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixDecoder.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixDecoder.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixDecoder.java Thu May 25 11:41:03 2006
@@ -62,6 +62,7 @@
     public void decode( Object encoded ) throws DecoderException
     {
         ByteBuffer buf;
+        int position = 0;
 
         if ( encoded instanceof ByteBuffer )
         {
@@ -77,42 +78,47 @@
                 + encoded.getClass() );
         }
 
-        if ( log.isDebugEnabled() )
+        while ( buf.hasRemaining() )
         {
-            log.debug( "Decoding the PDU : " );
 
-            if ( buf.hasArray() )
-            {
-                log.debug( StringTools.dumpBytes( buf.array() ) );
-            }
-            else
-            {
-                byte[] array = new byte[buf.capacity()];
-                int i = 0;
+            ldapDecoder.decode( buf, ldapMessageContainer );
 
-                while ( buf.hasRemaining() )
-                {
-                    array[i++] = buf.get();
-                }
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "Decoding the PDU : " );
 
+                int size = buf.position();
                 buf.flip();
+                
+            	byte[] array = new byte[ size - position ];
+            	
+            	for ( int i = position; i < size; i++ )
+            	{
+            		array[ i ] = buf.get();
+            	}
+
+                position = size;
+                
                 log.debug( StringTools.dumpBytes( array ) );
             }
-        }
-
-        while ( buf.hasRemaining() )
-        {
-            ldapDecoder.decode( buf, ldapMessageContainer );
-
+            
             if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
             {
                 if ( log.isDebugEnabled() )
                 {
                     log.debug( "Decoded LdapMessage : " + ldapMessageContainer.getLdapMessage() );
+                    buf.mark();
                 }
 
                 decoderCallback.decodeOccurred( null, ldapMessageContainer.getLdapMessage() );
                 ldapMessageContainer.clean();
+            }
+            else
+            {
+            	if ( log.isDebugEnabled() )
+            	{
+            		
+            	}
             }
         }
     }

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequest.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequest.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequest.java Thu May 25 11:41:03 2006
@@ -144,6 +144,18 @@
         attributes.put( currentAttribute );
     }
 
+    /**
+     * Create a new attributeValue
+     * 
+     * @param type
+     *            The attribute's name (called 'type' in the grammar)
+     */
+    public void addAttributeType( String type )
+    {
+        currentAttribute = new BasicAttribute( type.toLowerCase() );
+        attributes.put( currentAttribute );
+    }
+
 
     /**
      * Add a new value to the current attribute

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequest.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequest.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequest.java Thu May 25 11:41:03 2006
@@ -165,7 +165,18 @@
      */
     public void addAttributeTypeAndValues( LdapString type )
     {
-        currentAttribute = new BasicAttribute( StringTools.lowerCase( type.getString() ) );
+        addAttributeTypeAndValues( type.getString() );
+    }
+
+    /**
+     * Add a new attributeTypeAndValue
+     * 
+     * @param type
+     *            The attribute's name
+     */
+    public void addAttributeTypeAndValues( String type )
+    {
+        currentAttribute = new BasicAttribute( StringTools.lowerCase( type ) );
 
         int operation = 0;
 

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java Thu May 25 11:41:03 2006
@@ -17,98 +17,90 @@
 
 package org.apache.directory.shared.ldap.ldif;
 
-
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+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;
+import javax.naming.directory.DirContext;
 import javax.naming.directory.ModificationItem;
 import javax.naming.ldap.Control;
 
+import org.apache.directory.shared.ldap.util.StringTools;
 
 /**
  * A entry to be populated by an ldif parser.
  * 
- * We will have different kind of entries :
- *  - added entries
- *  - deleted entries
- *  - modified entries
- *  - RDN modified entries
- *  - DN modified entries
+ * We will have different kind of entries : - added entries - deleted entries -
+ * modified entries - RDN modified entries - DN modified entries
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class Entry
+public class Entry implements Cloneable
 {
-    /** the version of the ldif */
-    private int version;
-
     /** the change type */
     private int changeType;
 
     /** the modification item list */
     private List modificationList;
+
     private Map modificationItems;
 
     /** the dn of the ldif entry */
     private String dn;
-    
+
     /** The new superior */
     private String newSuperior;
-    
+
     /** The new rdn */
     private String newRdn;
-    
+
     /** The delete old rdn flag */
     private boolean deleteOldRdn;
 
     /** attributes of the entry */
     private BasicAttributes attributeList;
-    
+
     /** The possible change types */
     public final static int ADD = 0;
+
     public final static int MODIFY = 1;
+
     public final static int MODDN = 2;
+
     public final static int MODRDN = 3;
+
     public final static int DELETE = 4;
-    
+
     /** The control */
     private Control control;
-    
+
     /**
      * Creates a new Entry object.
      */
     public Entry()
     {
-    	changeType = ADD; // Default LDIF content
-    	modificationList = new LinkedList();
-    	modificationItems = new HashMap();
+        changeType = ADD; // Default LDIF content
+        modificationList = new LinkedList();
+        modificationItems = new HashMap();
         dn = null;
         attributeList = new BasicAttributes( true );
-        version = 1; // default version in ldif
         control = null;
     }
 
     /**
-     * Sets the version of this ldif
-     * 
-     * @param version The version of this ldif
-     */
-    public void setVersion( int version )
-    {
-        this.version = version;
-    }
-
-    /**
-     * Set the Distinguished Name 
+     * Set the Distinguished Name
      * 
-     * @param dn The Distinguished Name
+     * @param dn
+     *            The Distinguished Name
      */
     public void setDn( String dn )
     {
@@ -118,7 +110,8 @@
     /**
      * Set the modification type
      * 
-     * @param changeType The change type
+     * @param changeType
+     *            The change type
      * 
      */
     public void setChangeType( int changeType )
@@ -129,118 +122,131 @@
     /**
      * Set the change type
      * 
-     * @param changeType The change type
+     * @param changeType
+     *            The change type
      */
     public void setChangeType( String changeType )
     {
-    	if ( "add".equals( changeType ) )
-    	{
+        if ( "add".equals( changeType ) )
+        {
             this.changeType = ADD;
-    	} 
-    	else if ( "modify".equals( changeType ) )
-    	{
+        }
+        else if ( "modify".equals( changeType ) )
+        {
             this.changeType = MODIFY;
-    	}
-    	else if ( "moddn".equals( changeType ) )
-    	{
+        }
+        else if ( "moddn".equals( changeType ) )
+        {
             this.changeType = MODDN;
-    	}
-    	else if ( "modrdn".equals( changeType ) )
-    	{
+        }
+        else if ( "modrdn".equals( changeType ) )
+        {
             this.changeType = MODRDN;
-    	}
-    	else if ( "delete".equals( changeType ) )
-    	{
+        }
+        else if ( "delete".equals( changeType ) )
+        {
             this.changeType = DELETE;
-    	} 
+        }
     }
 
     /**
      * Add a modification item (used by modify operations)
      * 
-     * @param ModificationItem The modification to be added
+     * @param ModificationItem
+     *            The modification to be added
      */
     public void addModificationItem( ModificationItem modification )
     {
-    	if ( changeType == MODIFY )
-    	{
-    		modificationList.add( modification );
-    		modificationItems.put( modification.getAttribute().getID(), modification );
-    	}
+        if ( changeType == MODIFY )
+        {
+            modificationList.add( modification );
+            modificationItems.put( modification.getAttribute().getID(), modification );
+        }
     }
 
     /**
      * Add a modification item (used by modify operations)
      * 
-     * @param modOp The operation. One of : 
-     * 	DirContext.ADD_ATTRIBUTE
-     *  DirContext.REMOVE_ATTRIBUTE
-     *  DirContext.REPLACE_ATTRIBUTE
-     *  
-     * @param attr The attribute to be added
+     * @param modOp
+     *            The operation. One of : DirContext.ADD_ATTRIBUTE
+     *            DirContext.REMOVE_ATTRIBUTE DirContext.REPLACE_ATTRIBUTE
+     * 
+     * @param attr
+     *            The attribute to be added
      */
     public void addModificationItem( int modOp, Attribute attr ) throws NamingException
     {
-    	if ( changeType == MODIFY )
-    	{
-    		if ( modificationItems.containsKey( attr.getID() ) )
-    		{
-    			ModificationItem item = (ModificationItem)modificationItems.get( attr.getID() );
-    			Attribute attribute = item.getAttribute();
-    			
-    			Enumeration attrs = attr.getAll();
-    			
-    			while ( attrs.hasMoreElements() )
-    			{
-    				attribute.add( attrs.nextElement() );
-    			}
-    		}
-    		else
-    		{
-		    	ModificationItem item = new ModificationItem( modOp, attr );
-		    	modificationList.add( item );
-	    		modificationItems.put( attr.getID(), item );
-    		}
-    	}
+        if ( changeType == MODIFY )
+        {
+            if ( modificationItems.containsKey( attr.getID() ) )
+            {
+                ModificationItem item = (ModificationItem) modificationItems.get( attr.getID() );
+                Attribute attribute = item.getAttribute();
+
+                Enumeration attrs = attr.getAll();
+
+                while ( attrs.hasMoreElements() )
+                {
+                    attribute.add( attrs.nextElement() );
+                }
+            }
+            else
+            {
+                ModificationItem item = new ModificationItem( modOp, attr );
+                modificationList.add( item );
+                modificationItems.put( attr.getID(), item );
+            }
+        }
     }
 
     /**
      * Add a modification item
      * 
-     * @param modOp The operation. One of : 
-     * 	DirContext.ADD_ATTRIBUTE
-     *  DirContext.REMOVE_ATTRIBUTE
-     *  DirContext.REPLACE_ATTRIBUTE
-     *            
-     * @param id The attribute's ID
-     * @param value The attribute's value
-     */
-    public void addModificationItem( int modOp, String id, Object value )
-    {
-    	if ( changeType == MODIFY )
-    	{
-	        BasicAttribute attr = new BasicAttribute( id, value );
-	        
-    		if ( modificationItems.containsKey( id ) )
-    		{
-    			ModificationItem item = (ModificationItem)modificationItems.get( id );
-    			Attribute attribute = item.getAttribute();
-    			
-   				attribute.add( value );
-    		}
-    		else
-    		{
-		        ModificationItem item = new ModificationItem( modOp, attr );
-		        modificationList.add( item );
-		        modificationItems.put( id, item );
-    		}
-    	}    
+     * @param modOp
+     *            The operation. One of : DirContext.ADD_ATTRIBUTE
+     *            DirContext.REMOVE_ATTRIBUTE DirContext.REPLACE_ATTRIBUTE
+     * 
+     * @param id
+     *            The attribute's ID
+     * @param value
+     *            The attribute's value
+     */
+    public void addModificationItem( int modOp, String id, Object value ) throws NamingException
+    {
+        if ( changeType == MODIFY )
+        {
+            BasicAttribute attr = new BasicAttribute( id, value );
+
+            if ( modificationItems.containsKey( id ) )
+            {
+                ModificationItem item = (ModificationItem) modificationItems.get( id );
+                
+                if ( item.getModificationOp() != modOp )
+                {
+                    // This is an error : we can't have two different 
+                    // modifications of the same attribute for the same entry
+                    
+                    throw new NamingException( "Bad modification" );
+                }
+                
+                Attribute attribute = item.getAttribute();
+
+                attribute.add( value );
+            }
+            else
+            {
+                ModificationItem item = new ModificationItem( modOp, attr );
+                modificationList.add( item );
+                modificationItems.put( id, item );
+            }
+        }
     }
 
     /**
      * Add an attribute to the entry
      * 
-     * @param attr The attribute to be added
+     * @param attr
+     *            The attribute to be added
      */
     public void addAttribute( Attribute attr )
     {
@@ -250,56 +256,56 @@
     /**
      * Add an attribute to the entry
      * 
-     * @param id The attribute ID
-     *            
-     * @param value The attribute value
-     *            
+     * @param id
+     *            The attribute ID
+     * 
+     * @param value
+     *            The attribute value
+     * 
      */
     public void addAttribute( String id, Object value )
     {
-		Attribute attr = get( id );
-		
-		if ( attr != null )
-		{
-			attr.add( value );
-		}
-		else
-		{
-			attributeList.put( id, value );
-		}
+        Attribute attr = get( id );
+
+        if ( attr != null )
+        {
+            attr.add( value );
+        }
+        else
+        {
+            attributeList.put( id, value );
+        }
     }
 
     /**
      * Add an attribute value to an existing attribute
      * 
-     * @param id The attribute ID
-     *            
-     * @param value The attribute value
-     *            
+     * @param id
+     *            The attribute ID
+     * 
+     * @param value
+     *            The attribute value
+     * 
      */
     public void putAttribute( String id, Object value )
     {
         Attribute attribute = attributeList.get( id );
-        
+
         if ( attribute != null )
         {
-        	attribute.add( value );
+            attribute.add( value );
         }
         else
         {
-        	attributeList.put( id, value );
+            attributeList.put( id, value );
         }
     }
 
     /**
      * Get the change type
      * 
-     * @return The change type. One of : 
-     * 	ADD = 0;
-     *  MODIFY = 1;
-     *  MODDN = 2;
-     *  MODRDN = 3;
-     *  DELETE = 4;
+     * @return The change type. One of : ADD = 0; MODIFY = 1; MODDN = 2; MODRDN =
+     *         3; DELETE = 4;
      */
     public int getChangeType()
     {
@@ -323,142 +329,382 @@
     }
 
     /**
-     * @return The ldif file version
-     */
-    public int getVersion()
-    {
-        return this.version;
-    }
-    
-    /**
      * @return The number of entry modifications
      */
     public int size()
     {
-    	return modificationList.size();
+        return modificationList.size();
     }
-    
+
     /**
      * Returns a attribute given it's id
      * 
-     * @param attributeId The attribute Id
+     * @param attributeId
+     *            The attribute Id
      * @return The attribute if it exists
      */
     public Attribute get( String attributeId )
     {
-    	if ( "dn".equalsIgnoreCase( attributeId ) )
-    	{
-    		return new BasicAttribute( "dn", dn );
-    	}
-    	
-  		return attributeList.get( attributeId );
+        if ( "dn".equalsIgnoreCase( attributeId ) )
+        {
+            return new BasicAttribute( "dn", dn );
+        }
+
+        return attributeList.get( attributeId );
+    }
+
+    /**
+     * Get the entry's attributes
+     * 
+     * @return An Attributes
+     */
+    public Attributes getAttributes()
+    {
+        if ( isEntry() )
+        {
+            return attributeList;
+        }
+        else
+        {
+            return null;
+        }
     }
 
     /**
      * @return True, if the old RDN should be deleted.
      */
-	public boolean isDeleteOldRdn() 
-	{
-		return deleteOldRdn;
-	}
-
-	/**
-	 * Set the flage deleteOldRdn
-	 * @param deleteOldRdn True if the old RDN should be deleted
-	 */
-	public void setDeleteOldRdn( boolean deleteOldRdn ) 
-	{
-		this.deleteOldRdn = deleteOldRdn;
-	}
-
-	/**
-	 * @return The new RDN
-	 */
-	public String getNewRdn() 
-	{
-		return newRdn;
-	}
-
-	/**
-	 * Set the new RDN
-	 * @param newRdn The new RDN
-	 */
-	public void setNewRdn( String newRdn ) 
-	{
-		this.newRdn = newRdn;
-	}
-
-	/**
-	 * @return The new superior
-	 */
-	public String getNewSuperior() 
-	{
-		return newSuperior;
-	}
-
-	/**
-	 * Set the new superior
-	 * @param newSuperior The new Superior
-	 */
-	public void setNewSuperior( String newSuperior ) 
-	{
-		this.newSuperior = newSuperior;
-	}
-	
-	/**
-	 * @return True if the entry is an ADD entry
-	 */
-	public boolean isChangeAdd()
-	{
-		return changeType == ADD;
-	}
-
-	/**
-	 * @return True if the entry is a DELETE entry
-	 */
-	public boolean isChangeDelete()
-	{
-		return changeType == DELETE;
-	}
-
-	/**
-	 * @return True if the entry is a MODDN entry
-	 */
-	public boolean isChangeModDn()
-	{
-		return changeType == MODDN;
-	}
-
-	/**
-	 * @return True if the entry is a MODRDN entry
-	 */
-	public boolean isChangeModRdn()
-	{
-		return changeType == MODRDN;
-	}
-
-	/**
-	 * @return True if the entry is a MODIFY entry
-	 */
-	public boolean isChangeModify()
-	{
-		return changeType == MODIFY;
-	}
-
-	/**
-	 * @return The associated control, if any
-	 */
-	public Control getControl() 
-	{
-		return control;
-	}
-
-	/**
-	 * Add a control to the entry 
-	 * @param control The control
-	 */
-	public void setControl( Control control ) 
-	{
-		this.control = control;
-	}
+    public boolean isDeleteOldRdn()
+    {
+        return deleteOldRdn;
+    }
+
+    /**
+     * Set the flage deleteOldRdn
+     * 
+     * @param deleteOldRdn
+     *            True if the old RDN should be deleted
+     */
+    public void setDeleteOldRdn( boolean deleteOldRdn )
+    {
+        this.deleteOldRdn = deleteOldRdn;
+    }
+
+    /**
+     * @return The new RDN
+     */
+    public String getNewRdn()
+    {
+        return newRdn;
+    }
+
+    /**
+     * Set the new RDN
+     * 
+     * @param newRdn
+     *            The new RDN
+     */
+    public void setNewRdn( String newRdn )
+    {
+        this.newRdn = newRdn;
+    }
+
+    /**
+     * @return The new superior
+     */
+    public String getNewSuperior()
+    {
+        return newSuperior;
+    }
+
+    /**
+     * Set the new superior
+     * 
+     * @param newSuperior
+     *            The new Superior
+     */
+    public void setNewSuperior( String newSuperior )
+    {
+        this.newSuperior = newSuperior;
+    }
+
+    /**
+     * @return True if the entry is an ADD entry
+     */
+    public boolean isChangeAdd()
+    {
+        return changeType == ADD;
+    }
+
+    /**
+     * @return True if the entry is a DELETE entry
+     */
+    public boolean isChangeDelete()
+    {
+        return changeType == DELETE;
+    }
+
+    /**
+     * @return True if the entry is a MODDN entry
+     */
+    public boolean isChangeModDn()
+    {
+        return changeType == MODDN;
+    }
+
+    /**
+     * @return True if the entry is a MODRDN entry
+     */
+    public boolean isChangeModRdn()
+    {
+        return changeType == MODRDN;
+    }
+
+    /**
+     * @return True if the entry is a MODIFY entry
+     */
+    public boolean isChangeModify()
+    {
+        return changeType == MODIFY;
+    }
+
+    public boolean isEntry()
+    {
+        return changeType == ADD;
+    }
+
+    /**
+     * @return The associated control, if any
+     */
+    public Control getControl()
+    {
+        return control;
+    }
+
+    /**
+     * Add a control to the entry
+     * 
+     * @param control
+     *            The control
+     */
+    public void setControl( Control control )
+    {
+        this.control = control;
+    }
+
+    /**
+     * Clone method
+     */
+    public Object clone() throws CloneNotSupportedException
+    {
+        Entry clone = (Entry) super.clone();
+
+        if ( modificationList != null )
+        {
+            for ( Iterator iter = modificationList.iterator(); iter.hasNext(); )
+            {
+                ModificationItem modif = (ModificationItem) ( iter.next() );
+                ModificationItem modifClone = new ModificationItem( modif.getModificationOp(), (Attribute) modif.getAttribute()
+                        .clone() );
+                clone.modificationList.add( modifClone );
+            }
+        }
+
+        if ( modificationItems != null )
+        {
+            for ( Iterator iter = modificationItems.entrySet().iterator(); iter.hasNext(); )
+            {
+                Object key = iter.next();
+                ModificationItem modif = (ModificationItem) ( modificationItems.get( key ) );
+                ModificationItem modifClone = new ModificationItem( modif.getModificationOp(), (Attribute) modif.getAttribute()
+                        .clone() );
+                clone.modificationItems.put( key, modifClone );
+            }
+
+        }
+
+        if ( attributeList != null )
+        {
+            try
+            {
+                NamingEnumeration attrs = attributeList.getAll();
+
+                while ( attrs.hasMore() )
+                {
+                    Attribute attribute = (BasicAttribute) attrs.nextElement();
+                    Attribute attrClone = new BasicAttribute( attribute.getID() );
+
+                    for ( NamingEnumeration iter = attribute.getAll(); iter.hasMoreElements(); )
+                    {
+                        Object value = iter.next();
+
+                        if ( value instanceof String )
+                        {
+                            attrClone.add( value );
+                        }
+                        else if ( value instanceof byte[] )
+                        {
+                            int length = ( (byte[]) value ).length;
+                            byte[] valueClone = new byte[length];
+                            System.arraycopy( value, 0, valueClone, 0, length );
+                            attrClone.add( valueClone );
+                        }
+                    }
+
+                    clone.attributeList.put( attrClone );
+                }
+            }
+            catch (NamingException ne)
+            {
+                throw new CloneNotSupportedException( ne.getMessage() );
+            }
+        }
+
+        return clone;
+    }
+    
+    /**
+     * Dumps the attributes
+     */
+    private String dumpAttributes()
+    {
+        StringBuffer sb = new StringBuffer();
+        
+        try
+        {
+            for ( NamingEnumeration attrs = attributeList.getAll(); attrs.hasMoreElements(); )
+            {
+                Attribute attribute = (Attribute) attrs.nextElement();
+    
+                sb.append( "        ").append( attribute.getID() ).append( ":\n" );
+    
+                for ( NamingEnumeration values = attribute.getAll(); values.hasMoreElements(); )
+                {
+                    Object value = values.nextElement();
+                    
+                    if ( value instanceof String )
+                    {
+                        sb.append(  "            " ).append( (String)value ).append('\n' );
+                    }
+                    else
+                    {
+                        sb.append(  "            " ).append( StringTools.dumpBytes( (byte[]) value ) ).append('\n' );
+                    }
+                }
+            }
+        }
+        catch ( NamingException ne )
+        {
+            return "";
+        }
+        
+        return sb.toString();
+    }
+    
+    /**
+     * Dumps the modifications
+     */
+    private String dumpModificationItems()
+    {
+        StringBuffer sb = new StringBuffer();
+        
+        for ( Iterator iter = modificationList.iterator(); iter.hasNext(); )
+        {
+            ModificationItem modif = (ModificationItem) ( iter.next() );
+            
+            sb.append( "            Operation: " );
+            
+            switch ( modif.getModificationOp() )
+            {
+                case DirContext.ADD_ATTRIBUTE :
+                    sb.append( "ADD\n" );
+                    break;
+                    
+                case DirContext.REMOVE_ATTRIBUTE :
+                    sb.append( "REMOVE\n" );
+                    break;
+                    
+                case DirContext.REPLACE_ATTRIBUTE :
+                    sb.append( "REPLACE \n" );
+                    break;
+            }
+            
+            Attribute attribute = modif.getAttribute();
+            
+            sb.append( "                Attribute: " ).append( attribute.getID() ).append( '\n' );
+            
+            if ( attribute.size() != 0 )
+            {
+                try
+                {
+                    for ( NamingEnumeration values = attribute.getAll(); values.hasMoreElements(); )
+                    {
+                        Object value = values.nextElement();
+    
+                        if ( value instanceof String )
+                        {
+                            sb.append(  "                " ).append( (String)value ).append('\n' );
+                        }
+                        else
+                        {
+                            sb.append(  "                " ).append( StringTools.dumpBytes( (byte[]) value ) ).append('\n' );
+                        }
+                    }
+                }
+                catch ( NamingException ne )
+                {
+                    return "";
+                }
+            }
+        }
+        
+        return sb.toString();
+    }
+    
+    /**
+     * Return a String representing the Entry
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+        sb.append( "Entry : " ).append( dn ).append( '\n' );
+
+        if ( control != null )
+        {
+            sb.append( "    Control : " ).append(  control ).append( '\n' );
+        }
+        
+        switch ( changeType )
+        {
+            case ADD :
+                sb.append( "    Change type is ADD\n" );
+                sb.append( "        Attributes : \n" );
+                sb.append( dumpAttributes() );
+                break;
+                
+            case MODIFY :
+                sb.append( "    Change type is MODIFY\n" );
+                sb.append( "        Modifications : \n" );
+                sb.append( dumpModificationItems() );
+                break;
+                
+            case DELETE :
+                sb.append( "    Change type is DELETE\n" );
+                break;
+                
+            case MODDN :
+            case MODRDN :
+                sb.append( "    Change type is ").append( changeType == MODDN ? "MODDN\n" : "MODRDN\n" );
+                sb.append( "    Delete old RDN : " ).append( deleteOldRdn ? "true\n" : "false\n" );
+                sb.append( "    New RDN : " ).append( newRdn ).append( '\n' );
+                
+                if ( StringTools.isEmpty( newSuperior ) == false )
+                {
+                    sb.append( "    New superior : " ).append( newSuperior ).append( '\n' );
+                }
+
+                break;
+        }
+        
+        return sb.toString();
+    }
 }

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java Thu May 25 11:41:03 2006
@@ -54,77 +54,77 @@
      *            the multi map of single and multivalued attributes.
      * @return the LDIF as a String.
      */
-    public String compose( MultiMap a_attrHash )
+    public String compose( MultiMap attrHash )
     {
-        Object l_val = null;
-        String l_key = null;
-        Iterator l_keys = a_attrHash.keySet().iterator();
-        Iterator l_values = null;
-        Collection l_valueCol = null;
-        StringWriter l_sw = new StringWriter();
-        PrintWriter l_out = new PrintWriter( l_sw );
+        Object val = null;
+        String key = null;
+        Iterator keys = attrHash.keySet().iterator();
+        Iterator values = null;
+        Collection valueCol = null;
+        StringWriter sw = new StringWriter();
+        PrintWriter out = new PrintWriter( sw );
 
-        while ( l_keys.hasNext() )
+        while ( keys.hasNext() )
         {
-            l_key = ( String ) l_keys.next();
-            l_valueCol = ( Collection ) a_attrHash.get( l_key );
-            l_values = l_valueCol.iterator();
+            key = ( String ) keys.next();
+            valueCol = ( Collection ) attrHash.get( key );
+            values = valueCol.iterator();
 
-            if ( l_valueCol.isEmpty() )
+            if ( valueCol.isEmpty() )
             {
                 continue;
             }
-            else if ( l_valueCol.size() == 1 )
+            else if ( valueCol.size() == 1 )
             {
-                l_out.print( l_key );
-                l_out.print( ':' );
-                l_val = l_values.next();
+                out.print( key );
+                out.print( ':' );
+                val = values.next();
 
-                if ( l_val.getClass().isArray() )
+                if ( val.getClass().isArray() )
                 {
-                    l_out.print( ": " );
-                    l_out.println( base64encode( ( byte[] ) l_val ) );
+                    out.print( ": " );
+                    out.println( base64encode( ( byte[] ) val ) );
                 }
                 else
                 {
-                    l_out.print( ' ' );
-                    l_out.println( l_val );
+                    out.print( ' ' );
+                    out.println( val );
                 }
                 continue;
             }
 
-            while ( l_values.hasNext() )
+            while ( values.hasNext() )
             {
-                l_out.print( l_key );
-                l_out.print( ':' );
-                l_val = l_values.next();
+                out.print( key );
+                out.print( ':' );
+                val = values.next();
 
-                if ( l_val.getClass().isArray() )
+                if ( val.getClass().isArray() )
                 {
-                    l_out.print( ": " );
-                    l_out.println( base64encode( ( byte[] ) l_val ) );
+                    out.print( ": " );
+                    out.println( base64encode( ( byte[] ) val ) );
                 }
                 else
                 {
-                    l_out.print( ' ' );
-                    l_out.println( l_val );
+                    out.print( ' ' );
+                    out.println( val );
                 }
             }
         }
 
-        return l_sw.getBuffer().toString();
+        return sw.getBuffer().toString();
     }
 
 
     /**
      * Encodes an binary data into a base64 String.
      * 
-     * @param a_byteArray
+     * @param byteArray
      *            the value of a binary attribute.
      * @return the encoded binary data as a char array.
      */
-    public char[] base64encode( byte[] a_byteArray )
+    public char[] base64encode( byte[] byteArray )
     {
-        return Base64.encode( a_byteArray );
+        return Base64.encode( byteArray );
     }
 }

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java?rev=409424&r1=409423&r2=409424&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java Thu May 25 11:41:03 2006
@@ -23,91 +23,96 @@
 import org.apache.directory.shared.ldap.util.StringTools;
 
 /**
- * The LdifControl class stores a control defined for an entry found in
- * a ldif file.
+ * The LdifControl class stores a control defined for an entry found in a ldif
+ * file.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class LdifControl implements Control
 {
-	static final long serialVersionUID = 1L;
-	
-	/** The control OID */
-	private OID oid;
-	
-	/** The control criticality */
-	private boolean criticality;
-	
-	/** The control BER encoded value */
-	private byte[] value;
-	
-	/**
-	 * Create a new Control
-	 * @param oid OID of the created control
-	 */
-	public LdifControl( OID oid )
-	{
-		this.oid = oid;
-		criticality = false;
-		value = null;
-	}
-
-	/**
-	 *	Returns the criticality of the current control 
-	 */
-	public boolean isCritical() 
-	{
-		return criticality;
-	}
-
-	/**
-	 * Set the criticality
-	 * @param criticality True or false.
-	 */
-	public void setCriticality( boolean criticality ) 
-	{
-		this.criticality = criticality;
-	}
-
-	/**
-	 * Return the control's OID as a String
-	 */
-	public String getID() 
-	{
-		return oid.toString();
-	}
-
-	/**
-	 * Set the control's OID
-	 * 
-	 * @param oid The control's OID
-	 */
-	public void setOid( OID oid ) 
-	{
-		this.oid = oid;
-	}
-
-	/**
-	 * Returns the BER encoded value of the control
-	 */
-	public byte[] getEncodedValue() 
-	{
-		return value;
-	}
-
-	/**
-	 * Set the BER encoded value of the control
-	 * 
-	 * @param value BER encodec value
-	 */
-	public void setValue( byte[] value ) 
-	{
-		this.value = value;
-	}
-	
-	public String toString()
-	{
-		return "LdifControl : {" + oid.toString() + ", " + criticality + ", " + 
-			StringTools.dumpBytes( value ) + "}";
-	}
+    static final long serialVersionUID = 1L;
+
+    /** The control OID */
+    private OID oid;
+
+    /** The control criticality */
+    private boolean criticality;
+
+    /** The control BER encoded value */
+    private byte[] value;
+
+    /**
+     * Create a new Control
+     * 
+     * @param oid
+     *            OID of the created control
+     */
+    public LdifControl( OID oid )
+    {
+        this.oid = oid;
+        criticality = false;
+        value = null;
+    }
+
+    /**
+     * Returns the criticality of the current control
+     */
+    public boolean isCritical()
+    {
+        return criticality;
+    }
+
+    /**
+     * Set the criticality
+     * 
+     * @param criticality
+     *            True or false.
+     */
+    public void setCriticality( boolean criticality )
+    {
+        this.criticality = criticality;
+    }
+
+    /**
+     * Return the control's OID as a String
+     */
+    public String getID()
+    {
+        return oid.toString();
+    }
+
+    /**
+     * Set the control's OID
+     * 
+     * @param oid
+     *            The control's OID
+     */
+    public void setOid( OID oid )
+    {
+        this.oid = oid;
+    }
+
+    /**
+     * Returns the BER encoded value of the control
+     */
+    public byte[] getEncodedValue()
+    {
+        return value;
+    }
+
+    /**
+     * Set the BER encoded value of the control
+     * 
+     * @param value
+     *            BER encodec value
+     */
+    public void setValue( byte[] value )
+    {
+        this.value = value;
+    }
+
+    public String toString()
+    {
+        return "LdifControl : {" + oid.toString() + ", " + criticality + ", " + StringTools.dumpBytes( value ) + "}";
+    }
 }



Mime
View raw message