001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2014 ForgeRock AS.
025 *      Portions Copyright 2014 ForgeRock AS
026 */
027package org.opends.server.schema;
028
029import java.util.List;
030
031import org.forgerock.i18n.LocalizableMessage;
032import org.forgerock.opendj.ldap.schema.SchemaBuilder;
033import org.forgerock.opendj.server.config.server.SchemaProviderCfg;
034import org.forgerock.opendj.config.server.ConfigException;
035import org.opends.server.types.InitializationException;
036
037/**
038 * Provides some schema elements to load at startup.
039 * <p>
040 * A schema provider must be able to update the provided {@code SchemaBuilder}
041 * at initialization and to use the provided {@code SchemaUpdater} to update the
042 * schema on further configuration changes.
043 *
044 * @param <T>
045 *          The type of provider configuration.
046 */
047public interface SchemaProvider<T extends SchemaProviderCfg>
048{
049  /**
050   * Initialize the schema provider from provided configuration and schema
051   * builder.
052   *
053   * @param configuration
054   *          Configuration of the provider.
055   * @param initialSchemaBuilder
056   *          Schema builder to update during initialization phase.
057   * @param schemaUpdater
058   *          The updater to call when applying a configuration change.
059   * @throws ConfigException
060   *           If a configuration problem arises in the process of performing
061   *           the initialization.
062   * @throws InitializationException
063   *           If a problem that is not configuration-related occurs during
064   *           initialization.
065   */
066  void initialize(T configuration, SchemaBuilder initialSchemaBuilder, SchemaUpdater schemaUpdater)
067      throws ConfigException, InitializationException;
068
069  /**
070   * Finalize the provider.
071   */
072  void finalizeProvider();
073
074  /**
075   * Indicates whether the provided configuration is acceptable for this
076   * provider.
077   *
078   * @param configuration
079   *          The provider configuration for which to make the determination.
080   * @param unacceptableReasons
081   *          A list that may be used to hold the reasons that the provided
082   *          configuration is not acceptable.
083   * @return {@code true} if the provided configuration is acceptable for this
084   *         provider, or {@code false} if not.
085   */
086  boolean isConfigurationAcceptable(T configuration, List<LocalizableMessage> unacceptableReasons);
087
088  /**
089   * Returns the schema builder, as updated by this provider.
090   *
091   * @return the schema builder resulting from this provider.
092   */
093  SchemaBuilder getSchema();
094}