From 85811b64468e9b7a876bd352a0299b904a53a3fb Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Mon, 31 May 2010 12:16:23 +0000
Subject: [PATCH] Fix for Issue #615. Add support for multiple object-class inheritance. Support added in the schema, core server and tools including Control-Panel

---
 opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java |  158 ++++++++++++++++++++++++++--------------------------
 1 files changed, 80 insertions(+), 78 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
index 0255778..b30d736 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
@@ -99,6 +99,8 @@
 import org.opends.messages.MessageBuilder;
 import org.opends.messages.MessageDescriptor;
 import org.opends.quicksetup.ui.CustomHTMLEditorKit;
+import org.opends.server.types.ObjectClass;
+import org.opends.server.types.ObjectClassType;
 import org.opends.server.types.OpenDsException;
 import org.opends.server.util.ServerConstants;
 
@@ -1428,14 +1430,15 @@
    * @param newElements the new items for the combo box model.
    * @param model the combo box model to be updated.
    */
-  protected void updateComboBoxModel(final Collection<?> newElements,
-      final DefaultComboBoxModel model)
+  protected void updateComboBoxModel(Collection<?> newElements,
+      DefaultComboBoxModel model)
   {
     updateComboBoxModel(newElements, model, null);
   }
 
   /**
    * Updates a combo box model with a number of items.
+   * The method assumes that is called outside the event thread.
    * @param newElements the new items for the combo box model.
    * @param model the combo box model to be updated.
    * @param comparator the object that will be used to compare the objects in
@@ -1449,70 +1452,7 @@
     {
       public void run()
       {
-        boolean changed = newElements.size() != model.getSize();
-        if (!changed)
-        {
-          int i = 0;
-          for (Object newElement : newElements)
-          {
-            if (comparator == null)
-            {
-              changed = !newElement.equals(model.getElementAt(i));
-            }
-            else
-            {
-              changed =
-                comparator.compare(newElement, model.getElementAt(i)) != 0;
-            }
-            if (changed)
-            {
-              break;
-            }
-            i++;
-          }
-        }
-        if (changed)
-        {
-          Object selected = model.getSelectedItem();
-          model.removeAllElements();
-          boolean selectDefault = false;
-          for (Object newElement : newElements)
-          {
-            model.addElement(newElement);
-          }
-          if (selected != null)
-          {
-            if (model.getIndexOf(selected) != -1)
-            {
-              model.setSelectedItem(selected);
-            }
-            else
-            {
-              selectDefault = true;
-            }
-          }
-          else
-          {
-            selectDefault = true;
-          }
-          if (selectDefault)
-          {
-            for (int i=0; i<model.getSize(); i++)
-            {
-              Object o = model.getElementAt(i);
-              if (o instanceof CategorizedComboBoxElement)
-              {
-                if (((CategorizedComboBoxElement)o).getType() ==
-                  CategorizedComboBoxElement.Type.CATEGORY)
-                {
-                  continue;
-                }
-              }
-              model.setSelectedItem(o);
-              break;
-            }
-          }
-        }
+        Utilities.updateComboBoxModel(newElements, model, comparator);
       }
     });
   }
@@ -2140,10 +2080,17 @@
         getInfo().getDirContext().search(Utilities.getJNDIName(dn),
             filter, ctls);
 
-      while (result.hasMore())
+      try
       {
-        SearchResult sr = result.next();
-        entryExists = sr != null;
+        while (result.hasMore())
+        {
+          SearchResult sr = result.next();
+          entryExists = sr != null;
+        }
+      }
+      finally
+      {
+        result.close();
       }
     }
     catch (Throwable t)
@@ -2175,23 +2122,30 @@
         getInfo().getDirContext().search(Utilities.getJNDIName(dn),
             filter, ctls);
 
-      while (result.hasMore())
+      try
       {
-        SearchResult sr = result.next();
-        Set<String> values = ConnectionUtils.getValues(sr,
-            ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME);
-        if (values != null)
+        while (result.hasMore())
         {
-          for (String s : values)
+          SearchResult sr = result.next();
+          Set<String> values = ConnectionUtils.getValues(sr,
+              ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME);
+          if (values != null)
           {
-            if (s.equalsIgnoreCase(objectClass))
+            for (String s : values)
             {
-              hasObjectClass = true;
-              break;
+              if (s.equalsIgnoreCase(objectClass))
+              {
+                hasObjectClass = true;
+                break;
+              }
             }
           }
         }
       }
+      finally
+      {
+        result.close();
+      }
     }
     catch (Throwable t)
     {
@@ -2321,4 +2275,52 @@
   {
     return taskDateFormat.format(date);
   }
+
+
+
+  /**
+   * Checks whether the provided superior object classes are compatible with
+   * the provided object class type.  If not, the method updates the provided
+   * list of error messages with a message describing the incompatibility.
+   * @param objectClassSuperiors the superior object classes.
+   * @param objectClassType the object class type.
+   * @param errors the list of error messages.
+   */
+  protected void checkCompatibleSuperiors(Set<ObjectClass> objectClassSuperiors,
+      ObjectClassType objectClassType, List<Message> errors)
+  {
+    SortedSet<String> notCompatibleClasses =
+      new TreeSet<String>(new LowerCaseComparator());
+    for (ObjectClass oc : objectClassSuperiors)
+    {
+      if (oc.getObjectClassType() == ObjectClassType.ABSTRACT)
+      {
+        // Nothing to do.
+      }
+      else if (oc.getObjectClassType() != objectClassType)
+      {
+        notCompatibleClasses.add(oc.getNameOrOID());
+      }
+    }
+    if (!notCompatibleClasses.isEmpty())
+    {
+      String arg = Utilities.getStringFromCollection(notCompatibleClasses,
+          ", ");
+      if (objectClassType == ObjectClassType.STRUCTURAL)
+      {
+        errors.add(
+            ERR_CTRL_PANEL_INCOMPATIBLE_SUPERIORS_WITH_STRUCTURAL.get(arg));
+      }
+      else if (objectClassType == ObjectClassType.AUXILIARY)
+      {
+        errors.add(
+            ERR_CTRL_PANEL_INCOMPATIBLE_SUPERIORS_WITH_AUXILIARY.get(arg));
+      }
+      else if (objectClassType == ObjectClassType.ABSTRACT)
+      {
+        errors.add(
+            ERR_CTRL_PANEL_INCOMPATIBLE_SUPERIORS_WITH_ABSTRACT.get(arg));
+      }
+    }
+  }
 }

--
Gitblit v1.10.0