00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 package org.openmobileis.synchro.openmsp.client.core;
00027
00028 import java.util.Properties;
00029
00030 import org.openmobileis.common.util.PropertiesManager;
00031 import org.openmobileis.common.util.log.*;
00032
00033
00042 public class NumSyncQueryDB {
00043
00044
00045 private java.util.Properties props = new java.util.Properties();
00046
00047
00048 public NumSyncQueryDB() {
00049 String propsFilePath = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.client.openmsp.numsyncpropsfile");
00050 java.io.FileInputStream input = null;
00051 try {
00052 input = new java.io.FileInputStream(propsFilePath);
00053 props.load(input);
00054 } catch (Exception e) {
00055 LogManager.traceWarning(LogServices.WEBSERVICE, "NumSyncQueryDB Can not load " + propsFilePath+". Create it.");
00056 props = new Properties();
00057 this.saveProps();
00058 } finally {
00059 if (input != null) {
00060 try {
00061 input.close();
00062 } catch (Exception e) {
00063 LogManager.traceWarning(LogServices.WEBSERVICE, "Can not close " + propsFilePath);
00064 }
00065 }
00066 }
00067 }
00068
00069 public void initAllSyncNumber() {
00070 props.clear();
00071 this.saveProps();
00072 }
00073
00074
00075 public void saveSyncNumber (String serviceName, String syncNumber) {
00076 props.put(serviceName, syncNumber);
00077 this.saveProps();
00078 }
00079
00080
00081
00082
00083 public void delete (String serviceName) {
00084 props.remove(serviceName);
00085 this.saveProps();
00086 }
00087
00088
00089
00090
00091
00092
00093 public String getServiceSN(String serviceName) {
00094 return props.getProperty(serviceName);
00095 }
00096
00097 private void saveProps() {
00098 java.io.FileOutputStream output = null;
00099 String propsFilePath = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.client.openmsp.numsyncpropsfile");
00100 try {
00101 output = new java.io.FileOutputStream(propsFilePath);
00102
00103 for (java.util.Enumeration e = props.keys(); e.hasMoreElements();) {
00104 String key = (String)e.nextElement();
00105 String val = (String)props.get(key);
00106 output.write((key + "=" + val + "\n").getBytes());
00107 }
00108 output.flush();
00109 } catch (java.io.IOException e) {
00110 LogManager.traceError(LogServices.WEBSERVICE, "Impossible to store property file : " + propsFilePath);
00111 } finally {
00112 if (output != null) {
00113 try {
00114 output.close();
00115 } catch (java.io.IOException e) {
00116 LogManager.traceError(LogServices.WEBSERVICE, "Impossible to close property file : " + propsFilePath);
00117 }
00118 }
00119 }
00120 }
00121
00122 }