【Java开源代码栏目提醒】:以下是网学会员为您推荐的Java开源代码-ClientConfig.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;
}
}
上一篇:
ClientClass.java
下一篇:
带心行图案的把手水杯设计