EAS配置文件Configuration

bosconfig.xml在profiles/server1/config下面     配置监听listenerconfig.data
package com.kingdee.util;

import java.io.File;
import java.io.PrintStream;
import java.net.URL;
import java.util.List;

public class Configuration {
	public static final String SERVER_ROOT_PROP = "bos.root";
	public static final String SERVER_CONFIG_PROP = "bos.config";
	public static final String DEFAULT_SERVER_CONFIG = "bosconfig.xml";
	private XMLConfiguration xmlConfig;
	private File file;
	private URL url;
	private static Configuration myself;

	public static File getServerRoot() {
		String root = System.getProperty("bos.root");
		if (root == null)
			root = System.getProperty("user.dir");
		return new File(root);
	}

	public static File getFile(String name) {
		if (File.separatorChar != '/')
			name = name.replace('/', File.separatorChar);
		File file = new File(name);
		if (!(file.isAbsolute()))
			file = new File(getServerRoot(), name);
		return file;
	}

	private Configuration(String fileName) {
		this.file = getFile(fileName);
	}

	private Configuration(URL url) {
		this.url = url;
	}

	public static Configuration getInstance() throws ConfigurationException {
		String fileName = System.getProperty("bos.config", "bosconfig.xml");

		return getInstance(fileName);
	}

	public static Configuration getInstance(String fileName) throws ConfigurationException {
		if (myself == null) {
			synchronized (Configuration.class) {
				if (myself == null) {
					Configuration config = new Configuration(fileName);
					config.load();
					myself = config;
				}
			}
		}
		return myself;
	}

	public static Configuration getInstance(URL url) throws ConfigurationException {
		if (myself == null) {
			synchronized (Configuration.class) {
				if (myself == null) {
					Configuration config = new Configuration(url);
					config.load();
					myself = config;
				}
			}
		}
		return myself;
	}

	public void addConfigItem(ConfigurationItem item) {
		this.xmlConfig.addConfigItem(item);
	}

	public ConfigurationItem getConfigItem(String name) {
		return this.xmlConfig.getConfigItem(name);
	}

	public List getConfigItemList(String name) {
		return this.xmlConfig.getConfigItemList(name);
	}

	public ConfigurationItem getConfigItemByPath(String path) {
		return this.xmlConfig.getConfigItemByPath(path);
	}

	public List getConfigItemListByPath(String path) {
		return this.xmlConfig.getConfigItemListByPath(path);
	}

	public void removeConfigItem(String name) {
		this.xmlConfig.removeConfigItem(name);
	}

	public void removeAll() {
		this.xmlConfig.removeAll();
	}

	public void store() throws ConfigurationException {
		this.xmlConfig.store();
	}

	private void load() throws ConfigurationException {
		if ((this.file == null) && (this.url == null)) {
			throw new ConfigurationException("config file not exists.");
		}

		if (this.file != null) {
			if (this.file.exists()) {
				this.xmlConfig = XMLConfiguration.getInstance(this.file);
				return;
			}
			throw new ConfigurationException("config file " + this.file.getAbsolutePath() + " not exists.");
		}

		if (this.url != null) {
			this.xmlConfig = XMLConfiguration.getInstance(this.url);
		} else
			throw new ConfigurationException("config file not exists.");
	}

	public void dump(PrintStream ps) {
		this.xmlConfig.dump(ps);
	}
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值