franta-hg@16: /** franta-hg@16: * SQL-DK franta-hg@16: * Copyright © 2013 František Kučera (frantovo.cz) franta-hg@16: * franta-hg@16: * This program is free software: you can redistribute it and/or modify franta-hg@16: * it under the terms of the GNU General Public License as published by franta-hg@16: * the Free Software Foundation, either version 3 of the License, or franta-hg@16: * (at your option) any later version. franta-hg@16: * franta-hg@16: * This program is distributed in the hope that it will be useful, franta-hg@16: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@16: * GNU General Public License for more details. franta-hg@16: * franta-hg@16: * You should have received a copy of the GNU General Public License franta-hg@16: * along with this program. If not, see . franta-hg@16: */ franta-hg@1: package info.globalcode.sql.dk; franta-hg@1: franta-hg@26: import info.globalcode.sql.dk.configuration.ConfigurationProvider; franta-hg@20: import info.globalcode.sql.dk.CLIOptions.MODE; franta-hg@26: import info.globalcode.sql.dk.configuration.Configuration; franta-hg@13: import java.util.logging.Level; franta-hg@13: import java.util.logging.Logger; franta-hg@13: franta-hg@1: /** franta-hg@1: * franta-hg@1: * @author Ing. František Kučera (frantovo.cz) franta-hg@1: */ franta-hg@20: public class CLIStarter implements ConfigurationProvider { franta-hg@1: franta-hg@13: private static final Logger log = Logger.getLogger(CLIStarter.class.getName()); franta-hg@20: private CLIOptions options; franta-hg@20: private Configuration configuration; franta-hg@13: franta-hg@1: public static void main(String[] args) { franta-hg@21: franta-hg@21: if (args.length == 0) { franta-hg@21: args = new String[]{CLIParser.Tokens.INFO_HELP}; franta-hg@21: } franta-hg@21: franta-hg@13: try { franta-hg@13: CLIParser parser = new CLIParser(); franta-hg@13: CLIOptions options = parser.parseOptions(args); franta-hg@14: options.validate(); franta-hg@20: CLIStarter starter = new CLIStarter(options); franta-hg@21: starter.installDefaultConfiguration(); franta-hg@20: starter.process(); franta-hg@13: } catch (CLIParserException e) { franta-hg@14: log.log(Level.SEVERE, "Unable to parse CLI options", e); franta-hg@14: } catch (InvalidOptionsException e) { franta-hg@14: log.log(Level.SEVERE, "Invalid CLI options", e); franta-hg@13: } franta-hg@4: } franta-hg@20: franta-hg@20: public CLIStarter(CLIOptions options) { franta-hg@20: this.options = options; franta-hg@20: } franta-hg@20: franta-hg@20: private void process() { franta-hg@20: /** Show info */ franta-hg@20: if (!options.getShowInfo().isEmpty()) { franta-hg@20: InfoLister infoLister = new InfoLister(System.err, this); franta-hg@20: infoLister.showInfo(options); franta-hg@20: } franta-hg@20: franta-hg@20: MODE mode = options.getMode(); franta-hg@20: switch (mode) { franta-hg@20: case QUERY_NOW: franta-hg@20: break; franta-hg@20: case PREPARE_BATCH: franta-hg@20: break; franta-hg@20: case EXECUTE_BATCH: franta-hg@20: break; franta-hg@20: case JUST_SHOW_INFO: franta-hg@20: // already done above franta-hg@20: break; franta-hg@20: default: franta-hg@20: log.log(Level.SEVERE, "Unsupported mode: {0}", mode); franta-hg@20: break; franta-hg@20: } franta-hg@20: } franta-hg@20: franta-hg@20: @Override franta-hg@20: public Configuration getConfiguration() { franta-hg@20: if (configuration == null) { franta-hg@20: configuration = loadConfiguration(); franta-hg@20: } franta-hg@20: return configuration; franta-hg@20: } franta-hg@20: franta-hg@20: private void installDefaultConfiguration() { franta-hg@20: /** franta-hg@20: * TODO: check config folder/file and create it if missing franta-hg@20: */ franta-hg@20: } franta-hg@20: franta-hg@20: private Configuration loadConfiguration() { franta-hg@20: /** franta-hg@20: * TODO: load configuration from XML franta-hg@20: */ franta-hg@20: return null; franta-hg@20: } franta-hg@1: }