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

com.zusmart.basic.config.Configuration Maven / Gradle / Ivy

Go to download

基础模块,提供配置,日志,SPI,图排序,路径匹配,资源扫描,包扫描,常用工具类

There is a newer version: 0.0.3
Show newest version
package com.zusmart.basic.config;

import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import com.zusmart.basic.logging.Logger;
import com.zusmart.basic.logging.LoggerFactory;
import com.zusmart.basic.toolkit.StringUtils;

public class Configuration {

	private static final Logger logger = LoggerFactory.getLogger(Configuration.class);

	private static final String prefix = "zusmart";
	private static final Map properties = new ConcurrentHashMap();
	
	public static final String DEFAULT_EXTENSION_VALUE = "internal";
	
	static {
		initSystem();
	}

	public static void initSystem() {
		Properties systemProperties = System.getProperties();
		for (Entry entry : systemProperties.entrySet()) {
			String key = (String) entry.getKey();
			String val = (String) entry.getValue();
			if (StringUtils.isBlank(key)) {
				continue;
			}
			if (key.startsWith(prefix)) {
				properties.put(key, val);
			}
		}
	}

	public static void attachProperty(String key, String val) {
		if (StringUtils.isBlank(key)) {
			return;
		}
		properties.put(key, val);
	}

	public static void detachProperty(String key) {
		if (StringUtils.isBlank(key)) {
			return;
		}
		properties.remove(key);
	}

	public static String getProperty(String key) {
		if (StringUtils.isBlank(key)) {
			return null;
		}
		return properties.get(key);
	}

	public static String getProperty(String key, String defaultValue) {
		String value = getProperty(key);
		if (StringUtils.isBlank(value)) {
			value = defaultValue;
		}
		return value;
	}

	public static void printProperties() {
		for (Entry entry : properties.entrySet()) {
			logger.debug("zusmart config [{}={}]", entry.getKey(), entry.getValue());
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy