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