From c9364374a0c5ea8c1a151e3eb8deacd91b507b84 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 05 Dec 2013 16:38:09 +0000
Subject: [PATCH] Eliminate duplicate code by creating SchemaValidationPolicy#adaptSchemaForValidation.
---
opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIFEntryReader.java | 8 ++------
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaValidationPolicy.java | 17 ++++++++++++++++-
opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIFChangeRecordReader.java | 10 +++-------
3 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaValidationPolicy.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaValidationPolicy.java
index 493f782..de93d7a 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaValidationPolicy.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaValidationPolicy.java
@@ -21,7 +21,7 @@
* CDDL HEADER END
*
*
- * Copyright 2011-2012 ForgeRock AS
+ * Copyright 2011-2013 ForgeRock AS
*/
package org.forgerock.opendj.ldap.schema;
@@ -405,6 +405,21 @@
return this;
}
+ /**
+ * Returns a strict view of the provided schema if the this policy is
+ * configured to check attributes and object class, or a non-strict view of
+ * the schema if not.
+ *
+ * @param schema
+ * The schema to be adapted according to this policy.
+ * @return A strict or non-strict view of {@code schema} depending on
+ * {@link #checkAttributesAndObjectClasses()}.
+ */
+ public Schema adaptSchemaForValidation(final Schema schema) {
+ return checkAttributesAndObjectClasses().needsChecking() ? schema.asStrictSchema() : schema
+ .asNonStrictSchema();
+ }
+
// Assigns the provided options to this set of options.
SchemaValidationPolicy assign(final SchemaValidationPolicy policy) {
this.checkAttributeValues = policy.checkAttributeValues;
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIFChangeRecordReader.java b/opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIFChangeRecordReader.java
index 9e6fb68..3406171 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIFChangeRecordReader.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIFChangeRecordReader.java
@@ -22,7 +22,7 @@
*
*
* Copyright 2009-2010 Sun Microsystems, Inc.
- * Portions copyright 2011-2012 ForgeRock AS
+ * Portions copyright 2011-2013 ForgeRock AS
*/
package org.forgerock.opendj.ldif;
@@ -375,9 +375,7 @@
*/
public LDIFChangeRecordReader setSchema(final Schema schema) {
Validator.ensureNotNull(schema);
- this.schema =
- schemaValidationPolicy.checkAttributesAndObjectClasses().needsChecking() ? schema
- .asStrictSchema() : schema.asNonStrictSchema();
+ this.schema = schemaValidationPolicy.adaptSchemaForValidation(schema);
return this;
}
@@ -398,9 +396,7 @@
*/
public LDIFChangeRecordReader setSchemaValidationPolicy(final SchemaValidationPolicy policy) {
this.schemaValidationPolicy = SchemaValidationPolicy.copyOf(policy);
- this.schema =
- schemaValidationPolicy.checkAttributesAndObjectClasses().needsChecking() ? schema
- .asStrictSchema() : schema.asNonStrictSchema();
+ this.schema = schemaValidationPolicy.adaptSchemaForValidation(schema);
return this;
}
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIFEntryReader.java b/opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIFEntryReader.java
index ff97a84..ad17692 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIFEntryReader.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIFEntryReader.java
@@ -347,9 +347,7 @@
*/
public LDIFEntryReader setSchema(final Schema schema) {
Validator.ensureNotNull(schema);
- this.schema =
- schemaValidationPolicy.checkAttributesAndObjectClasses().needsChecking() ? schema
- .asStrictSchema() : schema.asNonStrictSchema();
+ this.schema = schemaValidationPolicy.adaptSchemaForValidation(schema);
return this;
}
@@ -370,9 +368,7 @@
*/
public LDIFEntryReader setSchemaValidationPolicy(final SchemaValidationPolicy policy) {
this.schemaValidationPolicy = SchemaValidationPolicy.copyOf(policy);
- this.schema =
- schemaValidationPolicy.checkAttributesAndObjectClasses().needsChecking() ? schema
- .asStrictSchema() : schema.asNonStrictSchema();
+ this.schema = schemaValidationPolicy.adaptSchemaForValidation(schema);
return this;
}
--
Gitblit v1.10.0