From ca6f8fa7fa2d8d4f69c076dc52f9e04d63f4bc8a Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 04 Mar 2014 11:28:12 +0000
Subject: [PATCH] OPENDJ-1308 Migrate schema support

---
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/SchemaBackend.java   |  320 ++++++-------------------------
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/SchemaConfigManager.java |  270 ++++++--------------------
 2 files changed, 128 insertions(+), 462 deletions(-)

diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/SchemaBackend.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/SchemaBackend.java
index 3a6a2ed..aa04f87 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/SchemaBackend.java
@@ -1413,8 +1413,7 @@
                     ResultCode.INVALID_ATTRIBUTE_SYNTAX, message, de);
               }
 
-              removeDITContentRule(dcr, newSchema, mods, pos,
-                  modifiedSchemaFiles);
+              removeDITContentRule(dcr, newSchema, modifiedSchemaFiles);
             }
           }
           else if (at.equals(ditStructureRulesType))
@@ -1461,8 +1460,7 @@
                     ResultCode.INVALID_ATTRIBUTE_SYNTAX, message, de);
               }
 
-              removeMatchingRuleUse(mru, newSchema, mods, pos,
-                  modifiedSchemaFiles);
+              removeMatchingRuleUse(mru, newSchema, modifiedSchemaFiles);
             }
           }
           else if (at.equals(ldapSyntaxesType))
@@ -1719,46 +1717,60 @@
     if (existingType == null)
     {
       schema.registerAttributeType(attributeType, false);
-      String schemaFile = getSchemaFile(attributeType);
-      if ((schemaFile == null) || (schemaFile.length() == 0))
-      {
-        schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        setSchemaFile(attributeType, schemaFile);
-      }
-
-      modifiedSchemaFiles.add(schemaFile);
+      addNewSchemaElement(modifiedSchemaFiles, attributeType);
     }
     else
     {
       schema.deregisterAttributeType(existingType);
       schema.registerAttributeType(attributeType, false);
       schema.rebuildDependentElements(existingType);
+      replaceExistingSchemaElement(modifiedSchemaFiles, attributeType,
+          existingType);
+    }
+  }
 
-      if ((getSchemaFile(attributeType) == null)
-          || (getSchemaFile(attributeType).length() == 0))
+
+
+  private void addNewSchemaElement(Set<String> modifiedSchemaFiles,
+      SchemaFileElement elem)
+  {
+    String schemaFile = getSchemaFile(elem);
+    if ((schemaFile == null) || (schemaFile.length() == 0))
+    {
+      schemaFile = FILE_USER_SCHEMA_ELEMENTS;
+      setSchemaFile(elem, schemaFile);
+    }
+
+    modifiedSchemaFiles.add(schemaFile);
+  }
+
+
+
+  private <T extends SchemaFileElement> void replaceExistingSchemaElement(
+      Set<String> modifiedSchemaFiles, T newElem, T existingElem)
+  {
+    String newSchemaFile = getSchemaFile(newElem);
+    String oldSchemaFile = getSchemaFile(existingElem);
+    if (newSchemaFile == null || newSchemaFile.length() == 0)
+    {
+      if (oldSchemaFile == null || oldSchemaFile.length() == 0)
       {
-        String schemaFile = getSchemaFile(existingType);
-        if ((schemaFile == null) || (schemaFile.length() == 0))
-        {
-          schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        }
+        oldSchemaFile = FILE_USER_SCHEMA_ELEMENTS;
+      }
 
-        setSchemaFile(attributeType, schemaFile);
-        modifiedSchemaFiles.add(schemaFile);
+      setSchemaFile(newElem, oldSchemaFile);
+      modifiedSchemaFiles.add(oldSchemaFile);
+    }
+    else
+    {
+      if ((oldSchemaFile == null) || oldSchemaFile.equals(newSchemaFile))
+      {
+        modifiedSchemaFiles.add(newSchemaFile);
       }
       else
       {
-        String newSchemaFile = getSchemaFile(attributeType);
-        String oldSchemaFile = getSchemaFile(existingType);
-        if ((oldSchemaFile == null) || oldSchemaFile.equals(newSchemaFile))
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-        }
-        else
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-          modifiedSchemaFiles.add(oldSchemaFile);
-        }
+        modifiedSchemaFiles.add(newSchemaFile);
+        modifiedSchemaFiles.add(oldSchemaFile);
       }
     }
   }
@@ -2048,47 +2060,15 @@
     if (existingClass == null)
     {
       schema.registerObjectClass(objectClass, false);
-      String schemaFile = getSchemaFile(objectClass);
-      if ((schemaFile == null) || (schemaFile.length() == 0))
-      {
-        schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        setSchemaFile(objectClass, schemaFile);
-      }
-
-      modifiedSchemaFiles.add(schemaFile);
+      addNewSchemaElement(modifiedSchemaFiles, objectClass);
     }
     else
     {
       schema.deregisterObjectClass(existingClass);
       schema.registerObjectClass(objectClass, false);
       schema.rebuildDependentElements(existingClass);
-
-      if ((getSchemaFile(objectClass) == null)
-          || (getSchemaFile(objectClass).length() == 0))
-      {
-        String schemaFile = getSchemaFile(existingClass);
-        if ((schemaFile == null) || (schemaFile.length() == 0))
-        {
-          schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        }
-
-        setSchemaFile(objectClass, schemaFile);
-        modifiedSchemaFiles.add(schemaFile);
-      }
-      else
-      {
-        String newSchemaFile = getSchemaFile(objectClass);
-        String oldSchemaFile = getSchemaFile(existingClass);
-        if ((oldSchemaFile == null) || oldSchemaFile.equals(newSchemaFile))
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-        }
-        else
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-          modifiedSchemaFiles.add(oldSchemaFile);
-        }
-      }
+      replaceExistingSchemaElement(modifiedSchemaFiles, objectClass,
+          existingClass);
     }
   }
 
@@ -2351,47 +2331,14 @@
     if (existingNF == null)
     {
       schema.registerNameForm(nameForm, false);
-      String schemaFile = getSchemaFile(nameForm);
-      if ((schemaFile == null) || (schemaFile.length() == 0))
-      {
-        schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        setSchemaFile(nameForm, schemaFile);
-      }
-
-      modifiedSchemaFiles.add(schemaFile);
+      addNewSchemaElement(modifiedSchemaFiles, nameForm);
     }
     else
     {
       schema.deregisterNameForm(existingNF);
       schema.registerNameForm(nameForm, false);
       schema.rebuildDependentElements(existingNF);
-
-      if ((getSchemaFile(nameForm) == null) ||
-          (getSchemaFile(nameForm).length() == 0))
-      {
-        String schemaFile = getSchemaFile(existingNF);
-        if ((schemaFile == null) || (schemaFile.length() == 0))
-        {
-          schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        }
-
-        setSchemaFile(nameForm, schemaFile);
-        modifiedSchemaFiles.add(schemaFile);
-      }
-      else
-      {
-        String newSchemaFile = getSchemaFile(nameForm);
-        String oldSchemaFile = getSchemaFile(existingNF);
-        if ((oldSchemaFile == null) || oldSchemaFile.equals(newSchemaFile))
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-        }
-        else
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-          modifiedSchemaFiles.add(oldSchemaFile);
-        }
-      }
+      replaceExistingSchemaElement(modifiedSchemaFiles, nameForm, existingNF);
     }
   }
 
@@ -2669,47 +2616,15 @@
     if (existingDCR == null)
     {
       schema.registerDITContentRule(ditContentRule, false);
-      String schemaFile = getSchemaFile(ditContentRule);
-      if ((schemaFile == null) || (schemaFile.length() == 0))
-      {
-        schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        setSchemaFile(ditContentRule, schemaFile);
-      }
-
-      modifiedSchemaFiles.add(schemaFile);
+      addNewSchemaElement(modifiedSchemaFiles, ditContentRule);
     }
     else
     {
       schema.deregisterDITContentRule(existingDCR);
       schema.registerDITContentRule(ditContentRule, false);
       schema.rebuildDependentElements(existingDCR);
-
-      if ((getSchemaFile(ditContentRule) == null) ||
-          (getSchemaFile(ditContentRule).length() == 0))
-      {
-        String schemaFile = getSchemaFile(existingDCR);
-        if ((schemaFile == null) || (schemaFile.length() == 0))
-        {
-          schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        }
-
-        setSchemaFile(ditContentRule, schemaFile);
-        modifiedSchemaFiles.add(schemaFile);
-      }
-      else
-      {
-        String newSchemaFile = getSchemaFile(ditContentRule);
-        String oldSchemaFile = getSchemaFile(existingDCR);
-        if ((oldSchemaFile == null) || oldSchemaFile.equals(newSchemaFile))
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-        }
-        else
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-          modifiedSchemaFiles.add(oldSchemaFile);
-        }
-      }
+      replaceExistingSchemaElement(modifiedSchemaFiles, ditContentRule,
+          existingDCR);
     }
   }
 
@@ -2729,10 +2644,6 @@
    *                              schema.
    * @param  schema               The schema from which the DIT content rule
    *                              should be removed.
-   * @param  modifications        The full set of modifications to be processed
-   *                              against the server schema.
-   * @param  currentPosition      The position of the modification currently
-   *                              being performed.
    * @param  modifiedSchemaFiles  The names of the schema files containing
    *                              schema elements that have been updated as part
    *                              of the schema modification.
@@ -2742,11 +2653,7 @@
    *                              schema.
    */
   private void removeDITContentRule(DITContentRule ditContentRule,
-                                    Schema schema,
-                                    ArrayList<Modification> modifications,
-                                    int currentPosition,
-                                    Set<String> modifiedSchemaFiles)
-          throws DirectoryException
+      Schema schema, Set<String> modifiedSchemaFiles) throws DirectoryException
   {
     // See if the specified DIT content rule is actually defined in the server
     // schema.  If not, then fail.
@@ -2890,47 +2797,15 @@
     if (existingDSR == null)
     {
       schema.registerDITStructureRule(ditStructureRule, false);
-      String schemaFile = getSchemaFile(ditStructureRule);
-      if ((schemaFile == null) || (schemaFile.length() == 0))
-      {
-        schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        setSchemaFile(ditStructureRule, schemaFile);
-      }
-
-      modifiedSchemaFiles.add(schemaFile);
+      addNewSchemaElement(modifiedSchemaFiles, ditStructureRule);
     }
     else
     {
       schema.deregisterDITStructureRule(existingDSR);
       schema.registerDITStructureRule(ditStructureRule, false);
       schema.rebuildDependentElements(existingDSR);
-
-      if ((getSchemaFile(ditStructureRule) == null) ||
-          (getSchemaFile(ditStructureRule).length() == 0))
-      {
-        String schemaFile = getSchemaFile(existingDSR);
-        if ((schemaFile == null) || (schemaFile.length() == 0))
-        {
-          schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        }
-
-        setSchemaFile(ditStructureRule, schemaFile);
-        modifiedSchemaFiles.add(schemaFile);
-      }
-      else
-      {
-        String newSchemaFile = getSchemaFile(ditStructureRule);
-        String oldSchemaFile = getSchemaFile(existingDSR);
-        if ((oldSchemaFile == null) || oldSchemaFile.equals(newSchemaFile))
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-        }
-        else
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-          modifiedSchemaFiles.add(oldSchemaFile);
-        }
-      }
+      replaceExistingSchemaElement(modifiedSchemaFiles, ditStructureRule,
+          existingDSR);
     }
   }
 
@@ -3150,47 +3025,15 @@
     if (existingMRU == null)
     {
       schema.registerMatchingRuleUse(matchingRuleUse, false);
-      String schemaFile = getSchemaFile(matchingRuleUse);
-      if ((schemaFile == null) || (schemaFile.length() == 0))
-      {
-        schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        setSchemaFile(matchingRuleUse, schemaFile);
-      }
-
-      modifiedSchemaFiles.add(schemaFile);
+      addNewSchemaElement(modifiedSchemaFiles, matchingRuleUse);
     }
     else
     {
       schema.deregisterMatchingRuleUse(existingMRU);
       schema.registerMatchingRuleUse(matchingRuleUse, false);
       schema.rebuildDependentElements(existingMRU);
-
-      if ((getSchemaFile(matchingRuleUse) == null) ||
-          (getSchemaFile(matchingRuleUse).length() == 0))
-      {
-        String schemaFile = getSchemaFile(existingMRU);
-        if ((schemaFile == null) || (schemaFile.length() == 0))
-        {
-          schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        }
-
-        setSchemaFile(matchingRuleUse, schemaFile);
-        modifiedSchemaFiles.add(schemaFile);
-      }
-      else
-      {
-        String newSchemaFile = getSchemaFile(matchingRuleUse);
-        String oldSchemaFile = getSchemaFile(existingMRU);
-        if ((oldSchemaFile == null) || oldSchemaFile.equals(newSchemaFile))
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-        }
-        else
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-          modifiedSchemaFiles.add(oldSchemaFile);
-        }
-      }
+      replaceExistingSchemaElement(modifiedSchemaFiles, matchingRuleUse,
+          existingMRU);
     }
   }
 
@@ -3211,22 +3054,15 @@
    *                              server schema.
    * @param  schema               The schema from which the matching rule use
    *                              should be removed.
-   * @param  modifications        The full set of modifications to be processed
-   *                              against the server schema.
-   * @param  currentPosition      The position of the modification currently
-   *                              being performed.
    * @param  modifiedSchemaFiles  The names of the schema files containing
    *                              schema elements that have been updated as part
    *                              of the schema modification.
-   *
    * @throws  DirectoryException  If a problem occurs while attempting to remove
    *                              the provided matching rule use from the server
    *                              schema.
    */
   private void removeMatchingRuleUse(MatchingRuleUse matchingRuleUse,
                                      Schema schema,
-                                     ArrayList<Modification> modifications,
-                                     int currentPosition,
                                      Set<String> modifiedSchemaFiles)
           throws DirectoryException
   {
@@ -3299,47 +3135,15 @@
     if (existingLSD == null)
     {
       schema.registerLdapSyntaxDescription(ldapSyntaxDesc, false);
-      String schemaFile = getSchemaFile(ldapSyntaxDesc);
-      if ((schemaFile == null) || (schemaFile.length() == 0))
-      {
-        schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        setSchemaFile(ldapSyntaxDesc, schemaFile);
-      }
-
-      modifiedSchemaFiles.add(schemaFile);
+      addNewSchemaElement(modifiedSchemaFiles, ldapSyntaxDesc);
     }
     else
     {
       schema.deregisterLdapSyntaxDescription(existingLSD);
       schema.registerLdapSyntaxDescription(ldapSyntaxDesc, false);
       schema.rebuildDependentElements(existingLSD);
-
-      if ((getSchemaFile(ldapSyntaxDesc) == null) ||
-          (getSchemaFile(ldapSyntaxDesc).length() == 0))
-      {
-        String schemaFile = getSchemaFile(ldapSyntaxDesc);
-        if ((schemaFile == null) || (schemaFile.length() == 0))
-        {
-          schemaFile = FILE_USER_SCHEMA_ELEMENTS;
-        }
-
-        setSchemaFile(ldapSyntaxDesc, schemaFile);
-        modifiedSchemaFiles.add(schemaFile);
-      }
-      else
-      {
-        String newSchemaFile = getSchemaFile(ldapSyntaxDesc);
-        String oldSchemaFile = getSchemaFile(existingLSD);
-        if ((oldSchemaFile == null) || oldSchemaFile.equals(newSchemaFile))
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-        }
-        else
-        {
-          modifiedSchemaFiles.add(newSchemaFile);
-          modifiedSchemaFiles.add(oldSchemaFile);
-        }
-      }
+      replaceExistingSchemaElement(modifiedSchemaFiles, ldapSyntaxDesc,
+          existingLSD);
     }
   }
 
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/SchemaConfigManager.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/SchemaConfigManager.java
index dbffb7f..f968f40 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/SchemaConfigManager.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/SchemaConfigManager.java
@@ -36,6 +36,7 @@
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.forgerock.opendj.ldap.ModificationType;
+import org.opends.server.api.AttributeSyntax;
 import org.opends.server.config.ConfigException;
 import org.opends.server.schema.*;
 import org.opends.server.types.*;
@@ -89,13 +90,11 @@
   public static String getSchemaDirectoryPath()
   {
     File schemaDir =
-              DirectoryServer.getEnvironmentConfig().
-                getSchemaDirectory();
+        DirectoryServer.getEnvironmentConfig().getSchemaDirectory();
     if (schemaDir != null) {
       return schemaDir.getAbsolutePath();
-    } else {
-      return null;
     }
+    return null;
   }
 
 
@@ -501,15 +500,8 @@
       ldapSyntax.initializeSyntax(null);
     }
 
-    AttributeType ldapSyntaxAttrType =
-         schema.getAttributeType(ATTR_LDAP_SYNTAXES_LC);
-    if (ldapSyntaxAttrType == null)
-    {
-      ldapSyntaxAttrType =
-           DirectoryServer.getDefaultAttributeType(ATTR_LDAP_SYNTAXES,
-                                                   ldapSyntax);
-    }
-
+    AttributeType ldapSyntaxAttrType = getAttributeType(
+        schema, ATTR_LDAP_SYNTAXES, ATTR_LDAP_SYNTAXES_LC, ldapSyntax);
     return createAddModifications(entry, mods, ldapSyntaxAttrType);
   }
 
@@ -536,15 +528,8 @@
       attrTypeSyntax.initializeSyntax(null);
     }
 
-    AttributeType attributeAttrType =
-         schema.getAttributeType(ATTR_ATTRIBUTE_TYPES_LC);
-    if (attributeAttrType == null)
-    {
-      attributeAttrType =
-           DirectoryServer.getDefaultAttributeType(ATTR_ATTRIBUTE_TYPES,
-                                                   attrTypeSyntax);
-    }
-
+    AttributeType attributeAttrType = getAttributeType(
+        schema, ATTR_ATTRIBUTE_TYPES, ATTR_ATTRIBUTE_TYPES_LC, attrTypeSyntax);
     return createAddModifications(entry, mods, attributeAttrType);
   }
 
@@ -571,15 +556,8 @@
       ocSyntax.initializeSyntax(null);
     }
 
-    AttributeType objectclassAttrType =
-         schema.getAttributeType(ATTR_OBJECTCLASSES_LC);
-    if (objectclassAttrType == null)
-    {
-      objectclassAttrType =
-           DirectoryServer.getDefaultAttributeType(ATTR_OBJECTCLASSES,
-                                                   ocSyntax);
-    }
-
+    AttributeType objectclassAttrType = getAttributeType(
+        schema, ATTR_OBJECTCLASSES, ATTR_OBJECTCLASSES_LC, ocSyntax);
     return createAddModifications(entry, mods, objectclassAttrType);
   }
 
@@ -606,14 +584,8 @@
       nfSyntax.initializeSyntax(null);
     }
 
-    AttributeType nameFormAttrType =
-         schema.getAttributeType(ATTR_NAME_FORMS_LC);
-    if (nameFormAttrType == null)
-    {
-      nameFormAttrType =
-           DirectoryServer.getDefaultAttributeType(ATTR_NAME_FORMS, nfSyntax);
-    }
-
+    AttributeType nameFormAttrType = getAttributeType(
+        schema, ATTR_NAME_FORMS, ATTR_NAME_FORMS_LC, nfSyntax);
     return createAddModifications(entry, mods, nameFormAttrType);
   }
 
@@ -641,15 +613,8 @@
       dcrSyntax.initializeSyntax(null);
     }
 
-    AttributeType dcrAttrType =
-         schema.getAttributeType(ATTR_DIT_CONTENT_RULES_LC);
-    if (dcrAttrType == null)
-    {
-      dcrAttrType =
-           DirectoryServer.getDefaultAttributeType(ATTR_DIT_CONTENT_RULES,
-                                                   dcrSyntax);
-    }
-
+    AttributeType dcrAttrType = getAttributeType(
+        schema, ATTR_DIT_CONTENT_RULES, ATTR_DIT_CONTENT_RULES_LC, dcrSyntax);
     return createAddModifications(entry, mods, dcrAttrType);
   }
 
@@ -677,15 +642,8 @@
       dsrSyntax.initializeSyntax(null);
     }
 
-    AttributeType dsrAttrType =
-         schema.getAttributeType(ATTR_DIT_STRUCTURE_RULES_LC);
-    if (dsrAttrType == null)
-    {
-      dsrAttrType =
-           DirectoryServer.getDefaultAttributeType(ATTR_DIT_STRUCTURE_RULES,
-                                                   dsrSyntax);
-    }
-
+    AttributeType dsrAttrType = getAttributeType(
+        schema, ATTR_DIT_STRUCTURE_RULES, ATTR_DIT_STRUCTURE_RULES_LC, dsrSyntax);
     return createAddModifications(entry, mods, dsrAttrType);
   }
 
@@ -713,18 +671,22 @@
       mruSyntax.initializeSyntax(null);
     }
 
-    AttributeType mruAttrType =
-         schema.getAttributeType(ATTR_MATCHING_RULE_USE_LC);
-    if (mruAttrType == null)
-    {
-      mruAttrType =
-           DirectoryServer.getDefaultAttributeType(ATTR_MATCHING_RULE_USE,
-                                                   mruSyntax);
-    }
-
+    AttributeType mruAttrType = getAttributeType(
+        schema, ATTR_MATCHING_RULE_USE, ATTR_MATCHING_RULE_USE_LC, mruSyntax);
     return createAddModifications(entry, mods, mruAttrType);
   }
 
+  private static AttributeType getAttributeType(Schema schema, String attrName,
+      String attrLowerName, AttributeSyntax<?> syntax)
+  {
+    final AttributeType attrType = schema.getAttributeType(attrLowerName);
+    if (attrType != null)
+    {
+      return attrType;
+    }
+    return DirectoryServer.getDefaultAttributeType(attrName, syntax);
+  }
+
   private static List<Attribute> createAddModifications(Entry entry,
       List<Modification> mods, AttributeType attrType)
   {
@@ -765,16 +727,8 @@
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_LDAP_SYNTAX.get(
                     schemaFile,
                     de.getMessageObject());
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, de);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, de, message);
+            continue;
           }
           catch (Exception e)
           {
@@ -783,16 +737,8 @@
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_LDAP_SYNTAX.get(
                     schemaFile,
                     v.getValue() + ":  " + getExceptionMessage(e));
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, e);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, e, message);
+            continue;
           }
 
            // Register it with the schema.  We will allow duplicates, with the
@@ -850,16 +796,8 @@
 
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_ATTR_TYPE.get(
                     schemaFile, de.getMessageObject());
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, de);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, de, message);
+            continue;
           }
           catch (Exception e)
           {
@@ -867,15 +805,8 @@
 
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_ATTR_TYPE.get(
                     schemaFile, v.getValue() + ":  " + getExceptionMessage(e));
-            if (failOnError)
-            {
-              throw new ConfigException(message, e);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, e, message);
+            continue;
           }
 
           // Register it with the schema.  We will allow duplicates, with the
@@ -933,16 +864,8 @@
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_OC.get(
                     schemaFile,
                     de.getMessageObject());
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, de);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, de, message);
+            continue;
           }
           catch (Exception e)
           {
@@ -951,16 +874,8 @@
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_OC.get(
                     schemaFile,
                     v.getValue() + ":  " + getExceptionMessage(e));
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, e);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, e, message);
+            continue;
           }
 
           // Register it with the schema.  We will allow duplicates, with the
@@ -1016,15 +931,8 @@
 
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_NAME_FORM.get(
                     schemaFile, de.getMessageObject());
-            if (failOnError)
-            {
-              throw new ConfigException(message, de);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, de, message);
+            continue;
           }
           catch (Exception e)
           {
@@ -1032,16 +940,8 @@
 
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_NAME_FORM.get(
                     schemaFile,  v.getValue() + ":  " + getExceptionMessage(e));
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, e);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, e, message);
+            continue;
           }
 
           // Register it with the schema.  We will allow duplicates, with the
@@ -1098,16 +998,8 @@
 
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_DCR.get(
                     schemaFile, de.getMessageObject());
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, de);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, de, message);
+            continue;
           }
           catch (Exception e)
           {
@@ -1115,16 +1007,8 @@
 
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_DCR.get(
                     schemaFile,v.getValue() + ":  " + getExceptionMessage(e));
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, e);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, e, message);
+            continue;
           }
 
           // Register it with the schema.  We will allow duplicates, with the
@@ -1155,6 +1039,16 @@
     }
   }
 
+  private static void reportError(boolean failOnError, Exception e,
+      LocalizableMessage message) throws ConfigException
+  {
+    if (failOnError)
+    {
+      throw new ConfigException(message, e);
+    }
+    logger.error(message);
+  }
+
   /** Parse the DIT structure rule definitions if there are any. */
   private static void parseDITStructureRuleDefinitions(Schema schema,
       String schemaFile, boolean failOnError, List<Attribute> dsrList)
@@ -1181,16 +1075,8 @@
 
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_DSR.get(
                     schemaFile, de.getMessageObject());
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, de);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, de, message);
+            continue;
           }
           catch (Exception e)
           {
@@ -1198,16 +1084,8 @@
 
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_DSR.get(
                     schemaFile, v.getValue() + ":  " + getExceptionMessage(e));
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, e);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, e, message);
+            continue;
           }
 
           // Register it with the schema.  We will allow duplicates, with the
@@ -1264,16 +1142,8 @@
 
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_MRU.get(
                     schemaFile, de.getMessageObject());
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, de);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, de, message);
+            continue;
           }
           catch (Exception e)
           {
@@ -1282,16 +1152,8 @@
             LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_MRU.get(
                     schemaFile,
                     v.getValue() + ":  " + getExceptionMessage(e));
-
-            if (failOnError)
-            {
-              throw new ConfigException(message, e);
-            }
-            else
-            {
-              logger.error(message);
-              continue;
-            }
+            reportError(failOnError, e, message);
+            continue;
           }
 
           // Register it with the schema.  We will allow duplicates, with the

--
Gitblit v1.10.0