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

Matthew Swift
27.42.2011 d2ffb3eb61ac14df25d56086bb36b544890bb69e
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/DITStructureRule.java
@@ -29,8 +29,7 @@
import static org.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_DSR_UNKNOWN_NAME_FORM;
import static org.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_DSR_UNKNOWN_RULE_ID;
import static org.forgerock.opendj.ldap.CoreMessages.*;
import java.util.*;
@@ -67,6 +66,12 @@
  private NameForm nameForm;
  private Set<DITStructureRule> superiorRules = Collections.emptySet();
  // Indicates whether or not validation has been performed.
  private boolean needsValidating = true;
  // The indicates whether or not validation failed.
  private boolean isValid = false;
  DITStructureRule(final Integer ruleID, final List<String> names,
@@ -305,10 +310,20 @@
  @Override
  void validate(final List<LocalizableMessage> warnings, final Schema schema)
      throws SchemaException
  boolean validate(final Schema schema,
      final List<DITStructureRule> invalidSchemaElements,
      final List<LocalizableMessage> warnings)
  {
    // Avoid validating this schema element more than once. This may occur if
    // multiple rules specify the same superior.
    if (!needsValidating)
    {
      return isValid;
    }
    // Prevent re-validation.
    needsValidating = false;
    try
    {
      nameForm = schema.getNameForm(nameFormOID);
@@ -317,7 +332,8 @@
    {
      final LocalizableMessage message = ERR_ATTR_SYNTAX_DSR_UNKNOWN_NAME_FORM
          .get(getNameOrRuleID(), nameFormOID);
      throw new SchemaException(message, e);
      failValidation(invalidSchemaElements, warnings, message);
      return false;
    }
    if (!superiorRuleIDs.isEmpty())
@@ -334,11 +350,23 @@
        {
          final LocalizableMessage message = ERR_ATTR_SYNTAX_DSR_UNKNOWN_RULE_ID
              .get(getNameOrRuleID(), id);
          throw new SchemaException(message, e);
          failValidation(invalidSchemaElements, warnings, message);
          return false;
        }
        superiorRules.add(rule);
      }
    }
    superiorRules = Collections.unmodifiableSet(superiorRules);
    return (isValid = true);
  }
  private void failValidation(final List<DITStructureRule> invalidSchemaElements,
      final List<LocalizableMessage> warnings, final LocalizableMessage message)
  {
    invalidSchemaElements.add(this);
    warnings.add(ERR_DSR_VALIDATION_FAIL.get(toString(), message));
  }
}