java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java
author František Kučera <franta-hg@frantovo.cz>
Sun, 22 Dec 2013 18:35:50 +0100
branchv_0
changeset 30 b7ea47b2d4ca
parent 29 d66858b4b563
child 32 5e412dbd9362
permissions -rw-r--r--
class for xmlns constants
     1 /**
     2  * SQL-DK
     3  * Copyright © 2013 František Kučera (frantovo.cz)
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, either version 3 of the License, or
     8  * (at your option) any later version.
     9  *
    10  * This program is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  * GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 package info.globalcode.sql.dk.configuration;
    19 
    20 import static info.globalcode.sql.dk.Xmlns.CONFIGURATION;
    21 import static info.globalcode.sql.dk.Functions.findByName;
    22 import info.globalcode.sql.dk.formatting.SilentFormatter;
    23 import info.globalcode.sql.dk.formatting.XmlFormatter;
    24 import java.util.ArrayList;
    25 import java.util.Collection;
    26 import java.util.Collections;
    27 import java.util.List;
    28 import javax.xml.bind.annotation.XmlElement;
    29 import javax.xml.bind.annotation.XmlRootElement;
    30 
    31 /**
    32  *
    33  * @author Ing. František Kučera (frantovo.cz)
    34  */
    35 @XmlRootElement(name = "configuration", namespace = CONFIGURATION)
    36 public class Configuration {
    37 
    38 	private List<DatabaseDefinition> databases = new ArrayList<>();
    39 	private List<FormatterDefinition> formatters = new ArrayList<>();
    40 	private String defaultFormatter;
    41 	/**
    42 	 * Default list of formatters. Is used if particular name is not found in user configuration.
    43 	 */
    44 	private static final Collection<FormatterDefinition> buildInFormatters;
    45 
    46 	static {
    47 		Collection<FormatterDefinition> l = new ArrayList<>();
    48 		l.add(new FormatterDefinition(SilentFormatter.NAME, SilentFormatter.class.getName()));
    49 		l.add(new FormatterDefinition(XmlFormatter.NAME, XmlFormatter.class.getName()));
    50 		buildInFormatters = Collections.unmodifiableCollection(l);
    51 	}
    52 
    53 	@XmlElement(name = "database", namespace = CONFIGURATION)
    54 	public List<DatabaseDefinition> getDatabases() {
    55 		return databases;
    56 	}
    57 
    58 	public void setDatabases(List<DatabaseDefinition> databases) {
    59 		this.databases = databases;
    60 	}
    61 
    62 	public DatabaseDefinition getDatabase(String name) {
    63 		return findByName(databases, name);
    64 	}
    65 
    66 	@XmlElement(name = "formatter", namespace = CONFIGURATION)
    67 	public List<FormatterDefinition> getFormatters() {
    68 		return formatters;
    69 	}
    70 
    71 	public void setFormatters(List<FormatterDefinition> formatters) {
    72 		this.formatters = formatters;
    73 	}
    74 
    75 	public FormatterDefinition getFormatter(String name) {
    76 		FormatterDefinition fd = findByName(formatters, name);
    77 		return fd == null ? findByName(buildInFormatters, name) : fd;
    78 	}
    79 
    80 	/**
    81 	 * @return name of default formatter, is used if name is not specified on CLI
    82 	 */
    83 	@XmlElement(name = "defaultFormatter", namespace = CONFIGURATION)
    84 	public String getDefaultFormatter() {
    85 		return defaultFormatter;
    86 	}
    87 
    88 	public void setDefaultFormatter(String defaultFormatter) {
    89 		this.defaultFormatter = defaultFormatter;
    90 	}
    91 }