001package ca.bc.webarts.tools; 002 003import ca.bc.webarts.widgets.ClassConstants; 004 005import java.util.Enumeration; 006import java.io.InputStream; 007import java.io.BufferedInputStream; 008import java.io.File; 009import java.io.FileInputStream; 010import java.io.IOException; 011import java.lang.Process; 012import java.lang.Runtime; 013import java.util.Arrays; 014import java.util.Properties; 015 016import java.util.Vector; 017 018 /** 019 * An Objectization of the information that makes up a timed app. 020 * 021 * @author Tom Gutwin 022 * @created June 7, 2001 023 */ 024 class TimedApp implements Runnable 025 { 026 /** 027 * The name to give to this timed app. 028 * 029 * @since 030 */ 031 public String name__ = ""; 032 033 /** 034 * The full filename of the Config file for this timed app. 035 * 036 * @since 037 */ 038 public String fileName__ = ""; 039 040 041 /** 042 * The initial start time for this timed app. 043 * 044 * @since 045 */ 046 public String startTime__ = "IMEDIATE"; 047 048 049 /** 050 * Fully Qualified app path of this timed app. 051 * 052 * @since 053 */ 054 public String appFileName__ = ""; 055 056 057 /** 058 * The timed repeat time interval qualifier.It must be one of this 059 * CONSTNAMES and qualifys the repeat__value. 060 * 061 * @since 062 */ 063 public String interval__ = ""; 064 065 066 /** 067 * The number of time before a repeat of this timed app. It is 068 * qualified by the interval__ to put this value into absolute terms. 069 * 070 * @since 071 */ 072 public String repeat__ = "0"; 073 074 075 /** 076 * Constructor for the TimedApp object. 077 * 078 * @param fileName The filename for the properties file for this 079 * TimedApp. 080 * @since 081 */ 082 public TimedApp(String fileName) throws Exception 083 { 084 System.out.println("Reading Properties File:" + fileName); 085 fileName__ = fileName; 086 Properties p = new Properties(); 087 try 088 { 089 p.load(new FileInputStream(new File(fileName))); 090 name__ = p.getProperty("Name"); 091 interval__ = p.getProperty("Repeat Interval"); 092 startTime__ = p.getProperty("Strat Time"); 093 repeat__ = p.getProperty("Repeat Time"); 094 appFileName__ = p.getProperty("Application Path"); 095 } 096 catch (IOException ex) 097 { 098 System.out.println("Choked on File:" + fileName); 099 throw new Exception("Unable to get properties"); 100 } 101 } 102 103 104 public void run() 105 { 106 System.out.println("Executing " +name__ ); 107 System.out.println("Path " +appFileName__ ); 108 try 109 { 110 Process p = Runtime.getRuntime().exec(appFileName__); 111 BufferedInputStream streamResults = 112 new BufferedInputStream(p.getInputStream()); 113 while(true) 114 { 115 byte [] b = new byte[streamResults.available()]; 116 if(b.length >0) 117 { 118 streamResults.read(b); 119 System.out.println(" :" + b.length ); 120 for (int i = 0; i< b.length; i++) 121 System.out.print(Byte.toString(b[i])); 122 } 123 } 124 } 125 catch (IOException ex) 126 { 127 System.out.println("CAN'T EXECUTE " +name__ + "\n" +ex.getMessage()); 128 } 129 } 130 }