View Javadoc
1 /* 2 * SystemProperties.java 3 * 4 * Created on February 14, 2003, 10:10 AM 5 */ 6 7 package com.mlw.fps.model.business.bean; 8 9 import java.io.File; 10 import java.io.FileInputStream; 11 import java.io.FileOutputStream; 12 import java.io.IOException; 13 import java.util.Map; 14 import java.util.Properties; 15 16 import com.mlw.fps.model.business.vo.SupportedGame; 17 /*** 18 * 19 * @author Matthew Wilson 20 */ 21 public class SystemProperties 22 { 23 public static final String VERSION= "1.0-beta2"; 24 25 private static SystemProperties system; 26 private static SupportedGame game; 27 28 private boolean initialized= false; 29 private Properties props= new Properties(); 30 private File file= new File("/fps.webapp.properties"); 31 32 /*** Creates a new instance of SystemProperties 33 */ 34 private SystemProperties() 35 { 36 } 37 38 private static SystemProperties instance() 39 { 40 system= new SystemProperties(); 41 try 42 { 43 if (!system.file.exists()) 44 { 45 system.props.put("version", VERSION); 46 system.save(); 47 } 48 else 49 { 50 system.props.load(new FileInputStream(system.file)); 51 game= new SupportedGame(system.props.getProperty("game.pk"), system.props.getProperty("game.name")); 52 } 53 } 54 catch (Exception e) 55 { 56 e.printStackTrace(); 57 } 58 59 return system; 60 } 61 62 private void save() throws IOException 63 { 64 props.store(new FileOutputStream(file), "System properties for fps (file mode)"); 65 game = new SupportedGame(props.getProperty("game"), props.getProperty("game")); 66 } 67 68 public static Map toMap() 69 { 70 if (system == null) system=instance(); 71 return system.props; 72 } 73 74 public static String getProperty(String name) 75 { 76 if (system == null) 77 system= instance(); 78 return system.props.getProperty(name); 79 } 80 81 public static String getProperty(String name, String defaultValue) 82 { 83 if (system == null) 84 system= instance(); 85 String value = system.props.getProperty(name); 86 return (value==null)?defaultValue:value; 87 } 88 89 public static void setProperty(String name, String value) 90 { 91 if (system == null) 92 system= instance(); 93 system.props.setProperty(name, value); 94 try 95 { 96 system.save(); 97 } 98 catch (Exception e) 99 { 100 e.printStackTrace(); 101 } 102 } 103 104 public static SupportedGame getSupportedGame() 105 { 106 return game; 107 } 108 109 }

This page was automatically generated by Maven