DefaultSystemAPI.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  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  * 
00027  */
00028 
00029 package org.openmobileis.embedded.util;
00030 
00031 import java.io.File;
00032 
00033 import org.openmobileis.common.util.PersistentPropertiesManager;
00034 import org.openmobileis.common.util.exception.DefaultException;
00035 import org.openmobileis.common.util.exception.OpenMISException;
00036 
00045 public class DefaultSystemAPI implements ISystemAPI{
00046 
00052   public int execProgramAndWait(String path, String args) throws OpenMISException       {
00053                 String execCommand[] = new String[2];
00054                 execCommand[0] = path;
00055                 execCommand[1] = args;
00056                 try     {
00057                   Process process = Runtime.getRuntime().exec(execCommand,null, new File(System.getProperty("user.dir")));
00058                   process.waitFor();
00059                 } catch (Exception ex)  {
00060                   throw new DefaultException(ex);
00061                 }
00062                 return 1;
00063   }
00064 
00070   public int execProgram (String path, String args) throws OpenMISException     {  
00071                 String execCommand[] = new String[2];
00072                 execCommand[0] = path;
00073                 execCommand[1] = args;
00074                 try     {
00075                   Runtime.getRuntime().exec(execCommand,null, new File(System.getProperty("user.dir")));
00076                 } catch (Exception ex)  {
00077                   throw new DefaultException(ex);
00078                 }
00079                 return 1;
00080   }
00081   
00086   public long currentTimeInMillis() {
00087       return System.currentTimeMillis();
00088   }
00089   
00094   public String getSystemUniqueID()     {
00095           String uniqueid = PersistentPropertiesManager.getManager().getProperty("OWSystemAPI",  "uniqueid");
00096           if (uniqueid == null) {
00097                   uniqueid = Long.toString(System.currentTimeMillis());
00098                   PersistentPropertiesManager.getManager().saveProperty("OWSystemAPI",  "uniqueid", uniqueid);
00099           }
00100           return uniqueid;
00101   }
00102 }

Generated on Mon Jan 14 17:29:45 2008 for OpenMobileIS by  doxygen 1.5.4