All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nuiton.topia.persistence.support.TopiaSqlDllSupportProvider Maven / Gradle / Ivy

The newest version!
package org.nuiton.topia.persistence.support;

/*-
 * #%L
 * ObServe Toolkit :: ToPIA Extension
 * %%
 * Copyright (C) 2017 - 2018 IRD, Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import com.google.common.collect.ImmutableMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;

/**
 * Created by tchemit on 05/05/2018.
 *
 * @author Tony Chemit - [email protected]
 */
@SuppressWarnings("WeakerAccess")
public class TopiaSqlDllSupportProvider {

    private static final Log log = LogFactory.getLog(TopiaSqlDllSupportProvider.class);

    private static TopiaSqlDllSupportProvider INSTANCE;
    /**
     * Available {@link TopiaSqlDllSupport} found in class-path indexed by their classifier.
     */
    protected final Map resources;

    protected TopiaSqlDllSupportProvider() {

        ImmutableMap.Builder resourcesBuilder = ImmutableMap.builder();
        for (TopiaSqlDllSupport resource : ServiceLoader.load(TopiaSqlDllSupport.class)) {
            resourcesBuilder.put(resource.getClassifier(), resource);
        }
        resources = resourcesBuilder.build();
        log.info(String.format("Found %d sql dll provider(s).", resources.size()));

    }

    public static synchronized TopiaSqlDllSupportProvider get() {
        return INSTANCE == null ? INSTANCE = new TopiaSqlDllSupportProvider() : INSTANCE;
    }

    public Optional get(String classifier) {
        return Optional.ofNullable(resources.get(classifier));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy