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

Nicolas Capponi
08.10.2016 3300da551d63df55ca61520966a459901d8e1a9b
OPENDJ-3089 Add SchemaHandler to ServerContext and SchemaBackend

- Add a field for SchemaHandler in SchemaBackend
- SchemaHandler can be retrieved from ServerContext
- There still references to server Schema in SchemaBackend
3 files modified
82 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java 33 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java 41 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/ServerContext.java 8 ●●●●● patch | view | raw | blame | history
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);
opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
@@ -575,6 +575,9 @@
  /** The schema for the Directory Server. */
  private volatile Schema schema;
  /** The schema handler provides management of the schema, including its memory and files representations. */
  private SchemaHandler schemaHandler;
  /** The schema configuration manager for the Directory Server. */
  private SchemaConfigManager schemaConfigManager;
@@ -1014,6 +1017,12 @@
    }
    @Override
    public SchemaHandler getSchemaHandler()
    {
      return directoryServer.schemaHandler;
    }
    @Override
    public DirectoryEnvironmentConfig getEnvironment()
    {
      return directoryServer.environmentConfig;
@@ -1361,22 +1370,6 @@
    initializeConfiguration();
  }
  /** Initialize the schema of this server. */
  @ActivateOnceSDKSchemaIsUsed
  private void initializeSchemaNG() throws InitializationException
  {
    SchemaHandler schemaHandler = new SchemaHandler();
    try
    {
      schemaHandler.initialize(serverContext);
    }
    catch (ConfigException e)
    {
      // TODO : fix message
      throw new InitializationException(LocalizableMessage.raw("Cannot initialize schema handler"), e);
    }
  }
  /**
   * Initializes the configuration.
   * <p>
@@ -1763,6 +1756,22 @@
    compressedSchema = new DefaultCompressedSchema(serverContext);
  }
  /** Initialize the schema of this server. */
  @ActivateOnceSDKSchemaIsUsed
  private void initializeSchemaNG() throws InitializationException
  {
    schemaHandler = new SchemaHandler();
    try
    {
      schemaHandler.initialize(serverContext);
    }
    catch (ConfigException e)
    {
      // TODO : fix message
      throw new InitializationException(LocalizableMessage.raw("Cannot initialize schema handler"), e);
    }
  }
  /**
   * Retrieves the default compressed schema manager for the Directory Server.
   *
opendj-server-legacy/src/main/java/org/opends/server/core/ServerContext.java
@@ -60,6 +60,13 @@
  org.forgerock.opendj.ldap.schema.Schema getSchemaNG();
  /**
   * Returns the schema handler, which provides schema management.
   *
   * @return the schema handler
   */
  SchemaHandler getSchemaHandler();
  /**
   * Returns the environment of the server.
   *
   * @return the environment
@@ -126,4 +133,5 @@
   * @return the Crypto Manager for the instance
   */
  CryptoManager getCryptoManager();
}