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

net.sf.aguacate.config.ConfigurationFactory Maven / Gradle / Ivy

package net.sf.aguacate.config;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.sf.aguacate.config.impl.ConfigurationImpl;
import net.sf.aguacate.config.spi.PathInfoCompilerImpl;
import net.sf.aguacate.util.json.JsonCodec;
import net.sf.aguacate.util.resource.ResourceLocator;
import net.sf.aguacate.util.resource.impl.ResourceLocatorClassImpl;
import net.sf.aguacate.util.resource.impl.ResourceLocatorFileImpl;
import net.sf.aguacate.validator.impl.ValidatorConverterImpl;

public final class ConfigurationFactory {

	private static final String DIRECTORY_CONFIGURATION = "DIRECTORY_CONFIGURATION";
	private static final Logger LOGGER = LogManager.getLogger(ConfigurationFactory.class);

	private ConfigurationFactory() {
	}

	public static Configuration create(JsonCodec codec) {
		ResourceLocator locator;
		String temp = System.getProperty(DIRECTORY_CONFIGURATION);
		if (temp == null || temp.isEmpty()) {
			temp = System.getenv(DIRECTORY_CONFIGURATION);
			if (temp == null || temp.isEmpty()) {
				LOGGER.info("No " + DIRECTORY_CONFIGURATION + " defined, using default");
				locator = new ResourceLocatorClassImpl(ConfigurationImpl.class);
			} else {
				LOGGER.info("using " + DIRECTORY_CONFIGURATION + " (env): {}", temp);
				locator = new ResourceLocatorFileImpl(temp);
			}
		} else {
			LOGGER.info("using " + DIRECTORY_CONFIGURATION + " (prop): {}", temp);
			locator = new ResourceLocatorFileImpl(temp);
		}
		return new ConfigurationImpl(locator, codec, new PathInfoCompilerImpl(), new ValidatorConverterImpl());
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy