Store db parameters in Config object, not in CFB object.
[cfb.git] / prod / net / jaekl / cfb / Config.java
index 8bb401dc4ebdb48d34f89290e3d030bda145b09f..76151a7c64c3b0159ede64dddd5dc2cb26624422 100644 (file)
@@ -1,20 +1,27 @@
 package net.jaekl.cfb;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Properties;
 
+import net.jaekl.qd.util.FileIO;
+
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.GnuParser;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 
 public class Config {
+       private static final String DB_HOST = "db.host";
+       private static final String DB_NAME = "db.name";
+       private static final String DB_PASS = "db.pass";
+       private static final String DB_PORT = "db.port";
+       private static final String DB_USER = "db.user";
        private static final String FINDBUGS_HOME = "FindBugsHome";
        private static final String MAIL_FROM = "mail.from";
        private static final String MAIL_SMTP_HOST = "mail.smtp.host";
@@ -62,21 +69,48 @@ public class Config {
        public String getMailSmtpHost() { return m_mailSmtpHost; }
        public ArrayList<String> getNotify() { return new ArrayList<String>(m_notify); }
        
+       public String getDbHost() { return m_host; }
+       public int    getDbPort() { return m_port; }
+       public String getDbName() { return m_dbName; }
+       public String getDbUser() { return m_user; }
+       public String getDbPass() { return m_pass; }
+       
+       public void setDbHost(String value) { m_host = value; }
+       public void setDbPort(int value)    { m_port = value; }
+       public void setDbName(String value) { m_dbName = value; }
+       public void setDbUser(String value) { m_user = value; }
+       public void setDbPass(String value) { m_pass = value; }
+       
        public void readFile(File configProperties) throws IOException
        {
                Properties props = new Properties();
-               FileInputStream fis = null;
+               InputStream is = null;
                
                try {
-                       fis = new FileInputStream(configProperties);
-                       props.load(fis);
+                       is = FileIO.getInst().openInput(configProperties);
+                       props.load(is);
                }
                finally {
-                       if (null != fis) {
-                               fis.close();
+                       if (null != is) {
+                               is.close();
                        }
                }
                
+               if (props.containsKey(DB_HOST)) {
+                       m_host = props.getProperty(DB_HOST);
+               }
+               if (props.containsKey(DB_NAME)) {
+                       m_dbName = props.getProperty(DB_NAME);
+               }
+               if (props.containsKey(DB_PASS)) {
+                       m_pass = props.getProperty(DB_PASS);
+               }
+               if (props.containsKey(DB_PORT)) {
+                       m_port = Integer.parseInt(props.getProperty(DB_PORT));
+               }
+               if (props.containsKey(DB_USER)) {
+                       m_user = props.getProperty(DB_USER);
+               }
                if (props.containsKey(FINDBUGS_HOME)) {
                        m_fbDir = new File(props.getProperty(FINDBUGS_HOME));
                }