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

com.axway.apim.lib.EnvironmentProperties Maven / Gradle / Ivy

package com.axway.apim.lib;

import java.util.Collection;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.axway.apim.actions.rest.APIMHttpClient;

public class EnvironmentProperties implements Map {
	
	private static Logger LOG = LoggerFactory.getLogger(EnvironmentProperties.class);
	
	private Properties mainProperties = new Properties();
	private Properties stageProperties = new Properties();
	private Properties systemProperties = System.getProperties();

	public EnvironmentProperties(String stage) throws AppException {
		super();
		initProperties(stage);
	}
	
	private void initProperties(String stage) throws AppException {
		try {
			mainProperties.load(APIMHttpClient.class.getClassLoader().getResourceAsStream("env.properties"));
			LOG.info("Loaded environment properties from file: env.properties.");
		} catch (Exception e) {
			LOG.info("Trying to load environment properties from file: env.properties ... not found.");
		}
		try {
			if(stage!=null && !stage.equals("NOT_SET")) {
				stageProperties.load(APIMHttpClient.class.getClassLoader().getResourceAsStream("env."+stage+".properties"));
				LOG.info("Loaded environment properties from file: env."+stage+".properties.");
			}
		} catch (Exception e) {
			LOG.info("Trying to load environment properties from file: env."+stage+".properties ... not found.");
		}
	}
	
	@Override
	public String get(Object key) {
		if(stageProperties!=null && stageProperties.containsKey(key)) {
			return stageProperties.getProperty((String)key);
		} else if(this.mainProperties!=null && mainProperties.containsKey(key)) {
			return mainProperties.getProperty((String)key);
		} else if(this.systemProperties!=null && systemProperties.containsKey(key)) {
			return systemProperties.getProperty((String)key);
		} else {
			LOG.debug("Property: '" + key + "' not found.");
			return null;
		}
	}
	
	@Override
	public boolean containsKey(Object key) {
		return (this.mainProperties.containsKey(key) || this.stageProperties.containsKey(key) || this.systemProperties.containsKey(key));
	}

	@Override
	public void clear() {
		throw new UnsupportedOperationException();
	}



	@Override
	public boolean containsValue(Object value) {
		throw new UnsupportedOperationException();
	}

	@Override
	public Set> entrySet() {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean isEmpty() {
		throw new UnsupportedOperationException();
	}

	@Override
	public Set keySet() {
		throw new UnsupportedOperationException();
	}

	@Override
	public String put(String key, String value) {
		throw new UnsupportedOperationException();
	}

	@Override
	public void putAll(Map m) {
		throw new UnsupportedOperationException();
	}

	@Override
	public String remove(Object key) {
		throw new UnsupportedOperationException();
	}

	@Override
	public int size() {
		throw new UnsupportedOperationException();
	}

	@Override
	public Collection values() {
		throw new UnsupportedOperationException();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy