⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientconfig.java

📁 《j2ee开发全程实录》随书源码
💻 JAVA
字号:
package com.cownew.PIS.framework.client;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import com.cownew.ctk.common.ExceptionUtils;
import com.cownew.ctk.common.StringUtils;
import com.cownew.ctk.constant.StringConst;
import com.cownew.ctk.io.ResourceUtils;

public class ClientConfig
{
	private String serverURL;

	private String metaDataPath;

	private String entityCacheFile;

	private boolean metaCacheEnabled;

	private String lookAndFeel;

	private static ClientConfig instance;

	private ClientConfig()
	{
	}

	public static ClientConfig getInstance()
	{
		if (instance == null)
		{
			instance = new ClientConfig();
			try
			{
				instance.initConfig();
			} catch (Exception e)
			{
				throw ExceptionUtils.toRuntimeException(e);
			}
		}

		return instance;
	}

	protected void initConfig() throws Exception
	{
		InputStream beansXFStream = null;
		try
		{
			beansXFStream = getClass().getResourceAsStream(
					"/com/cownew/PIS/framework/client/ClientConfig.xml");
			Document doc = new SAXReader().read(new InputStreamReader(
					beansXFStream, StringConst.UTF8));
			Node serverURLNode = doc.selectSingleNode("//Config/ServerURL");
			serverURL = serverURLNode.getText().trim();
			metaDataPath = doc.selectSingleNode(
					"//Config/MetaData/MetaDataPath").getText().trim();
			entityCacheFile = doc.selectSingleNode(
					"//Config/MetaData/EntityCacheFile").getText().trim();
			String cacheState = doc.selectSingleNode(
					"//Config/MetaData/CacheEnabled").getText().trim();
			if (StringUtils.isEmpty(cacheState)
					|| cacheState.equalsIgnoreCase("false")
					|| cacheState.equalsIgnoreCase("no")
					|| cacheState.equalsIgnoreCase("off"))
			{
				metaCacheEnabled = false;
			} else
			{
				metaCacheEnabled = true;
			}
			lookAndFeel = doc.selectSingleNode("//Config/LookAndFeel")
					.getText().trim();
		} finally
		{
			ResourceUtils.close(beansXFStream);
		}

	}

	public URL getServerURL()
	{
		try
		{
			return new URL(serverURL);
		} catch (MalformedURLException e)
		{
			throw ExceptionUtils.toRuntimeException(e);
		}
	}

	public boolean isMetaCacheEnabled()
	{
		return metaCacheEnabled;
	}

	public String getEntityCacheFile()
	{
		return entityCacheFile;
	}

	public String getMetaDataPath()
	{
		return metaDataPath;
	}

	public String getLookAndFeel()
	{
		return lookAndFeel;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -