/**
* SQL-DK
* Copyright © 2013 František Kučera (frantovo.cz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package info.globalcode.sql.dk.configuration;
import static info.globalcode.sql.dk.Constants.XMLNS_CONFIGURATION;
import static info.globalcode.sql.dk.Functions.findByName;
import info.globalcode.sql.dk.formatting.SilentFormatter;
import info.globalcode.sql.dk.formatting.XmlFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author Ing. František Kučera (frantovo.cz)
*/
@XmlRootElement(name = "configuration", namespace = XMLNS_CONFIGURATION)
public class Configuration {
private List<DatabaseDefinition> databases = new ArrayList<>();
private List<FormatterDefinition> formatters = new ArrayList<>();
private String defaultFormatter;
/**
* Default list of formatters. Is used if particular name is not found in user configuration.
*/
private static final Collection<FormatterDefinition> buildInFormatters;
static {
Collection<FormatterDefinition> l = new ArrayList<>();
l.add(new FormatterDefinition(SilentFormatter.NAME, SilentFormatter.class.getName()));
l.add(new FormatterDefinition(XmlFormatter.NAME, XmlFormatter.class.getName()));
buildInFormatters = Collections.unmodifiableCollection(l);
}
@XmlElement(name = "database", namespace = XMLNS_CONFIGURATION)
public List<DatabaseDefinition> getDatabases() {
return databases;
}
public void setDatabases(List<DatabaseDefinition> databases) {
this.databases = databases;
}
public DatabaseDefinition getDatabase(String name) {
return findByName(databases, name);
}
@XmlElement(name = "formatter", namespace = XMLNS_CONFIGURATION)
public List<FormatterDefinition> getFormatters() {
return formatters;
}
public void setFormatters(List<FormatterDefinition> formatters) {
this.formatters = formatters;
}
public FormatterDefinition getFormatter(String name) {
FormatterDefinition fd = findByName(formatters, name);
return fd == null ? findByName(buildInFormatters, name) : fd;
}
/**
* @return name of default formatter, is used if name is not specified on CLI
*/
@XmlElement(name = "defaultFormatter", namespace = XMLNS_CONFIGURATION)
public String getDefaultFormatter() {
return defaultFormatter;
}
public void setDefaultFormatter(String defaultFormatter) {
this.defaultFormatter = defaultFormatter;
}
}