directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r797798 - /directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.java
Date Sat, 25 Jul 2009 17:04:53 GMT
Author: seelmann
Date: Sat Jul 25 17:04:53 2009
New Revision: 797798

URL: http://svn.apache.org/viewvc?rev=797798&view=rev
Log:
Fix for DIRSTUDIO-506 (Export Schemas for ApacheDS: object classes must be sorted by hierarchy)

Modified:
    directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.java

Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.java?rev=797798&r1=797797&r2=797798&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.java
(original)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.java
Sat Jul 25 17:04:53 2009
@@ -28,6 +28,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -349,7 +350,8 @@
         sb.append( "\n" ); //$NON-NLS-1$
 
         // Generating LDIF for Object Classes
-        for ( ObjectClassImpl oc : schema.getObjectClasses() )
+        List<ObjectClassImpl> sortedObjectClasses = getSortedObjectClasses( schema.getObjectClasses()
);
+        for ( ObjectClassImpl oc : sortedObjectClasses )
         {
             ObjectClassHolder holder = new ObjectClassHolder( oc.getOid() );
             holder.setClassType( oc.getType() );
@@ -400,6 +402,66 @@
 
 
     /**
+     * Sorts the object classes by hierarchy.
+     *
+     * @param objectClasses the unsorted object classes
+     * @return the sorted object classes
+     */
+    private List<ObjectClassImpl> getSortedObjectClasses( List<ObjectClassImpl>
objectClasses )
+    {
+        // clone the unsorted list
+        List<ObjectClassImpl> unsortedObjectClasses = new ArrayList<ObjectClassImpl>(
objectClasses );
+
+        // list of all existing names
+        Set<String> objectClassNames = new HashSet<String>();
+        for ( ObjectClassImpl oc : unsortedObjectClasses )
+        {
+            for ( String name : oc.getNamesRef() )
+            {
+                objectClassNames.add( name.toLowerCase() );
+            }
+        }
+
+        // sort object classes
+        List<ObjectClassImpl> sortedObjectClasses = new ArrayList<ObjectClassImpl>();
+        Set<String> movedObjectClasses = new HashSet<String>();
+        boolean moved = true;
+        while ( !unsortedObjectClasses.isEmpty() && moved )
+        {
+            moved = false;
+            Iterator<ObjectClassImpl> unsortedIterator = unsortedObjectClasses.iterator();
+            while ( unsortedIterator.hasNext() )
+            {
+                ObjectClassImpl oc = unsortedIterator.next();
+                for ( String superName : oc.getSuperClassesNames() )
+                {
+                    if ( !objectClassNames.contains( superName.toLowerCase() )
+                        || movedObjectClasses.contains( superName.toLowerCase() ) )
+                    {
+                        unsortedIterator.remove();
+                        sortedObjectClasses.add( oc );
+                        for ( String name : oc.getNamesRef() )
+                        {
+                            movedObjectClasses.add( name.toLowerCase() );
+                        }
+                        moved = true;
+                        break;
+                    }
+                }
+            }
+        }
+
+        // add the rest
+        for ( ObjectClassImpl oc : unsortedObjectClasses )
+        {
+            sortedObjectClasses.add( oc );
+        }
+
+        return sortedObjectClasses;
+    }
+
+
+    /**
      * Gets the schema dependencies.
      *
      * @param schema



Mime
View raw message