directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1209068 - in /directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor: controller/ model/schemachecker/ view/views/ view/wrappers/
Date Thu, 01 Dec 2011 13:14:27 GMT
Author: pamarcelot
Date: Thu Dec  1 13:14:24 2011
New Revision: 1209068

URL: http://svn.apache.org/viewvc?rev=1209068&view=rev
Log:
Brought back schema warnings (especially the NoAliasWarning) for the SchemaEditor plugin.
The use of the SchemaManager from Shared was only reporting errors. Warnings needed to be
processed aside.

Added:
    directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/NoAliasWarning.java
    directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaWarning.java
      - copied, changed from r1209033, directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaCheckerElement.java
Removed:
    directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaCheckerElement.java
Modified:
    directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java
    directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaChecker.java
    directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewContentProvider.java
    directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewLabelProvider.java
    directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaWarningWrapper.java

Modified: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java?rev=1209068&r1=1209067&r2=1209068&view=diff
==============================================================================
--- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java
(original)
+++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java
Thu Dec  1 13:14:24 2011
@@ -131,19 +131,18 @@ public class ProblemsViewController
                 }
                 else if ( objectSelection instanceof SchemaWarningWrapper )
                 {
-                    // TODO
-                    //                    SchemaObject object = ( ( SchemaWarningWrapper
) objectSelection ).getSchemaWarning().getSource();
-                    //
-                    //                    if ( object instanceof AttributeType )
-                    //                    {
-                    //                        input = new AttributeTypeEditorInput( ( AttributeType
) object );
-                    //                        editorId = AttributeTypeEditor.ID;
-                    //                    }
-                    //                    else if ( object instanceof ObjectClass )
-                    //                    {
-                    //                        input = new ObjectClassEditorInput( ( ObjectClass
) object );
-                    //                        editorId = ObjectClassEditor.ID;
-                    //                    }
+                    SchemaObject object = ( ( SchemaWarningWrapper ) objectSelection ).getSchemaWarning().getSource();
+
+                    if ( object instanceof AttributeType )
+                    {
+                        input = new AttributeTypeEditorInput( ( AttributeType ) object );
+                        editorId = AttributeTypeEditor.ID;
+                    }
+                    else if ( object instanceof ObjectClass )
+                    {
+                        input = new ObjectClassEditorInput( ( ObjectClass ) object );
+                        editorId = ObjectClassEditor.ID;
+                    }
                 }
                 else if ( ( objectSelection instanceof Folder ) )
                 {

Added: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/NoAliasWarning.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/NoAliasWarning.java?rev=1209068&view=auto
==============================================================================
--- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/NoAliasWarning.java
(added)
+++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/NoAliasWarning.java
Thu Dec  1 13:14:24 2011
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.schemaeditor.model.schemachecker;
+
+
+import org.apache.directory.shared.ldap.model.schema.SchemaObject;
+
+
+/**
+ * This class represents the NoAliasWarning.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class NoAliasWarning implements SchemaWarning
+{
+    /** The source object */
+    private SchemaObject source;
+
+
+    /**
+     * Creates a new instance of NoAliasWarning.
+     *
+     * @param source
+     *      the source object
+     */
+    public NoAliasWarning( SchemaObject source )
+    {
+        this.source = source;
+    }
+
+
+    /**
+     * {@inheritDoc
+     */
+    public SchemaObject getSource()
+    {
+        return source;
+    }
+}

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=1209068&r1=1209067&r2=1209068&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 Dec  1 13:14:24 2011
@@ -62,17 +62,20 @@ public class SchemaChecker
     /** The schema manager */
     private SchemaManager schemaManager;
 
-    /** The errors List */
-    private List<Throwable> errorsList;
+    /** The errors map */
+    private MultiMap errorsMap = new MultiValueMap();;
 
-    /** The errors MultiMap */
-    private MultiMap errorsMap;
+    /** The warnings list */
+    private List<SchemaWarning> warningsList = new ArrayList<SchemaWarning>();
+
+    /** The warnings map */
+    private MultiMap warningsMap = new MultiValueMap();;
 
     /** The 'listening to modifications' flag*/
     private boolean listeningToModifications = false;
 
     /** The listeners List */
-    private List<SchemaCheckerListener> listeners;
+    private List<SchemaCheckerListener> listeners = new ArrayList<SchemaCheckerListener>();
 
     /** The SchemaHandlerListener */
     private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter()
@@ -155,11 +158,6 @@ public class SchemaChecker
      */
     private SchemaChecker()
     {
-        listeners = new ArrayList<SchemaCheckerListener>();
-
-        schemaManager = new DefaultSchemaManager( new SchemaEditorSchemaLoader() );
-        errorsMap = new MultiValueMap();
-
         Activator.getDefault().getProjectsHandler().addListener( new ProjectsHandlerAdapter()
         {
             public void openProjectChanged( Project oldProject, Project newProject )
@@ -263,6 +261,7 @@ public class SchemaChecker
         {
             protected IStatus run( IProgressMonitor monitor )
             {
+                // Checks the whole schema via the schema manager
                 try
                 {
                     schemaManager = new DefaultSchemaManager( new SchemaEditorSchemaLoader()
);
@@ -274,9 +273,12 @@ public class SchemaChecker
                     e.printStackTrace();
                 }
 
-                updateErrorsList();
+                // Updates errors and warnings
+                updateErrorsAndWarnings();
 
+                // Notify listeners
                 notifyListeners();
+
                 monitor.done();
 
                 return Status.OK_STATUS;
@@ -286,11 +288,28 @@ public class SchemaChecker
     }
 
 
-    private void updateErrorsList()
+    /**
+     * Updates the errors and warnings. 
+     */
+    private void updateErrorsAndWarnings()
     {
+        // Errors
         errorsMap.clear();
-        errorsList = schemaManager.getErrors();
-        for ( Throwable error : errorsList )
+        indexErrors();
+
+        // Warnings
+        createWarnings();
+        warningsMap.clear();
+        indexWarnings();
+    }
+
+
+    /**
+     * Indexes the errors.
+     */
+    private void indexErrors()
+    {
+        for ( Throwable error : schemaManager.getErrors() )
         {
             if ( error instanceof LdapSchemaException )
             {
@@ -325,6 +344,60 @@ public class SchemaChecker
 
 
     /**
+     * Creates the warnings.
+     */
+    private void createWarnings()
+    {
+        // Clearing previous warnings
+        warningsList.clear();
+
+        // Getting the schema handler to check for schema objects without names (aliases)
+        SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler();
+
+        if ( schemaHandler != null )
+        {
+            // Checking attribute types
+            for ( AttributeType attributeType : schemaHandler.getAttributeTypes() )
+            {
+                checkSchemaObjectNames( attributeType );
+            }
+
+            // Checking object classes
+            for ( ObjectClass objectClass : schemaHandler.getObjectClasses() )
+            {
+                checkSchemaObjectNames( objectClass );
+            }
+        }
+    }
+
+
+    /**
+     * Checks the names of the given schema object.
+     *
+     * @param schemaObject the schema object to check
+     */
+    private void checkSchemaObjectNames( SchemaObject schemaObject )
+    {
+        if ( ( schemaObject.getNames() == null ) || ( schemaObject.getNames().size() == 0
) )
+        {
+            warningsList.add( new NoAliasWarning( schemaObject ) );
+        }
+    }
+
+
+    /**
+     * Indexes the warnings.
+     */
+    private void indexWarnings()
+    {
+        for ( SchemaWarning warning : warningsList )
+        {
+            warningsMap.put( warning.getSource(), warning );
+        }
+    }
+
+
+    /**
      * Gets the errors.
      *
      * @return
@@ -332,7 +405,14 @@ public class SchemaChecker
      */
     public List<Throwable> getErrors()
     {
-        return errorsList;
+        if ( schemaManager != null )
+        {
+            return schemaManager.getErrors();
+        }
+        else
+        {
+            return new ArrayList<Throwable>();
+        }
     }
 
 
@@ -342,10 +422,9 @@ public class SchemaChecker
      * @return
      *      the warnings
      */
-    public List<Object> getWarnings()
+    public List<SchemaWarning> getWarnings()
     {
-        // TODO
-        return new ArrayList<Object>();
+        return warningsList;
     }
 
 
@@ -435,8 +514,7 @@ public class SchemaChecker
      */
     public List<Object> getWarnings( SchemaObject so )
     {
-        return new ArrayList<Object>();
-        //   return ( List<?> ) warningsMap.get( so );
+        return ( List<Object> ) warningsMap.get( so );
     }
 
 

Copied: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaWarning.java
(from r1209033, directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaCheckerElement.java)
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaWarning.java?p2=directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaWarning.java&p1=directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaCheckerElement.java&r1=1209033&r2=1209068&rev=1209068&view=diff
==============================================================================
--- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaCheckerElement.java
(original)
+++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemachecker/SchemaWarning.java
Thu Dec  1 13:14:24 2011
@@ -24,11 +24,11 @@ import org.apache.directory.shared.ldap.
 
 
 /**
- * Common interface for the all the schema errors.
+ * This interface defines a schema warning.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public interface SchemaCheckerElement
+public interface SchemaWarning
 {
     /**
      * Gets the source object.

Modified: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewContentProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewContentProvider.java?rev=1209068&r1=1209067&r2=1209068&view=diff
==============================================================================
--- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewContentProvider.java
(original)
+++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewContentProvider.java
Thu Dec  1 13:14:24 2011
@@ -26,6 +26,7 @@ import java.util.List;
 import org.apache.directory.shared.ldap.model.exception.LdapSchemaException;
 import org.apache.directory.studio.schemaeditor.Activator;
 import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaChecker;
+import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaWarning;
 import org.apache.directory.studio.schemaeditor.view.wrappers.Folder;
 import org.apache.directory.studio.schemaeditor.view.wrappers.Folder.FolderType;
 import org.apache.directory.studio.schemaeditor.view.wrappers.ProblemsViewRoot;
@@ -103,17 +104,16 @@ public class ProblemsViewContentProvider
                         }
                     }
 
-                    // TODO
-//                    SchemaWarning[] warnings = schemaChecker.getWarnings().toArray( new
SchemaWarning[0] );
-//                    if ( !( warnings.length == 0 ) )
-//                    {
-//                        Folder warningsFolder = new Folder( FolderType.WARNING, root );
-//                        root.addChild( warningsFolder );
-//                        for ( SchemaWarning warning : warnings )
-//                        {
-//                            warningsFolder.addChild( new SchemaWarningWrapper( warning,
warningsFolder ) );
-//                        }
-//                    }
+                    SchemaWarning[] warnings = schemaChecker.getWarnings().toArray( new SchemaWarning[0]
);
+                    if ( !( warnings.length == 0 ) )
+                    {
+                        Folder warningsFolder = new Folder( FolderType.WARNING, root );
+                        root.addChild( warningsFolder );
+                        for ( SchemaWarning warning : warnings )
+                        {
+                            warningsFolder.addChild( new SchemaWarningWrapper( warning, warningsFolder
) );
+                        }
+                    }
                 }
             }
 

Modified: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewLabelProvider.java?rev=1209068&r1=1209067&r2=1209068&view=diff
==============================================================================
--- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewLabelProvider.java
(original)
+++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewLabelProvider.java
Thu Dec  1 13:14:24 2011
@@ -29,6 +29,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.studio.schemaeditor.Activator;
 import org.apache.directory.studio.schemaeditor.PluginConstants;
 import org.apache.directory.studio.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.schemaeditor.model.schemachecker.NoAliasWarning;
+import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaWarning;
 import org.apache.directory.studio.schemaeditor.view.wrappers.Folder;
 import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaErrorWrapper;
 import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaWarningWrapper;
@@ -95,22 +97,20 @@ public class ProblemsViewLabelProvider e
 
             if ( columnIndex == 0 )
             {
-                return ""; // TODO getMessage( warningWrapper.getSchemaWarning() );
+                return getMessage( warningWrapper.getSchemaWarning() );
             }
             else if ( columnIndex == 1 )
             {
-                return "";
-                // TODO
-                //                String name = warningWrapper.getSchemaWarning().getSource().getName();
-                //
-                //                if ( ( name != null ) && ( !name.equals( "" ) )
) //$NON-NLS-1$
-                //                {
-                //                    return name;
-                //                }
-                //                else
-                //                {
-                //                    return warningWrapper.getSchemaWarning().getSource().getOid();
-                //                }
+                String name = warningWrapper.getSchemaWarning().getSource().getName();
+
+                if ( ( name != null ) && ( !name.equals( "" ) ) ) //$NON-NLS-1$
+                {
+                    return name;
+                }
+                else
+                {
+                    return warningWrapper.getSchemaWarning().getSource().getOid();
+                }
             }
         }
         else if ( element instanceof Folder )
@@ -137,7 +137,7 @@ public class ProblemsViewLabelProvider e
         {
             switch ( exception.getCode() )
             {
-                // Codes for all Schema Objects
+            // Codes for all Schema Objects
                 case NAME_ALREADY_REGISTERED:
                     return getMessageNameAlreadyRegistered( exception );
                 case OID_ALREADY_REGISTERED:
@@ -204,24 +204,31 @@ public class ProblemsViewLabelProvider e
         }
 
         return ""; //$NON-NLS-1$
+    }
 
-        //        else if ( element instanceof NoAliasWarning )
-        //        {
-        //            NoAliasWarning noAliasWarning = ( NoAliasWarning ) element;
-        //            SchemaObject source = noAliasWarning.getSourceObject();
-        //            if ( source instanceof AttributeType )
-        //            {
-        //                return NLS
-        //                        .bind(
-        //                            Messages.getString( "ProblemsViewLabelProvider.NoAliasWarningAttributeType"
), new String[] { source.getOid() } ); //$NON-NLS-1$
-        //            }
-        //            else if ( source instanceof ObjectClass )
-        //            {
-        //                return NLS
-        //                        .bind(
-        //                            Messages.getString( "ProblemsViewLabelProvider.NoAliasWarningObjectClass"
), new String[] { source.getOid() } ); //$NON-NLS-1$
-        //            }
-        //        }
+
+    private String getMessage( SchemaWarning warning )
+    {
+
+        if ( warning instanceof NoAliasWarning )
+        {
+            NoAliasWarning noAliasWarning = ( NoAliasWarning ) warning;
+            SchemaObject source = noAliasWarning.getSource();
+            if ( source instanceof AttributeType )
+            {
+                return NLS
+                    .bind(
+                        Messages.getString( "ProblemsViewLabelProvider.NoAliasWarningAttributeType"
), new String[] { source.getOid() } ); //$NON-NLS-1$
+            }
+            else if ( source instanceof ObjectClass )
+            {
+                return NLS
+                    .bind(
+                        Messages.getString( "ProblemsViewLabelProvider.NoAliasWarningObjectClass"
), new String[] { source.getOid() } ); //$NON-NLS-1$
+            }
+        }
+
+        return ""; //$NON-NLS-1$
     }
 
 

Modified: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaWarningWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaWarningWrapper.java?rev=1209068&r1=1209067&r2=1209068&view=diff
==============================================================================
--- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaWarningWrapper.java
(original)
+++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaWarningWrapper.java
Thu Dec  1 13:14:24 2011
@@ -19,6 +19,8 @@
  */
 package org.apache.directory.studio.schemaeditor.view.wrappers;
 
+import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaWarning;
+
 
 
 
@@ -29,8 +31,8 @@ package org.apache.directory.studio.sche
  */
 public class SchemaWarningWrapper extends AbstractTreeNode
 {
-    /** The wrapped SchemaError */
-    private Object schemaWarning;
+    /** The wrapped SchemaWarning */
+    private SchemaWarning schemaWarning;
 
 
     /**
@@ -39,7 +41,7 @@ public class SchemaWarningWrapper extend
      * @param warning
      *      the wrapped SchemaWarning
      */
-    public SchemaWarningWrapper( Object warning )
+    public SchemaWarningWrapper( SchemaWarning warning )
     {
         super( null );
         schemaWarning = warning;
@@ -54,7 +56,7 @@ public class SchemaWarningWrapper extend
      * @param parent
      *      the parent TreeNode
      */
-    public SchemaWarningWrapper( Object warning, TreeNode parent )
+    public SchemaWarningWrapper( SchemaWarning warning, TreeNode parent )
     {
         super( parent );
         schemaWarning = warning;
@@ -67,7 +69,7 @@ public class SchemaWarningWrapper extend
      * @return
      *      the wrapped SchemaWarning
      */
-    public Object getSchemaWarning()
+    public SchemaWarning getSchemaWarning()
     {
         return schemaWarning;
     }



Mime
View raw message