java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java
branchv_0
changeset 20 e225bdcd260e
parent 17 d8ab8aece6f2
child 21 d42ed0d10a10
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Mon Dec 16 20:42:45 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Mon Dec 16 23:17:34 2013 +0100
     1.3 @@ -17,6 +17,7 @@
     1.4   */
     1.5  package info.globalcode.sql.dk;
     1.6  
     1.7 +import info.globalcode.sql.dk.CLIOptions.MODE;
     1.8  import java.util.logging.Level;
     1.9  import java.util.logging.Logger;
    1.10  
    1.11 @@ -24,28 +25,73 @@
    1.12   *
    1.13   * @author Ing. František Kučera (frantovo.cz)
    1.14   */
    1.15 -public class CLIStarter {
    1.16 +public class CLIStarter implements ConfigurationProvider {
    1.17  
    1.18  	private static final Logger log = Logger.getLogger(CLIStarter.class.getName());
    1.19 +	private CLIOptions options;
    1.20 +	private Configuration configuration;
    1.21  
    1.22  	public static void main(String[] args) {
    1.23  		try {
    1.24 -			/** Parse options */
    1.25  			CLIParser parser = new CLIParser();
    1.26  			CLIOptions options = parser.parseOptions(args);
    1.27 -
    1.28  			options.validate();
    1.29 -
    1.30 -			/** Show info */
    1.31 -			if (!options.getShowInfo().isEmpty()) {
    1.32 -				InfoLister infoLister = new InfoLister(System.err);
    1.33 -				infoLister.showInfo(options);
    1.34 -			}
    1.35 -
    1.36 +			CLIStarter starter = new CLIStarter(options);
    1.37 +			starter.process();
    1.38  		} catch (CLIParserException e) {
    1.39  			log.log(Level.SEVERE, "Unable to parse CLI options", e);
    1.40  		} catch (InvalidOptionsException e) {
    1.41  			log.log(Level.SEVERE, "Invalid CLI options", e);
    1.42  		}
    1.43  	}
    1.44 +
    1.45 +	public CLIStarter(CLIOptions options) {
    1.46 +		this.options = options;
    1.47 +	}
    1.48 +
    1.49 +	private void process() {
    1.50 +		/** Show info */
    1.51 +		if (!options.getShowInfo().isEmpty()) {
    1.52 +			InfoLister infoLister = new InfoLister(System.err, this);
    1.53 +			infoLister.showInfo(options);
    1.54 +		}
    1.55 +
    1.56 +		MODE mode = options.getMode();
    1.57 +		switch (mode) {
    1.58 +			case QUERY_NOW:
    1.59 +				break;
    1.60 +			case PREPARE_BATCH:
    1.61 +				break;
    1.62 +			case EXECUTE_BATCH:
    1.63 +				break;
    1.64 +			case JUST_SHOW_INFO:
    1.65 +				// already done above
    1.66 +				break;
    1.67 +			default:
    1.68 +				log.log(Level.SEVERE, "Unsupported mode: {0}", mode);
    1.69 +				break;
    1.70 +		}
    1.71 +	}
    1.72 +
    1.73 +	@Override
    1.74 +	public Configuration getConfiguration() {
    1.75 +		if (configuration == null) {
    1.76 +			installDefaultConfiguration();
    1.77 +			configuration = loadConfiguration();
    1.78 +		}
    1.79 +		return configuration;
    1.80 +	}
    1.81 +
    1.82 +	private void installDefaultConfiguration() {
    1.83 +		/**
    1.84 +		 * TODO: check config folder/file and create it if missing
    1.85 +		 */
    1.86 +	}
    1.87 +
    1.88 +	private Configuration loadConfiguration() {
    1.89 +		/**
    1.90 +		 * TODO: load configuration from XML
    1.91 +		 */
    1.92 +		return null;
    1.93 +	}
    1.94  }