directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r409467 - in /directory/branches/apacheds/1.0: core-unit/src/main/java/org/apache/directory/server/core/unit/ core/src/main/java/org/apache/directory/server/core/ core/src/main/java/org/apache/directory/server/core/configuration/ core/src/m...
Date Thu, 25 May 2006 21:00:44 GMT
Author: elecharny
Date: Thu May 25 14:00:43 2006
New Revision: 409467

URL: http://svn.apache.org/viewvc?rev=409467&view=rev
Log:
merging ldif modification into 1.0-trunks

Added:
    directory/branches/apacheds/1.0/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
      - copied unchanged from r409441, directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
Modified:
    directory/branches/apacheds/1.0/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/StartupConfiguration.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java
    directory/branches/apacheds/1.0/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/AbstractBackingStoreTest.java
    directory/branches/apacheds/1.0/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java
    directory/branches/apacheds/1.0/server-main/log4j.properties
    directory/branches/apacheds/1.0/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
    directory/branches/apacheds/1.0/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java

Modified: directory/branches/apacheds/1.0/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java?rev=409467&r1=409466&r2=409467&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java
(original)
+++ directory/branches/apacheds/1.0/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java
Thu May 25 14:00:43 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/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=409467&r1=409466&r2=409467&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
Thu May 25 14:00:43 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/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java?rev=409467&r1=409466&r2=409467&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java
Thu May 25 14:00:43 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/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java?rev=409467&r1=409466&r2=409467&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java
Thu May 25 14:00:43 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/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/StartupConfiguration.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/StartupConfiguration.java?rev=409467&r1=409466&r2=409467&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/StartupConfiguration.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/configuration/StartupConfiguration.java
Thu May 25 14:00:43 2006
@@ -43,6 +43,7 @@
 import org.apache.directory.server.core.schema.SchemaService;
 import org.apache.directory.server.core.schema.bootstrap.*;
 import org.apache.directory.server.core.subtree.SubentryService;
+import org.apache.directory.shared.ldap.ldif.Entry;
 
 
 /**
@@ -366,7 +367,14 @@
      */
     public List getTestEntries()
     {
-        return ConfigurationUtil.getClonedAttributesList( testEntries );
+    	try
+    	{
+    		return ConfigurationUtil.getClonedAttributesList( testEntries );
+    	}
+    	catch ( CloneNotSupportedException cnse )
+    	{
+    		return null;
+    	}
     }
 
 
@@ -376,20 +384,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/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java?rev=409467&r1=409466&r2=409467&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java
Thu May 25 14:00:43 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/branches/apacheds/1.0/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/AbstractBackingStoreTest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/AbstractBackingStoreTest.java?rev=409467&r1=409466&r2=409467&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/AbstractBackingStoreTest.java
(original)
+++ directory/branches/apacheds/1.0/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/AbstractBackingStoreTest.java
Thu May 25 14:00:43 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/branches/apacheds/1.0/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java?rev=409467&r1=409466&r2=409467&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java
(original)
+++ directory/branches/apacheds/1.0/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java
Thu May 25 14:00:43 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/branches/apacheds/1.0/server-main/log4j.properties
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/server-main/log4j.properties?rev=409467&r1=409466&r2=409467&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/server-main/log4j.properties (original)
+++ directory/branches/apacheds/1.0/server-main/log4j.properties Thu May 25 14:00:43 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/branches/apacheds/1.0/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java?rev=409467&r1=409466&r2=409467&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
(original)
+++ directory/branches/apacheds/1.0/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
Thu May 25 14:00:43 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/branches/apacheds/1.0/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java?rev=409467&r1=409466&r2=409467&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
(original)
+++ directory/branches/apacheds/1.0/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
Thu May 25 14:00:43 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 )



Mime
View raw message