001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2014 ForgeRock AS.
015 */
016package org.opends.server.core;
017
018import org.forgerock.i18n.LocalizableMessage;
019import org.forgerock.opendj.config.ConfigurationFramework;
020import org.forgerock.opendj.config.server.ConfigException;
021import org.forgerock.opendj.config.server.ServerManagementContext;
022import org.opends.server.types.InitializationException;
023
024/**
025 * Bootstrap the server configuration.
026 */
027public class ConfigurationBootstrapper
028{
029
030  /**
031   * Bootstrap the server configuration.
032   * <p>
033   * The returned server management context is fully initialized with
034   * all configuration objects valued from configuration file.
035   *
036   * @param serverContext
037   *            The server context.
038   * @return the server management context
039   * @throws InitializationException
040   *            If an error occurs during bootstrapping.
041   */
042  public static ServerManagementContext bootstrap(ServerContext serverContext) throws InitializationException {
043    final ConfigurationFramework configFramework = ConfigurationFramework.getInstance();
044    try
045    {
046      if (!configFramework.isInitialized())
047      {
048        configFramework.initialize();
049      }
050    }
051    catch (ConfigException e)
052    {
053      // TODO : fix the message
054      throw new InitializationException(LocalizableMessage.raw("Cannot initialize config framework"), e);
055    }
056
057    final ConfigurationHandler configurationHandler = new ConfigurationHandler(serverContext);
058    configurationHandler.initialize();
059
060    return new ServerManagementContext(configurationHandler);
061  }
062}