1 17 package org.apache.servicemix.common; 18 19 import java.io.File ; 20 import java.io.FileInputStream ; 21 import java.io.FileOutputStream ; 22 import java.io.IOException ; 23 import java.util.Properties ; 24 25 37 public class PersistentConfiguration { 38 39 public final static String CONFIG_FILE = "component.properties"; 40 41 protected String rootDir; 42 protected Properties properties; 43 44 public PersistentConfiguration() { 45 properties = new Properties (); 46 } 47 48 public boolean load() { 49 if (rootDir == null) { 50 return false; 51 } 52 File f = new File (rootDir, CONFIG_FILE); 53 if (!f.exists()) { 54 return false; 55 } 56 try { 57 properties.load(new FileInputStream (f)); 58 return true; 59 } catch (IOException e) { 60 throw new RuntimeException ("Could not load component configuration", e); 61 } 62 } 63 64 public void save() { 65 if (rootDir != null) { 66 File f = new File (rootDir, CONFIG_FILE); 67 try { 68 this.properties.store(new FileOutputStream (f), null); 69 } catch (Exception e) { 70 throw new RuntimeException ("Could not store component configuration", e); 71 } 72 } 73 } 74 75 78 public String getRootDir() { 79 return rootDir; 80 } 81 82 85 public void setRootDir(String rootDir) { 86 this.rootDir = rootDir; 87 } 88 89 } 90 | Popular Tags |