java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java
branchv_0
changeset 32 5e412dbd9362
parent 30 b7ea47b2d4ca
child 60 d4e88172a363
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java	Sun Dec 22 20:51:32 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java	Sun Dec 22 21:02:37 2013 +0100
     1.3 @@ -20,6 +20,7 @@
     1.4  import static info.globalcode.sql.dk.Xmlns.CONFIGURATION;
     1.5  import static info.globalcode.sql.dk.Functions.findByName;
     1.6  import info.globalcode.sql.dk.formatting.SilentFormatter;
     1.7 +import info.globalcode.sql.dk.formatting.TabularFormatter;
     1.8  import info.globalcode.sql.dk.formatting.XmlFormatter;
     1.9  import java.util.ArrayList;
    1.10  import java.util.Collection;
    1.11 @@ -37,6 +38,10 @@
    1.12  
    1.13  	private List<DatabaseDefinition> databases = new ArrayList<>();
    1.14  	private List<FormatterDefinition> formatters = new ArrayList<>();
    1.15 +	/**
    1.16 +	 * is used if no formatter is specified on CLI nor in user configuration
    1.17 +	 */
    1.18 +	public static final String DEFAULT_FORMATTER = TabularFormatter.NAME;
    1.19  	private String defaultFormatter;
    1.20  	/**
    1.21  	 * Default list of formatters. Is used if particular name is not found in user configuration.
    1.22 @@ -47,6 +52,7 @@
    1.23  		Collection<FormatterDefinition> l = new ArrayList<>();
    1.24  		l.add(new FormatterDefinition(SilentFormatter.NAME, SilentFormatter.class.getName()));
    1.25  		l.add(new FormatterDefinition(XmlFormatter.NAME, XmlFormatter.class.getName()));
    1.26 +		l.add(new FormatterDefinition(TabularFormatter.NAME, TabularFormatter.class.getName()));
    1.27  		buildInFormatters = Collections.unmodifiableCollection(l);
    1.28  	}
    1.29  
    1.30 @@ -72,9 +78,23 @@
    1.31  		this.formatters = formatters;
    1.32  	}
    1.33  
    1.34 +	/**
    1.35 +	 * @param name name of desired formatter. Looking for this name in user configuration, then in
    1.36 +	 * buil-in formatters. If null, default from configuration or (if not configured) built-in
    1.37 +	 * default is used.
    1.38 +	 * @return formatter definition or null if none for this name is found
    1.39 +	 */
    1.40  	public FormatterDefinition getFormatter(String name) {
    1.41 -		FormatterDefinition fd = findByName(formatters, name);
    1.42 -		return fd == null ? findByName(buildInFormatters, name) : fd;
    1.43 +		if (name == null) {
    1.44 +			if (defaultFormatter == null) {
    1.45 +				return getFormatter(DEFAULT_FORMATTER);
    1.46 +			} else {
    1.47 +				return getFormatter(defaultFormatter);
    1.48 +			}
    1.49 +		} else {
    1.50 +			FormatterDefinition fd = findByName(formatters, name);
    1.51 +			return fd == null ? findByName(buildInFormatters, name) : fd;
    1.52 +		}
    1.53  	}
    1.54  
    1.55  	/**