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 2008 Sun Microsystems, Inc.
025 *      Portions copyright 2013 ForgeRock AS.
026 */
027package org.forgerock.opendj.server.core;
028
029import java.util.List;
030
031import org.forgerock.i18n.LocalizableMessage;
032import org.forgerock.opendj.config.server.ConfigException;
033
034/**
035 * A factory for creating data provider instances.
036 *
037 * @param <T>
038 *            The type of configuration handled by this data provider.
039 * @see DataProvider
040 */
041public interface DataProviderFactory<T extends DataProviderCfg> {
042
043    /**
044     * Creates and initializes a new data provider based on the information in
045     * the provided configuration.
046     * <p>
047     * Implementations must not start any services nor attempt to connect to
048     * other data providers. However, they may register with the backup/restore
049     * and import/export managers.
050     *
051     * @param id
052     *            The ID which should be used to uniquely identify this data
053     *            provider.
054     * @param configuration
055     *            The configuration that contains the information to use to
056     *            create and initialize the new data provider.
057     * @return The new data provider instance.
058     * @throws ConfigException
059     *             If an unrecoverable problem arises during initialization of
060     *             the data provider as a result of the server configuration.
061     * @see DataProvider#startDataProvider()
062     */
063    DataProvider createDataProvider(DataProviderID id, T configuration) throws ConfigException;
064
065    /**
066     * Indicates whether the provided configuration is acceptable for creating
067     * and initializing a new data provider using this data provider factory.
068     * <p>
069     * This method will be called before
070     * {@link #createDataProvider(DataProviderID, DataProviderCfg)} in order
071     * validate the configuration.
072     * <p>
073     * Implementations should perform basic validation of the configuration but
074     * should not attempt to start any resource or connect to other data
075     * providers.
076     *
077     * @param configuration
078     *            The configuration for which to make the determination.
079     * @param unacceptableReasons
080     *            A list that may be used to hold the reasons that the provided
081     *            configuration is not acceptable.
082     * @return {@code true} if the provided configuration is acceptable for this
083     *         data provider factory, or {@code false} if not.
084     */
085    boolean isConfigurationAcceptable(T configuration, List<LocalizableMessage> unacceptableReasons);
086}