[Jdvb-cvs] jdvb-server/src/uk/midearth/dvb/confParser Configurator.java,1.2,1.3
Status: Inactive
Brought to you by:
hundalz
|
From: pinder <hu...@us...> - 2006-02-19 22:18:44
|
Update of /cvsroot/jdvb/jdvb-server/src/uk/midearth/dvb/confParser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9820/src/uk/midearth/dvb/confParser Modified Files: Configurator.java Log Message: good night Index: Configurator.java =================================================================== RCS file: /cvsroot/jdvb/jdvb-server/src/uk/midearth/dvb/confParser/Configurator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Configurator.java 19 Feb 2006 16:59:31 -0000 1.2 --- Configurator.java 19 Feb 2006 22:18:37 -0000 1.3 *************** *** 6,9 **** --- 6,12 ---- import org.apache.log4j.Logger; + import uk.midearth.dvb.exception.JDVBException; + + public class Configurator { private Hashtable<String, String> variables = new Hashtable<String, String>(); *************** *** 11,14 **** --- 14,21 ---- private File configFile; + private static Properties props = new Properties(); + + private static Configurator configurator; + /** * Serial Version UID *************** *** 17,22 **** public static Logger LOG = Logger.getLogger(Configurator.class); ! public Configurator(String newConfigFilename) { configFile = new File(newConfigFilename); if (configFile.isFile() && configFile.canRead()) { --- 24,32 ---- public static Logger LOG = Logger.getLogger(Configurator.class); + + protected Configurator() { + } ! protected Configurator(String newConfigFilename) { configFile = new File(newConfigFilename); if (configFile.isFile() && configFile.canRead()) { *************** *** 55,61 **** } } public String get(String newConfig) { ! return new String((String) variables.get(newConfig)); } } --- 65,107 ---- } } + + public static Configurator getInstance() throws JDVBException { + if (configurator == null) { + throw new JDVBException("Configurator is not initialised yet. Please call load() first"); + } + return configurator; + } + + private static void cleanUp() { + props.clear(); + } + + public static void load(String filename) { + if (configurator != null) { + cleanUp(); + } + try { + load(new FileInputStream(filename)); + } catch (FileNotFoundException e) { + LOG.warn("File not found: [" + filename + "]. Ignoring load.", e); + cleanUp(); + } + } + + public static void load(InputStream inputStream) { + if (configurator != null) { + cleanUp(); + } + configurator = new Configurator(); + try { + props.load(inputStream); + } catch (IOException e) { + LOG.warn("General IO exception. Ignoring load.", e); + cleanUp(); + } + } public String get(String newConfig) { ! return props.getProperty(newConfig); } } |