import classess.LogFile;
import classess.LogFile;
import java.io.File;
import javax.swing.JOptionPane;
import org.dom4j.*;
import org.dom4j.io.SAXReader;
/**
*
* @author CycoLabs
*/
public class AppSettings {
private String appmode;
private String terminalname;
private String dbonlineautoupload;
private String dbserverip;
private String dbtimecheckinuri;
boolean b = false;
////////////////////////////////////////////////
private static AppSettings appsettings;
private AppSettings() {
}
public static AppSettings getAppSettings() {
System.gc();
if (appsettings == null) {
appsettings = new AppSettings();
}
return appsettings;
}
////////////////////////////////////////////////
public boolean setLoadAppSettings() {
b = false;
try {
//File file = ;
SAXReader reader = new SAXReader();
Document document = reader.read(new File("appsettings.xml"));
AppSettings.getAppSettings().setAppmode(document.selectSingleNode("//settings/appmode").getText());
AppSettings.getAppSettings().setDBOnlineAutoUpload(document.selectSingleNode("//settings/dbonlineautoupload").getText());
AppSettings.getAppSettings().setDBServerIP(document.selectSingleNode("//settings/dbserverip").getText());
b = true;
} catch (Exception e) {
e.printStackTrace();
b = false;
LogFile.log(getClass().getName(), "setLoadAppSettings", e.getMessage().toString(), null);
JOptionPane.showMessageDialog(null, "App Settings Error!\nSystem cannot run anymore.\nSystem will exit now.\n"+e.getMessage().toString(), "CRITICAL ERROR", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
return b;
}
/**
* @return the appmode
*/
public String getAppmode() {
return appmode;
}
/**
* @param appmode the appmode to set
*/
private void setAppmode(String appmode) {
System.out.println("appmode: " + appmode);
this.appmode = appmode;
}
/**
* @return the terminalname
*/
public String getTerminalName() {
return terminalname;
}
/**
* @param terminalname the terminalname to set
*/
private void setTerminalName(String terminalname) {
System.out.println("terminalname: " + terminalname);
this.terminalname = terminalname;
}
/**
* @return the dbautoupload
*/
public String getDBOnlineAutoUpload() {
return dbonlineautoupload;
}
/**
* @param dbautoupload the dbautoupload to set
*/
private void setDBOnlineAutoUpload(String dbonlineautoupload) {
System.out.println("dbonlineautoupload: " + dbonlineautoupload);
this.dbonlineautoupload = dbonlineautoupload;
}
/**
* @return the terminalip
*/
public String getDBServerIP() {
return dbserverip;
}
/**
* @param terminalip the terminalip to set
*/
public void setDBServerIP(String dbserverip) {
System.out.println("dbserverip: " + dbserverip);
this.dbserverip = dbserverip;
}
/**
* @return the dbtimecheckin
*/
public String getDbtimecheckinuri() {
return dbtimecheckinuri;
}
/**
* @param dbtimecheckin the dbtimecheckin to set
*/
public void setDbtimecheckinuri(String dbtimecheckinuri) {
System.out.println("dbtimecheckinuri: " + dbtimecheckinuri);
this.dbtimecheckinuri = dbtimecheckinuri;
}
}
XML File -> appsettings.xml
<?xml version = "1.0"?>
<settings>
<appmode>d</appmode>
<dbserverip>localhost</dbserverip>
<dbonlineautoupload>0</dbonlineautoupload>
</settings>
No comments:
Post a Comment