Store db parameters in Config object, not in CFB object.
[cfb.git] / prod / net / jaekl / cfb / Config.java
index 9a0a1463ddda835b454e06723834470d446de1ed..76151a7c64c3b0159ede64dddd5dc2cb26624422 100644 (file)
@@ -17,6 +17,11 @@ 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";
@@ -64,6 +69,18 @@ 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();
@@ -79,6 +96,21 @@ public class Config {
                        }
                }
                
+               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));
                }
@@ -92,31 +124,6 @@ public class Config {
                        String[] addresses = props.getProperty(NOTIFY).split(",");
                        m_notify = Arrays.asList(addresses);
                }
-               
-               try (PrintWriter pw = new PrintWriter(System.out)) {
-                       dump(pw);                       
-               }
-       }
-       
-       private void dump(PrintWriter pw)
-       {
-               pw.println("CONFIG DUMP:");
-               pw.println("db_name: " + m_dbName);
-               pw.println("fbp:  " + m_fbp);
-               pw.println("fbDir:  " + m_fbDir);
-               pw.println("host:  " + m_host);
-               pw.println("port:  " + m_port);
-               pw.println("user:  " + m_user);
-               pw.println("pass:  " + m_pass);
-               pw.println("buildNum:  " + m_buildNum);
-               pw.println("removeSchema:  " + m_removeSchema);
-               pw.println("output:  " + m_output);
-               pw.println("mailFrom:  " + m_mailFrom);
-               pw.println("smtpHost:  " + m_mailSmtpHost);
-               pw.println("notify:  " + m_notify.size() + " entries");
-               for (String s : m_notify) {
-                       pw.println("= " + s);
-               }
        }
        
        public Options createOptions() {