From 2f013f1734a0fc098255f578fc2847f6194f46e1 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 22 Dec 2014 10:19:56 +0000
Subject: [PATCH] Improved code readability.

---
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/BaseDnRegistry.java |   56 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/BaseDnRegistry.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/BaseDnRegistry.java
index fae6bb7..91bd1b5 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/BaseDnRegistry.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/BaseDnRegistry.java
@@ -110,32 +110,7 @@
     // Check to see if the new base DN is subordinate to any other base DN
     // already defined.  If it is, then any other base DN(s) for the same
     // backend must also be subordinate to the same base DN.
-    Backend<?> superiorBackend = null;
-    DN      superiorBaseDN         ;
-    DN      parentDN        = baseDN.parent();
-    while (parentDN != null)
-    {
-      if (baseDNs.containsKey(parentDN))
-      {
-        superiorBaseDN  = parentDN;
-        superiorBackend = baseDNs.get(parentDN);
-
-        for (DN dn : otherBaseDNs)
-        {
-          if (! dn.isDescendantOf(superiorBaseDN))
-          {
-            LocalizableMessage message = ERR_REGISTER_BASEDN_DIFFERENT_PARENT_BASES.
-                get(baseDN, backend.getBackendID(), dn);
-            throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
-          }
-        }
-
-        break;
-      }
-
-      parentDN = parentDN.parent();
-    }
-
+    final Backend<?> superiorBackend = getSuperiorBackend(baseDN, otherBaseDNs, backend.getBackendID());
     if (superiorBackend == null && backend.getParentBackend() != null)
     {
       LocalizableMessage message = ERR_REGISTER_BASEDN_NEW_BASE_NOT_SUBORDINATE.
@@ -151,7 +126,7 @@
     for (DN dn : baseDNs.keySet())
     {
       Backend<?> b = baseDNs.get(dn);
-      parentDN = dn.parent();
+      DN parentDN = dn.parent();
       while (parentDN != null)
       {
         if (parentDN.equals(baseDN))
@@ -238,6 +213,33 @@
     return errors;
   }
 
+  private Backend<?> getSuperiorBackend(DN baseDN, LinkedList<DN> otherBaseDNs, String backendID)
+      throws DirectoryException
+  {
+    Backend<?> superiorBackend = null;
+    DN parentDN = baseDN.parent();
+    while (parentDN != null)
+    {
+      if (baseDNs.containsKey(parentDN))
+      {
+        superiorBackend = baseDNs.get(parentDN);
+
+        for (DN dn : otherBaseDNs)
+        {
+          if (!dn.isDescendantOf(parentDN))
+          {
+            LocalizableMessage msg = ERR_REGISTER_BASEDN_DIFFERENT_PARENT_BASES.get(baseDN, backendID, dn);
+            throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, msg);
+          }
+        }
+        break;
+      }
+
+      parentDN = parentDN.parent();
+    }
+    return superiorBackend;
+  }
+
 
   /**
    * Deregisters a base DN with this registry.

--
Gitblit v1.10.0