From d2ffb3eb61ac14df25d56086bb36b544890bb69e Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Mon, 27 Jun 2011 16:42:54 +0000
Subject: [PATCH] Fix OPENDJ-217: Unpredictable failures during schema validation using SDK
---
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/DITStructureRule.java | 42 +++++++++++++++++++++++++++++++++++-------
1 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/DITStructureRule.java b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/DITStructureRule.java
index 36bddbc..0d2cb87 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/DITStructureRule.java
+++ b/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));
}
}
--
Gitblit v1.10.0