NumSyncQueryDB.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
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   // key serviceName, value syncNumber
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 * delete a row by giving the SERVICE_NAME in parameters
00082 */
00083  public void delete (String serviceName) {
00084    props.remove(serviceName);
00085    this.saveProps();
00086 }
00087 
00088 
00089 /*
00090 * get  Sync number of specified service
00091 * @param : one param giving service name (SERVICE_NAME)
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         // since the method #store is not available in jdk1.1.6, dot it manually
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 }

Generated on Mon Dec 4 11:03:28 2006 for OpenMobileIS by  doxygen 1.5.1-p1