From 3300da551d63df55ca61520966a459901d8e1a9b Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Fri, 09 Sep 2016 09:45:22 +0000
Subject: [PATCH] OPENDJ-3089 Add SchemaHandler to ServerContext and SchemaBackend

---
 opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
index 04f325d..c50f2bb 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -83,6 +83,7 @@
 import org.opends.server.core.ModifyDNOperation;
 import org.opends.server.core.ModifyOperation;
 import org.opends.server.core.SchemaConfigManager;
+import org.opends.server.core.SchemaHandler;
 import org.opends.server.core.SearchOperation;
 import org.opends.server.core.ServerContext;
 import org.opends.server.schema.AttributeTypeSyntax;
@@ -167,6 +168,8 @@
 
   private ServerContext serverContext;
 
+  private SchemaHandler schemaHandler;
+
   /**
    * Creates a new backend with the provided information.  All backend
    * implementations must implement a default constructor that use
@@ -175,8 +178,6 @@
   public SchemaBackend()
   {
     super();
-
-    // Perform all initialization in initializeBackend.
   }
 
   @Override
@@ -216,6 +217,8 @@
     userDefinedAttributes = new ArrayList<>();
     addAllNonSchemaConfigAttributes(userDefinedAttributes, configEntry.getAllAttributes());
 
+    schemaHandler = serverContext.getSchemaHandler();
+
     currentConfig = cfg;
   }
 
@@ -237,10 +240,21 @@
       }
     }
 
-    // Identify any differences that may exist between the concatenated schema
-    // file from the last online modification and the current schema files.  If
-    // there are any differences, then they should be from making changes to the
-    // schema files with the server offline.
+    updateConcatenatedSchema();
+
+    // Register with the Directory Server as a configurable component.
+    currentConfig.addSchemaChangeListener(this);
+  }
+
+  /**
+   * Updates the concatenated schema if changes are detected in the current schema files.
+   * <p>
+   * Identify any differences that may exist between the concatenated schema file from the last
+   * online modification and the current schema files. If there are any differences, then they
+   * should be from making changes to the schema files with the server offline.
+   */
+  private void updateConcatenatedSchema() throws InitializationException
+  {
     try
     {
       // First, generate lists of elements from the current schema.
@@ -299,9 +313,6 @@
 
       logger.error(ERR_SCHEMA_ERROR_DETERMINING_SCHEMA_CHANGES, getExceptionMessage(e));
     }
-
-    // Register with the Directory Server as a configurable component.
-    currentConfig.addSchemaChangeListener(this);
   }
 
   private File getConcatFile() throws InitializationException
@@ -474,7 +485,7 @@
     }
 
     /* Add the schema definition attributes. */
-    Schema schema = DirectoryServer.getSchema();
+    org.forgerock.opendj.ldap.schema.Schema schema = serverContext.getSchemaNG();
     buildSchemaAttribute(schema.getAttributeTypes(), userAttrs,
         operationalAttrs, attributeTypesType, includeSchemaFile,
         AttributeTypeSyntax.isStripSyntaxMinimumUpperBound(),
@@ -500,7 +511,7 @@
         operationalAttrs, nameFormsType, includeSchemaFile, false, true);
     buildSchemaAttribute(schema.getDITContentRules(), userAttrs,
         operationalAttrs, ditContentRulesType, includeSchemaFile, false, true);
-    buildSchemaAttribute(schema.getDITStructureRules(), userAttrs,
+    buildSchemaAttribute(schema.getDITStuctureRules(), userAttrs,
         operationalAttrs, ditStructureRulesType, includeSchemaFile, false, true);
     buildSchemaAttribute(schema.getMatchingRuleUses(), userAttrs,
         operationalAttrs, matchingRuleUsesType, includeSchemaFile, false, true);

--
Gitblit v1.10.0