directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1066900 - /directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaChecker.java
Date Thu, 03 Feb 2011 18:03:10 GMT
Author: pamarcelot
Date: Thu Feb  3 18:03:10 2011
New Revision: 1066900

URL: http://svn.apache.org/viewvc?rev=1066900&view=rev
Log:
Getting the reporting of errors to work with the SchemaManager and modifications to the schema
(adding/removing schemas and schema objects).
Bloody hack as the SchemaManager get re-instantiated at each modification (SchemaManager needs
to be fixed first and then we can clean this).

Modified:
    directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaChecker.java

Modified: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaChecker.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaChecker.java?rev=1066900&r1=1066899&r2=1066900&view=diff
==============================================================================
--- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaChecker.java
(original)
+++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaChecker.java
Thu Feb  3 18:03:10 2011
@@ -27,12 +27,15 @@ import org.apache.commons.collections.Mu
 import org.apache.commons.collections.map.MultiValueMap;
 import org.apache.directory.shared.ldap.model.exception.LdapSchemaException;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.LdapSyntax;
+import org.apache.directory.shared.ldap.model.schema.MatchingRule;
 import org.apache.directory.shared.ldap.model.schema.ObjectClass;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.SchemaObject;
 import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
 import org.apache.directory.studio.schemaeditor.Activator;
 import org.apache.directory.studio.schemaeditor.controller.ProjectsHandlerAdapter;
+import org.apache.directory.studio.schemaeditor.controller.SchemaHandler;
 import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerAdapter;
 import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerListener;
 import org.apache.directory.studio.schemaeditor.model.Project;
@@ -78,8 +81,7 @@ public class SchemaChecker
         {
             synchronized ( this )
             {
-
-                notifyListeners();
+                recheckWholeSchema();
             }
         }
 
@@ -88,8 +90,7 @@ public class SchemaChecker
         {
             synchronized ( this )
             {
-
-                notifyListeners();
+                recheckWholeSchema();
             }
         }
 
@@ -98,8 +99,7 @@ public class SchemaChecker
         {
             synchronized ( this )
             {
-
-                notifyListeners();
+                recheckWholeSchema();
             }
         }
 
@@ -108,8 +108,7 @@ public class SchemaChecker
         {
             synchronized ( this )
             {
-
-                notifyListeners();
+                recheckWholeSchema();
             }
         }
 
@@ -118,8 +117,7 @@ public class SchemaChecker
         {
             synchronized ( this )
             {
-
-                notifyListeners();
+                recheckWholeSchema();
             }
         }
 
@@ -128,8 +126,7 @@ public class SchemaChecker
         {
             synchronized ( this )
             {
-
-                notifyListeners();
+                recheckWholeSchema();
             }
         }
 
@@ -138,8 +135,7 @@ public class SchemaChecker
         {
             synchronized ( this )
             {
-
-                notifyListeners();
+                recheckWholeSchema();
             }
         }
 
@@ -148,8 +144,7 @@ public class SchemaChecker
         {
             synchronized ( this )
             {
-
-                notifyListeners();
+                recheckWholeSchema();
             }
         }
     };
@@ -161,7 +156,7 @@ public class SchemaChecker
     private SchemaChecker()
     {
         listeners = new ArrayList<SchemaCheckerListener>();
-        
+
         schemaManager = new DefaultSchemaManager( new SchemaEditorSchemaLoader() );
         errorsMap = new MultiValueMap();
 
@@ -211,8 +206,7 @@ public class SchemaChecker
             {
                 Activator.getDefault().getSchemaHandler().addListener( schemaHandlerListener
);
                 listeningToModifications = true;
-                checkWholeSchema();
-                notifyListeners();
+                recheckWholeSchema();
             }
         }
     }
@@ -241,10 +235,7 @@ public class SchemaChecker
     {
         synchronized ( this )
         {
-            schemaManager = new DefaultSchemaManager( new SchemaEditorSchemaLoader() );
-            errorsMap = new MultiValueMap();
-            
-            checkWholeSchema();
+            recheckWholeSchema();
         }
     }
 
@@ -266,7 +257,7 @@ public class SchemaChecker
     /**
      * Checks the whole schema.
      */
-    private synchronized void checkWholeSchema()
+    private synchronized void recheckWholeSchema()
     {
         Job job = new Job( "Checking Schema" )
         {
@@ -274,6 +265,7 @@ public class SchemaChecker
             {
                 try
                 {
+                    schemaManager = new DefaultSchemaManager( new SchemaEditorSchemaLoader()
);
                     schemaManager.loadAllEnabled();
                 }
                 catch ( Exception e )
@@ -282,19 +274,7 @@ public class SchemaChecker
                     e.printStackTrace();
                 }
 
-                errorsList = schemaManager.getErrors();
-                for ( Throwable error : errorsList )
-                {
-                    if ( error instanceof LdapSchemaException )
-                    {
-                        LdapSchemaException ldapSchemaException = (LdapSchemaException) error;
-                        SchemaObject source = ldapSchemaException.getSourceObject();
-                        if ( source != null )
-                        {
-                            errorsMap.put( source, ldapSchemaException );
-                        }
-                    }
-                }
+                updateErrorsList();
 
                 notifyListeners();
                 monitor.done();
@@ -306,6 +286,44 @@ public class SchemaChecker
     }
 
 
+    private void updateErrorsList()
+    {
+        errorsMap.clear();
+        errorsList = schemaManager.getErrors();
+        for ( Throwable error : errorsList )
+        {
+            if ( error instanceof LdapSchemaException )
+            {
+                LdapSchemaException ldapSchemaException = ( LdapSchemaException ) error;
+                SchemaObject source = ldapSchemaException.getSourceObject();
+                if ( source != null )
+                {
+                    SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler();
+
+                    if ( source instanceof AttributeType )
+                    {
+                        source = schemaHandler.getAttributeType( source.getOid() );
+                    }
+                    else if ( source instanceof LdapSyntax )
+                    {
+                        source = schemaHandler.getSyntax( source.getOid() );
+                    }
+                    else if ( source instanceof MatchingRule )
+                    {
+                        source = schemaHandler.getMatchingRule( source.getOid() );
+                    }
+                    else if ( source instanceof ObjectClass )
+                    {
+                        source = schemaHandler.getObjectClass( source.getOid() );
+                    }
+
+                    errorsMap.put( source, ldapSchemaException );
+                }
+            }
+        }
+    }
+
+
     /**
      * Gets the errors.
      *
@@ -418,7 +436,7 @@ public class SchemaChecker
     public List<Object> getWarnings( SchemaObject so )
     {
         return new ArrayList<Object>();
-     //   return ( List<?> ) warningsMap.get( so );
+        //   return ( List<?> ) warningsMap.get( so );
     }
 
 
@@ -443,4 +461,5 @@ public class SchemaChecker
             return warnings.size() > 0;
         }
     }
+
 }



Mime
View raw message