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

org.jxls.util.ServiceFactoryDefaultImpl Maven / Gradle / Ivy

The newest version!
package org.jxls.util;

import java.util.Iterator;
import java.util.ServiceLoader;

import org.jxls.template.SimpleExporter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * SPI creator factory
 */
public class ServiceFactoryDefaultImpl implements ServiceFactory {
	private static final Logger LOGGER = LogManager.getLogger(SimpleExporter.class);
	
    @Override
    public  T createService(Class interfaceClass, T defaultImpl) {
        final T service;
        final Iterator iterator = ServiceLoader.load(interfaceClass).iterator();
        if (iterator.hasNext()) {
            service = iterator.next();
        } else {
            service = defaultImpl;
        }
        LOGGER.debug("SPI {} => {}", interfaceClass.getName(), service);
        LOGGER.info("you may change the SPI on file: META-INF/services/{}", interfaceClass.getName());
        return service;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy