1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sat May 16 20:25:16 2015 +0200
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sat May 16 21:42:52 2015 +0200
1.3 @@ -27,6 +27,7 @@
1.4 import info.globalcode.sql.dk.configuration.ConfigurationException;
1.5 import info.globalcode.sql.dk.configuration.DatabaseDefinition;
1.6 import info.globalcode.sql.dk.configuration.FormatterDefinition;
1.7 +import info.globalcode.sql.dk.configuration.Loader;
1.8 import info.globalcode.sql.dk.configuration.NameIdentified;
1.9 import info.globalcode.sql.dk.formatting.Formatter;
1.10 import info.globalcode.sql.dk.formatting.FormatterContext;
1.11 @@ -43,8 +44,6 @@
1.12 import java.util.logging.Level;
1.13 import java.util.logging.LogRecord;
1.14 import java.util.logging.Logger;
1.15 -import javax.xml.bind.JAXBContext;
1.16 -import javax.xml.bind.Unmarshaller;
1.17
1.18 /**
1.19 * Entry point of the command line interface of SQL-DK.
1.20 @@ -64,7 +63,8 @@
1.21 public static final int EXIT_FORMATTING_ERROR = 7; // doc:formatting error
1.22 public static final int EXIT_BATCH_ERROR = 8; // doc:batch error
1.23 private static final Logger log = Logger.getLogger(CLIStarter.class.getName());
1.24 - private CLIOptions options;
1.25 + private final CLIOptions options;
1.26 + private final Loader configurationLoader = new Loader();
1.27 private Configuration configuration;
1.28
1.29 public static void main(String[] args) {
1.30 @@ -186,7 +186,7 @@
1.31 @Override
1.32 public Configuration getConfiguration() throws ConfigurationException {
1.33 if (configuration == null) {
1.34 - configuration = loadConfiguration();
1.35 + configuration = configurationLoader.loadConfiguration();
1.36 }
1.37 return configuration;
1.38 }
1.39 @@ -206,16 +206,6 @@
1.40 }
1.41 }
1.42
1.43 - private Configuration loadConfiguration() throws ConfigurationException {
1.44 - try {
1.45 - JAXBContext jaxb = JAXBContext.newInstance(Configuration.class);
1.46 - Unmarshaller u = jaxb.createUnmarshaller();
1.47 - return (Configuration) u.unmarshal(Constants.CONFIG_FILE);
1.48 - } catch (Exception e) {
1.49 - throw new ConfigurationException("Unable to load configuration from " + Constants.CONFIG_FILE, e);
1.50 - }
1.51 - }
1.52 -
1.53 private void generateBashCompletion() {
1.54 if (configuration == null) {
1.55 log.log(Level.FINER, "Not writing Bash completion helper files. In order to generate these files please run some command which requires configuration.");
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/Loader.java Sat May 16 21:42:52 2015 +0200
2.3 @@ -0,0 +1,41 @@
2.4 +/**
2.5 + * SQL-DK
2.6 + * Copyright © 2015 František Kučera (frantovo.cz)
2.7 + *
2.8 + * This program is free software: you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation, either version 3 of the License, or
2.11 + * (at your option) any later version.
2.12 + *
2.13 + * This program is distributed in the hope that it will be useful,
2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.16 + * GNU General Public License for more details.
2.17 + *
2.18 + * You should have received a copy of the GNU General Public License
2.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2.20 + */
2.21 +package info.globalcode.sql.dk.configuration;
2.22 +
2.23 +import info.globalcode.sql.dk.*;
2.24 +import javax.xml.bind.JAXBContext;
2.25 +import javax.xml.bind.Unmarshaller;
2.26 +
2.27 +/**
2.28 + * Configuration loader – deserializes Configuration from the XML file.
2.29 + *
2.30 + * @author Ing. František Kučera (frantovo.cz)
2.31 + */
2.32 +public class Loader {
2.33 +
2.34 + public Configuration loadConfiguration() throws ConfigurationException {
2.35 + try {
2.36 + JAXBContext jaxb = JAXBContext.newInstance(Configuration.class);
2.37 + Unmarshaller u = jaxb.createUnmarshaller();
2.38 + return (Configuration) u.unmarshal(Constants.CONFIG_FILE);
2.39 + } catch (Exception e) {
2.40 + throw new ConfigurationException("Unable to load configuration from " + Constants.CONFIG_FILE, e);
2.41 + }
2.42 + }
2.43 +
2.44 +}