
net.wicp.tams.commons.connector.config.xmlParser.ConfigClassXml Maven / Gradle / Ivy
package net.wicp.tams.commons.connector.config.xmlParser;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.configuration.tree.ConfigurationNode;
import org.apache.commons.configuration.tree.DefaultConfigurationNode;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
import org.apache.commons.lang.StringUtils;
import net.wicp.tams.commons.apiext.XmlUtil;
import net.wicp.tams.commons.connector.config.AbstractConfigClass;
import net.wicp.tams.commons.constant.ColProperty;
import net.wicp.tams.commons.constant.ColType;
import net.wicp.tams.commons.exception.ExceptAll;
import net.wicp.tams.commons.exception.ProjectException;
public class ConfigClassXml extends AbstractConfigClass {
private XMLConfigurationExt xml;
private ConfigClassXml(String className, String path, String xmlName)
throws ProjectException {
super(className);
File inputFile = new File(path, xmlName);
try {
java.io.Reader reader = new java.io.FileReader(inputFile);
this.xml = new XMLConfigurationExt();
this.xml.setEncoding("UTF-8");
this.xml.setExpressionEngine(new XPathExpressionEngine());// 设置Xpath解析器
this.xml.load(reader);
} catch (Exception e) {
throw new ProjectException(ExceptAll.Project_default, "加载XML文件错误");
}
AbstractConfigClass.parseClassMap.put(className, this);
}
private ConfigClassXml(String className, InputStream stream)
throws ProjectException {
super(className);
try {
this.xml = new XMLConfigurationExt();
this.xml.setEncoding("UTF-8");
this.xml.setExpressionEngine(new XPathExpressionEngine());// 设置Xpath解析器
this.xml.load(stream);
} catch (Exception e) {
throw new ProjectException(ExceptAll.Project_default,
"xml流组装成XML错误");
}
AbstractConfigClass.parseClassMap.put(className, this);
}
public static ConfigClassXml createConfigClassXml(String className,
String path, String xmlName) throws ProjectException {
AbstractConfigClass retobj = AbstractConfigClass.parseClassMap
.get(className);
if (retobj == null) {
retobj = new ConfigClassXml(className, path, xmlName);
AbstractConfigClass.parseClassMap.put(className, retobj);
}
return (ConfigClassXml) retobj;
}
public static ConfigClassXml createConfigClassXml(String className,
InputStream stream) throws ProjectException {
AbstractConfigClass retobj = AbstractConfigClass.parseClassMap
.get(className);
if (retobj == null) {
retobj = new ConfigClassXml(className, stream);
AbstractConfigClass.parseClassMap.put(className, retobj);
}
return (ConfigClassXml) retobj;
}
private List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy