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