tgtools.tasklibrary.tables.TableFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tgtools.tasklibrary Show documentation
Show all versions of tgtools.tasklibrary Show documentation
base tgtools.tasklibrary task tools
package tgtools.tasklibrary.tables;
import tgtools.tasklibrary.config.ConfigInfo;
import tgtools.tasklibrary.entity.TableInfo;
import tgtools.tasklibrary.util.LogHelper;
import tgtools.util.FileUtil;
import tgtools.util.StringUtil;
import tgtools.util.XmlSerialize;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class TableFactory {
private static HashMap m_Tables;
public static synchronized HashMap getTables() {
if (m_Tables == null) {
m_Tables = new HashMap();
}
return m_Tables;
}
public static synchronized void loadData() {
loadData(getPatch());
}
public static synchronized void loadData(String m_Path) {
String[] files = FileUtil.listFiles(m_Path, new String[]{"config"});
for (String name : files) {
try {
Object obj = XmlSerialize.deserialize(FileUtil.readFile(name, "UTF-8"),
"TableInfo", TableInfo.class);
if ((obj != null) && ((obj instanceof TableInfo))) {
TableInfo table = (TableInfo) obj;
table.SortColumnInfo();
getTables().put(name, table);
LogHelper.info("加载文件成功:" + name);
}
} catch (Exception e) {
LogHelper.error("加载文件失败:" + name, e);
}
}
}
private static String getPatch() {
String patch = System.getProperty("user.dir");
return patch + "/config";
}
public static void main(String[] args) {
// String path ="C:/Works/DQ/javademos/binfo.config/config/config.xml";
// String dd= FileUtil.getFileEncode(path);
// String xmlstr= FileUtil.readFile(path,dd);
// try {
// Object obj = XmlSerialize.deserialize(xmlstr, "Config", ConfigInfo.class);
// if (null != obj && obj instanceof ConfigInfo) {
// System.out.println(obj);
// }
//
// } catch (Exception e) {
// LogHelper.error("解析配置文件出错:"+xmlstr, e);
// }
System.out.println(System.getProperty("user.dir"));
loadData("C:\\tianjing\\github\\tgtools.tasklibrary\\src\\main\\resources\\config\\demo\\");
ByteArrayOutputStream vOutputStream =new ByteArrayOutputStream();
try {
XmlSerialize.serialize(vOutputStream,m_Tables.get("C:\\tianjing\\github\\tgtools.tasklibrary\\src\\main\\resources\\config\\demo\\PVC.config"));
System.out.println(vOutputStream.toString());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("loadData end");
}
public static TableInfo getTableByStartName(String p_FileName) {
TableInfo[] list =getTables().values().toArray(new TableInfo[getTables().values().size()]);
for(int i=0;i getTablesByStartName(String p_FileName) {
return getTablesByStartName(p_FileName,null);
}
public static List getTablesByStartName(String p_FileName, String p_FileExt) {
List list=new ArrayList();
if(!StringUtil.isNullOrEmpty(p_FileName))
{
TableInfo[] tables =getTables().values().toArray(new TableInfo[getTables().values().size()]);
for(int i=0;i list=new ArrayList();
if(!StringUtil.isNullOrEmpty(p_FileName))
{
TableInfo[] tables =getTables().values().toArray(new TableInfo[getTables().values().size()]);
for(int i=0;i