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

Nicolas Capponi
11.23.2016 f2081ed7fa0035da4567342a9510fb0112c02ccf
OPENDJ-3089 Remove simple references to SchemaConfigManager

More complex references will be addressed separately, in each of the
following classes: SchemaLoader, AddSchemaFileTask, DirectoryServer
9 files modified
129 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java 11 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/SchemaHandler.java 55 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tasks/AddSchemaFileTask.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeUtils.java 4 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/SchemaWriter.java 33 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/tasks/AddSchemaFileTaskTestCase.java 14 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/types/PrivilegeTestCase.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -77,7 +77,6 @@
import org.opends.server.core.DirectoryServer;
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;
@@ -1872,7 +1871,15 @@
  @Override
  public File getDirectory()
  {
    return new File(SchemaConfigManager.getSchemaDirectoryPath());
    try
    {
      return schemaHandler.getSchemaDirectoryPath();
    }
    catch (InitializationException e)
    {
      logger.traceException(e);
      return null;
    }
  }
  private static final FileFilter BACKUP_FILES_FILTER = new FileFilter()
opendj-server-legacy/src/main/java/org/opends/server/core/SchemaHandler.java
@@ -15,6 +15,9 @@
 */
package org.opends.server.core;
import static org.opends.messages.ConfigMessages.ERR_CONFIG_SCHEMA_DIR_NOT_DIRECTORY;
import static org.opends.messages.ConfigMessages.ERR_CONFIG_SCHEMA_NO_SCHEMA_DIR;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.opends.messages.SchemaMessages.NOTE_SCHEMA_IMPORT_FAILED;
import static org.opends.server.util.SchemaUtils.getElementSchemaFile;
@@ -227,6 +230,31 @@
  }
  /**
   * Retrieves the path to the directory containing the server schema files.
   *
   * @return The path to the directory containing the server schema files.
   * @throws InitializationException
   *            If the directory path does not exists or is not a directory
   */
  public File getSchemaDirectoryPath() throws InitializationException
  {
    final File dir = serverContext.getEnvironment().getSchemaDirectory();
    if (dir == null)
    {
      throw new InitializationException(ERR_CONFIG_SCHEMA_NO_SCHEMA_DIR.get(null));
    }
    if (!dir.exists())
    {
      throw new InitializationException(ERR_CONFIG_SCHEMA_NO_SCHEMA_DIR.get(dir.getPath()));
    }
    if (!dir.isDirectory())
    {
      throw new InitializationException(ERR_CONFIG_SCHEMA_DIR_NOT_DIRECTORY.get(dir.getPath()));
    }
    return dir;
  }
  /**
   * Update the schema using the provided schema updater.
   * <p>
   * An implicit lock is performed, so it is in general not necessary
@@ -296,7 +324,7 @@
    {
      switchSchema(newSchema);
      this.extraAttributes = newExtraAttributes;
      new SchemaWriter()
      new SchemaWriter(serverContext)
        .updateSchemaFiles(schema, newExtraAttributes.values(), modifiedSchemaFileNames, alertGenerator);
      youngestModificationTime = System.currentTimeMillis();
    }
@@ -589,29 +617,6 @@
    }
  }
  /**
   * Retrieves the path to the directory containing the server schema files.
   *
   * @return The path to the directory containing the server schema files.
   */
  private File getSchemaDirectoryPath() throws InitializationException
  {
    final File dir = serverContext.getEnvironment().getSchemaDirectory();
    if (dir == null)
    {
      throw new InitializationException(ERR_CONFIG_SCHEMA_NO_SCHEMA_DIR.get(null));
    }
    if (!dir.exists())
    {
      throw new InitializationException(ERR_CONFIG_SCHEMA_NO_SCHEMA_DIR.get(dir.getPath()));
    }
    if (!dir.isDirectory())
    {
      throw new InitializationException(ERR_CONFIG_SCHEMA_DIR_NOT_DIRECTORY.get(dir.getPath()));
    }
    return dir;
  }
  /** Returns the LDIF reader on provided LDIF file. The caller must ensure the reader is closed. */
  private EntryReader getLDIFReader(final File ldifFile, final Schema schema)
      throws InitializationException
@@ -892,7 +897,7 @@
  }
  /** A file filter implementation that accepts only LDIF files. */
  private static class SchemaFileFilter implements FilenameFilter
  public static class SchemaFileFilter implements FilenameFilter
  {
    private static final String LDIF_SUFFIX = ".ldif";
opendj-server-legacy/src/main/java/org/opends/server/tasks/AddSchemaFileTask.java
@@ -100,8 +100,7 @@
    // Get the name(s) of the schema files to add and make sure they exist in
    // the schema directory.
    String schemaInstanceDirectory =
      SchemaConfigManager.getSchemaDirectoryPath();
    String schemaInstanceDirectory = DirectoryServer.getEnvironmentConfig().getSchemaDirectory().getPath();
    filesToAdd = new TreeSet<>();
    for (Attribute a : attrList)
    {
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeUtils.java
@@ -56,7 +56,7 @@
import org.forgerock.opendj.ldif.LDIFEntryReader;
import org.forgerock.opendj.ldif.LDIFEntryWriter;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.SchemaConfigManager;
import org.opends.server.core.SchemaHandler;
import org.opends.server.util.ChangeOperationType;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
@@ -632,7 +632,7 @@
    // and add all attribute/object classes in this new super entry which
    // will be read at start-up.
    Entry theNewSchemaEntry = new LinkedHashMapEntry();
    final FilenameFilter filter = new SchemaConfigManager.SchemaFileFilter();
    final FilenameFilter filter = new SchemaHandler.SchemaFileFilter();
    for (final File f : folder.listFiles(filter))
    {
      logger.debug(LocalizableMessage.raw("Processing %s", f.getAbsolutePath()));
opendj-server-legacy/src/main/java/org/opends/server/types/SchemaWriter.java
@@ -66,7 +66,8 @@
import org.forgerock.opendj.ldap.schema.Syntax;
import org.opends.server.api.AlertGenerator;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.SchemaConfigManager;
import org.opends.server.core.SchemaHandler;
import org.opends.server.core.ServerContext;
import org.opends.server.util.Base64;
import org.opends.server.util.BuildVersion;
import org.opends.server.util.LDIFException;
@@ -88,6 +89,19 @@
  private static final AttributeType nameFormsType = getNameFormsAttributeType();
  private static final AttributeType objectClassesType = getObjectClassesAttributeType();
  private final ServerContext serverContext;
  /**
   * Creates a schema writer.
   *
   * @param serverContext
   *            The server context.
   */
  public SchemaWriter(ServerContext serverContext)
  {
    this.serverContext = serverContext;
  }
  /**
   * Compares the provided sets of schema element definitions and writes any differences found into
   * the given list of modifications.
@@ -139,9 +153,9 @@
  {
    // Get a sorted list of the files in the schema directory.
    TreeSet<File> schemaFiles = new TreeSet<>();
    String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath();
    String schemaDirectory = getSchemaDirectoryPath();
    final FilenameFilter filter = new SchemaConfigManager.SchemaFileFilter();
    final FilenameFilter filter = new SchemaHandler.SchemaFileFilter();
    for (File f : new File(schemaDirectory).listFiles(filter))
    {
      if (f.isFile())
@@ -170,6 +184,12 @@
    }
  }
  private static String getSchemaDirectoryPath()
  {
    File schemaDir = DirectoryServer.getEnvironmentConfig().getSchemaDirectory();
    return schemaDir != null ? schemaDir.getAbsolutePath() : null;
  }
  /**
   * Reads data from the specified concatenated schema file into the provided sets.
   *
@@ -914,9 +934,11 @@
   *          The set of temporary schema files to be activated.
   * @throws DirectoryException
   *           If a problem occurs while attempting to install the temporary schema files.
   * @throws InitializationException
   *           If directory of schema files can't be retrieved
   */
  private void installSchemaFiles(AlertGenerator alertGenerator, HashMap<String,File> tempSchemaFiles)
          throws DirectoryException
          throws DirectoryException, InitializationException
  {
    // Create lists that will hold the three types of files we'll be dealing
    // with (the temporary files that will be installed, the installed schema
@@ -925,8 +947,7 @@
    ArrayList<File> tempFileList      = new ArrayList<>();
    ArrayList<File> origFileList      = new ArrayList<>();
    File schemaInstanceDir =
      new File(SchemaConfigManager.getSchemaDirectoryPath());
    File schemaInstanceDir = serverContext.getSchemaHandler().getSchemaDirectoryPath();
    for (String name : tempSchemaFiles.keySet())
    {
opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java
@@ -55,7 +55,6 @@
import org.opends.server.core.DeleteOperationBasis;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyDNOperationBasis;
import org.opends.server.core.SchemaConfigManager;
import org.opends.server.core.ServerContext;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
@@ -3766,7 +3765,7 @@
  private File assertSchemaFileExists(String schemaFileName, boolean expectExists)
  {
    File schemaFile = new File(SchemaConfigManager.getSchemaDirectoryPath(), schemaFileName);
    File schemaFile = new File(DirectoryServer.getEnvironmentConfig().getSchemaDirectory(), schemaFileName);
    assertEquals(schemaFile.exists(), expectExists);
    return schemaFile;
  }
opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java
@@ -42,7 +42,6 @@
import org.opends.server.core.ModifyDNOperationBasis;
import org.opends.server.core.ModifyOperation;
import org.opends.server.core.ModifyOperationBasis;
import org.opends.server.core.SchemaConfigManager;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.types.Attributes;
@@ -450,7 +449,7 @@
  {
    assertEquals(conn.hasPrivilege(Privilege.JMX_WRITE, null), hasPrivilege);
    String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath();
    String schemaDirectory = DirectoryServer.getEnvironmentConfig().getSchemaDirectory().getPath();
    String identifier;
    Entry authNEntry = conn.getAuthenticationInfo().getAuthenticationEntry();
opendj-server-legacy/src/test/java/org/opends/server/tasks/AddSchemaFileTaskTestCase.java
@@ -32,7 +32,6 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.backends.SchemaTestMatchingRuleImpl;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.SchemaConfigManager;
import org.opends.server.types.DirectoryException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -107,7 +106,7 @@
    registerNewMatchingRule("testAddValidSchemaFileMatch", "1.3.6.1.4.1.26027.1.999.23");
    String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath();
    String schemaDirectory = getSchemaDirectory();
    String[] fileLines =
    {
@@ -197,7 +196,7 @@
           "APPLIES testAddMultipleValidSchemaFiles1AT )"
    };
    String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath();
    String schemaDirectory = getSchemaDirectory();
    File validFile1 = new File(schemaDirectory, "05-multiple-valid-1.ldif");
    writeLines(validFile1, fileLines1);
@@ -332,7 +331,7 @@
    Thread.sleep(2);
    String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath();
    String schemaDirectory = getSchemaDirectory();
    File emptyFile = new File(schemaDirectory, "05-empty.ldif");
    emptyFile.createNewFile();
@@ -364,7 +363,7 @@
  public void testAddInvalidSchemaFile()
         throws Exception
  {
    String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath();
    String schemaDirectory = getSchemaDirectory();
    File invalidFile = new File(schemaDirectory, "05-invalid.ldif");
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(invalidFile)))
@@ -386,4 +385,9 @@
    assertFalse(resultCode == 0);
    invalidFile.delete();
  }
  private String getSchemaDirectory()
  {
    return DirectoryServer.getEnvironmentConfig().getSchemaDirectory().getPath();
  }
}
opendj-server-legacy/src/test/java/org/opends/server/types/PrivilegeTestCase.java
@@ -56,7 +56,6 @@
import org.opends.server.core.ModifyDNOperationBasis;
import org.opends.server.core.ModifyOperation;
import org.opends.server.core.ModifyOperationBasis;
import org.opends.server.core.SchemaConfigManager;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.Requests;
@@ -909,7 +908,7 @@
          + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )"
    };
    String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath();
    String schemaDirectory = DirectoryServer.getEnvironmentConfig().getSchemaDirectory().getPath();
    File validFile = new File(schemaDirectory, "05-" + identifier + ".ldif");
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(validFile)))
    {