author | František Kučera <franta-hg@frantovo.cz> |
Mon, 04 Mar 2019 20:15:24 +0100 | |
branch | v_0 |
changeset 238 | 4a1864c3e867 |
parent 224 | java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java@36db9fd27436 |
child 248 | 7f81cfa150d0 |
permissions | -rw-r--r-- |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* SQL-DK |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2013 František Kučera (frantovo.cz) |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* (at your option) any later version. |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
*/ |
26
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
18 |
package info.globalcode.sql.dk.configuration; |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
19 |
|
30
b7ea47b2d4ca
class for xmlns constants
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
20 |
import static info.globalcode.sql.dk.Xmlns.CONFIGURATION; |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
21 |
import static info.globalcode.sql.dk.Functions.findByName; |
224
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
202
diff
changeset
|
22 |
import info.globalcode.sql.dk.formatting.BarChartFormatter; |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
23 |
import info.globalcode.sql.dk.formatting.SilentFormatter; |
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
24 |
import info.globalcode.sql.dk.formatting.SingleRecordFormatter; |
60
d4e88172a363
SingleValueFormatter
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
25 |
import info.globalcode.sql.dk.formatting.SingleValueFormatter; |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
26 |
import info.globalcode.sql.dk.formatting.TabularFormatter; |
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
80
diff
changeset
|
27 |
import info.globalcode.sql.dk.formatting.TabularPrefetchingFormatter; |
123
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
89
diff
changeset
|
28 |
import info.globalcode.sql.dk.formatting.TabularWrappingFormatter; |
174
3c6d560a1d14
TeXFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
29 |
import info.globalcode.sql.dk.formatting.TeXFormatter; |
128
67f5ff139da0
XML formatter: abstract + part of basic XML formatter
František Kučera <franta-hg@frantovo.cz>
parents:
123
diff
changeset
|
30 |
import info.globalcode.sql.dk.formatting.XhtmlFormatter; |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
31 |
import info.globalcode.sql.dk.formatting.XmlFormatter; |
26
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
32 |
import java.util.ArrayList; |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
33 |
import java.util.Collection; |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
34 |
import java.util.Collections; |
26
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
35 |
import java.util.List; |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
36 |
import javax.xml.bind.annotation.XmlElement; |
26
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
37 |
import javax.xml.bind.annotation.XmlRootElement; |
67
10c9b9e54622
option --list-formatters – list configured and built-in formatters
František Kučera <franta-hg@frantovo.cz>
parents:
60
diff
changeset
|
38 |
import javax.xml.bind.annotation.XmlTransient; |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
|
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
/** |
155 | 41 |
* Object representation of user configuration loaded from XML. |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
* |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
* @author Ing. František Kučera (frantovo.cz) |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
*/ |
30
b7ea47b2d4ca
class for xmlns constants
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
45 |
@XmlRootElement(name = "configuration", namespace = CONFIGURATION) |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
public class Configuration { |
26
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
47 |
|
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
48 |
private List<DatabaseDefinition> databases = new ArrayList<>(); |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
49 |
private List<FormatterDefinition> formatters = new ArrayList<>(); |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
50 |
/** |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
51 |
* is used if no formatter is specified on CLI nor in user configuration |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
52 |
*/ |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
53 |
public static final String DEFAULT_FORMATTER = TabularFormatter.NAME; |
89
98d18e9a357b
InfoLister (configuration listings) will use TabularPrefetchingFormatter as default
František Kučera <franta-hg@frantovo.cz>
parents:
88
diff
changeset
|
54 |
/** |
98d18e9a357b
InfoLister (configuration listings) will use TabularPrefetchingFormatter as default
František Kučera <franta-hg@frantovo.cz>
parents:
88
diff
changeset
|
55 |
* Can be used as default if prefetching is ok – for configuration listings (config is alread in |
98d18e9a357b
InfoLister (configuration listings) will use TabularPrefetchingFormatter as default
František Kučera <franta-hg@frantovo.cz>
parents:
88
diff
changeset
|
56 |
* memory, so this does not matter) |
98d18e9a357b
InfoLister (configuration listings) will use TabularPrefetchingFormatter as default
František Kučera <franta-hg@frantovo.cz>
parents:
88
diff
changeset
|
57 |
*/ |
98d18e9a357b
InfoLister (configuration listings) will use TabularPrefetchingFormatter as default
František Kučera <franta-hg@frantovo.cz>
parents:
88
diff
changeset
|
58 |
public static final String DEFAULT_FORMATTER_PREFETCHING = TabularPrefetchingFormatter.NAME; |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
59 |
private String defaultFormatter; |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
60 |
/** |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
61 |
* Default list of formatters. Is used if particular name is not found in user configuration. |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
62 |
*/ |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
63 |
private static final Collection<FormatterDefinition> buildInFormatters; |
26
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
64 |
|
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
65 |
static { |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
66 |
Collection<FormatterDefinition> l = new ArrayList<>(); |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
67 |
l.add(new FormatterDefinition(SilentFormatter.NAME, SilentFormatter.class.getName())); |
60
d4e88172a363
SingleValueFormatter
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
68 |
l.add(new FormatterDefinition(SingleValueFormatter.NAME, SingleValueFormatter.class.getName())); |
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
69 |
l.add(new FormatterDefinition(SingleRecordFormatter.NAME, SingleRecordFormatter.class.getName())); |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
70 |
l.add(new FormatterDefinition(XmlFormatter.NAME, XmlFormatter.class.getName())); |
128
67f5ff139da0
XML formatter: abstract + part of basic XML formatter
František Kučera <franta-hg@frantovo.cz>
parents:
123
diff
changeset
|
71 |
l.add(new FormatterDefinition(XhtmlFormatter.NAME, XhtmlFormatter.class.getName())); |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
72 |
l.add(new FormatterDefinition(TabularFormatter.NAME, TabularFormatter.class.getName())); |
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
80
diff
changeset
|
73 |
l.add(new FormatterDefinition(TabularPrefetchingFormatter.NAME, TabularPrefetchingFormatter.class.getName())); |
123
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
89
diff
changeset
|
74 |
l.add(new FormatterDefinition(TabularWrappingFormatter.NAME, TabularWrappingFormatter.class.getName())); |
174
3c6d560a1d14
TeXFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
155
diff
changeset
|
75 |
l.add(new FormatterDefinition(TeXFormatter.NAME, TeXFormatter.class.getName())); |
224
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
202
diff
changeset
|
76 |
//l.add(new FormatterDefinition(DsvFormatter.NAME, DsvFormatter.class.getName())); |
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
202
diff
changeset
|
77 |
//l.add(new FormatterDefinition(SystemCommandExecutor.NAME, SystemCommandExecutor.class.getName())); |
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
202
diff
changeset
|
78 |
l.add(new FormatterDefinition(BarChartFormatter.NAME, BarChartFormatter.class.getName())); |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
79 |
buildInFormatters = Collections.unmodifiableCollection(l); |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
80 |
} |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
81 |
|
30
b7ea47b2d4ca
class for xmlns constants
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
82 |
@XmlElement(name = "database", namespace = CONFIGURATION) |
26
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
83 |
public List<DatabaseDefinition> getDatabases() { |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
84 |
return databases; |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
85 |
} |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
86 |
|
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
87 |
public void setDatabases(List<DatabaseDefinition> databases) { |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
88 |
this.databases = databases; |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
89 |
} |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
90 |
|
75
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
91 |
/** |
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
188
diff
changeset
|
92 |
* @param name |
224
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
202
diff
changeset
|
93 |
* @return |
75
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
94 |
* @throws ConfigurationException if no database with this name is configured |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
95 |
*/ |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
96 |
public DatabaseDefinition getDatabase(String name) throws ConfigurationException { |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
97 |
DatabaseDefinition dd = findByName(databases, name); |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
98 |
if (dd == null) { |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
99 |
throw new ConfigurationException("Database is not configured: " + name); |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
100 |
} else { |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
101 |
return dd; |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
102 |
} |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
103 |
} |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
104 |
|
80
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
105 |
/** |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
106 |
* @return only configured formatters |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
107 |
* @see #getBuildInFormatters() |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
108 |
* @see #getAllFormatters() |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
109 |
*/ |
30
b7ea47b2d4ca
class for xmlns constants
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
110 |
@XmlElement(name = "formatter", namespace = CONFIGURATION) |
26
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
111 |
public List<FormatterDefinition> getFormatters() { |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
112 |
return formatters; |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
113 |
} |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
114 |
|
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
115 |
public void setFormatters(List<FormatterDefinition> formatters) { |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
116 |
this.formatters = formatters; |
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
117 |
} |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
118 |
|
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
119 |
/** |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
120 |
* @param name name of desired formatter. Looking for this name in user configuration, then in |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
121 |
* buil-in formatters. If null, default from configuration or (if not configured) built-in |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
122 |
* default is used. |
75
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
123 |
* @return formatter definition |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
124 |
* @throws ConfigurationException if no formatter with this name was found |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
125 |
*/ |
75
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
126 |
public FormatterDefinition getFormatter(String name) throws ConfigurationException { |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
127 |
if (name == null) { |
75
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
128 |
return defaultFormatter == null ? getFormatter(DEFAULT_FORMATTER) : getFormatter(defaultFormatter); |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
129 |
} else { |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
130 |
FormatterDefinition fd = findByName(formatters, name); |
75
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
131 |
fd = fd == null ? findByName(buildInFormatters, name) : fd; |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
132 |
if (fd == null) { |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
133 |
throw new ConfigurationException("Formatter is not configured: " + name); |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
134 |
} else { |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
135 |
return fd; |
43aa4625ab7e
throw ConfigurationException instead of returning null, if database or formatter of given name is not configured
František Kučera <franta-hg@frantovo.cz>
parents:
67
diff
changeset
|
136 |
} |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
137 |
} |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
138 |
} |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
139 |
|
80
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
140 |
/** |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
141 |
* @return only built-in formatters |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
142 |
* @see #getAllFormatters() |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
143 |
* @see #getFormatters() |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
144 |
*/ |
67
10c9b9e54622
option --list-formatters – list configured and built-in formatters
František Kučera <franta-hg@frantovo.cz>
parents:
60
diff
changeset
|
145 |
@XmlTransient |
10c9b9e54622
option --list-formatters – list configured and built-in formatters
František Kučera <franta-hg@frantovo.cz>
parents:
60
diff
changeset
|
146 |
public Collection<FormatterDefinition> getBuildInFormatters() { |
10c9b9e54622
option --list-formatters – list configured and built-in formatters
František Kučera <franta-hg@frantovo.cz>
parents:
60
diff
changeset
|
147 |
return buildInFormatters; |
10c9b9e54622
option --list-formatters – list configured and built-in formatters
František Kučera <franta-hg@frantovo.cz>
parents:
60
diff
changeset
|
148 |
} |
10c9b9e54622
option --list-formatters – list configured and built-in formatters
František Kučera <franta-hg@frantovo.cz>
parents:
60
diff
changeset
|
149 |
|
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
150 |
/** |
80
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
151 |
* @return built-in + configured formatters |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
152 |
* @see #getFormatters() |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
153 |
*/ |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
154 |
@XmlTransient |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
155 |
public Collection<FormatterDefinition> getAllFormatters() { |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
156 |
Collection<FormatterDefinition> allFormatters = new ArrayList<>(); |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
157 |
allFormatters.addAll(buildInFormatters); |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
158 |
allFormatters.addAll(formatters); |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
159 |
return allFormatters; |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
160 |
} |
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
161 |
|
c4635ab3a7af
bash completion: generate helper files with databases and formatters from configuration
František Kučera <franta-hg@frantovo.cz>
parents:
75
diff
changeset
|
162 |
/** |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
163 |
* @return name of default formatter, is used if name is not specified on CLI |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
164 |
*/ |
30
b7ea47b2d4ca
class for xmlns constants
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
165 |
@XmlElement(name = "defaultFormatter", namespace = CONFIGURATION) |
29
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
166 |
public String getDefaultFormatter() { |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
167 |
return defaultFormatter; |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
168 |
} |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
169 |
|
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
170 |
public void setDefaultFormatter(String defaultFormatter) { |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
171 |
this.defaultFormatter = defaultFormatter; |
d66858b4b563
more configuration, more JAXB, more formatters
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
172 |
} |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
173 |
} |