mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
22.19.2014 2f013f1734a0fc098255f578fc2847f6194f46e1
Improved code readability.


BaseDnRegistry.java:
In registerBaseDN(), extracted method getSuperiorBackend().
1 files modified
56 ■■■■ changed files
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/BaseDnRegistry.java 56 ●●●● patch | view | raw | blame | history
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.