diff -r 5e412dbd9362 -r 04db6ccd6c48 java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sun Dec 22 21:02:37 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sun Dec 22 22:02:44 2013 +0100 @@ -20,8 +20,12 @@ import info.globalcode.sql.dk.configuration.ConfigurationProvider; import info.globalcode.sql.dk.CLIOptions.MODE; import info.globalcode.sql.dk.configuration.Configuration; +import info.globalcode.sql.dk.configuration.ConfigurationException; +import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; /** * @@ -82,7 +86,7 @@ } @Override - public Configuration getConfiguration() { + public Configuration getConfiguration() throws ConfigurationException { if (configuration == null) { configuration = loadConfiguration(); } @@ -90,15 +94,27 @@ } private void installDefaultConfiguration() { - /** - * TODO: check config folder/file and create it if missing - */ + Constants.DIR.mkdir(); + + if (Constants.CONFIG_FILE.exists()) { + log.log(Level.FINE, "Config file already exists: {0}", Constants.CONFIG_FILE); + } else { + try { + Functions.installResource(Constants.EXAMPLE_CONFIG_FILE, Constants.CONFIG_FILE); + } catch (IOException e) { + log.log(Level.SEVERE, "Unable to write example configuration to " + Constants.CONFIG_FILE, e); + } + } + } - private Configuration loadConfiguration() { - /** - * TODO: load configuration from XML - */ - return null; + private Configuration loadConfiguration() throws ConfigurationException { + try { + JAXBContext jaxb = JAXBContext.newInstance(Configuration.class); + Unmarshaller u = jaxb.createUnmarshaller(); + return (Configuration) u.unmarshal(Constants.CONFIG_FILE); + } catch (Exception e) { + throw new ConfigurationException("Unable to load configuration from " + Constants.CONFIG_FILE, e); + } } }