author | František Kučera <franta-hg@frantovo.cz> |
Wed, 25 Dec 2013 00:43:06 +0100 | |
branch | v_0 |
changeset 55 | f5ed7c4efacc |
parent 48 | 28735e71a1da |
child 56 | 29f45ab3b959 |
permissions | -rw-r--r-- |
16
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
1 |
/** |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
2 |
* SQL-DK |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
3 |
* Copyright © 2013 František Kučera (frantovo.cz) |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
4 |
* |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
8 |
* (at your option) any later version. |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
9 |
* |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
13 |
* GNU General Public License for more details. |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
14 |
* |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
5b8fcd35d4d6
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
17 |
*/ |
1
f32dac78d13a
WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
package info.globalcode.sql.dk; |
f32dac78d13a
WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
|
26
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
20 |
import info.globalcode.sql.dk.configuration.ConfigurationProvider; |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
21 |
import info.globalcode.sql.dk.CLIOptions.MODE; |
26
4ec8e5534eb9
configuration basics
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
22 |
import info.globalcode.sql.dk.configuration.Configuration; |
33
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
23 |
import info.globalcode.sql.dk.configuration.ConfigurationException; |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
24 |
import info.globalcode.sql.dk.configuration.DatabaseDefinition; |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
25 |
import info.globalcode.sql.dk.configuration.FormatterDefinition; |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
26 |
import info.globalcode.sql.dk.formatting.Formatter; |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
27 |
import info.globalcode.sql.dk.formatting.FormatterContext; |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
28 |
import info.globalcode.sql.dk.formatting.FormatterException; |
33
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
29 |
import java.io.IOException; |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
30 |
import java.sql.SQLException; |
13 | 31 |
import java.util.logging.Level; |
32 |
import java.util.logging.Logger; |
|
33
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
33 |
import javax.xml.bind.JAXBContext; |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
34 |
import javax.xml.bind.Unmarshaller; |
13 | 35 |
|
1
f32dac78d13a
WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
/** |
f32dac78d13a
WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
* |
f32dac78d13a
WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
* @author Ing. František Kučera (frantovo.cz) |
f32dac78d13a
WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
*/ |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
40 |
public class CLIStarter implements ConfigurationProvider { |
1
f32dac78d13a
WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
|
13 | 42 |
private static final Logger log = Logger.getLogger(CLIStarter.class.getName()); |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
43 |
private CLIOptions options; |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
44 |
private Configuration configuration; |
13 | 45 |
|
1
f32dac78d13a
WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
public static void main(String[] args) { |
55 | 47 |
log.log(Level.FINE, "Starting " + Constants.PROGRAM_NAME); |
21
d42ed0d10a10
CLI: --help is default option
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
48 |
|
d42ed0d10a10
CLI: --help is default option
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
49 |
if (args.length == 0) { |
d42ed0d10a10
CLI: --help is default option
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
50 |
args = new String[]{CLIParser.Tokens.INFO_HELP}; |
d42ed0d10a10
CLI: --help is default option
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
51 |
} |
d42ed0d10a10
CLI: --help is default option
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
52 |
|
13 | 53 |
try { |
54 |
CLIParser parser = new CLIParser(); |
|
55 |
CLIOptions options = parser.parseOptions(args); |
|
14 | 56 |
options.validate(); |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
57 |
CLIStarter starter = new CLIStarter(options); |
21
d42ed0d10a10
CLI: --help is default option
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
58 |
starter.installDefaultConfiguration(); |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
59 |
starter.process(); |
55 | 60 |
log.log(Level.FINE, "All done"); |
13 | 61 |
} catch (CLIParserException e) { |
14 | 62 |
log.log(Level.SEVERE, "Unable to parse CLI options", e); |
63 |
} catch (InvalidOptionsException e) { |
|
64 |
log.log(Level.SEVERE, "Invalid CLI options", e); |
|
48
28735e71a1da
print CLI options problems if any
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
65 |
for (InvalidOptionsException.OptionProblem p : e.getProblems()) { |
28735e71a1da
print CLI options problems if any
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
66 |
log.log(Level.SEVERE, "Option problem: {0}", p.getDescription()); |
28735e71a1da
print CLI options problems if any
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
67 |
} |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
68 |
} catch (ConfigurationException e) { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
69 |
log.log(Level.SEVERE, "Configuration problem", e); |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
70 |
} catch (SQLException e) { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
71 |
log.log(Level.SEVERE, "SQL problem", e); |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
72 |
} catch (FormatterException e) { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
73 |
log.log(Level.SEVERE, "Formatting problem", e); |
13 | 74 |
} |
4
f5c3350f3d78
data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
75 |
} |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
76 |
|
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
77 |
public CLIStarter(CLIOptions options) { |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
78 |
this.options = options; |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
79 |
} |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
80 |
|
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
81 |
private void process() throws ConfigurationException, SQLException, FormatterException { |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
82 |
/** Show info */ |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
83 |
if (!options.getShowInfo().isEmpty()) { |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
84 |
InfoLister infoLister = new InfoLister(System.err, this); |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
85 |
infoLister.showInfo(options); |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
86 |
} |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
87 |
|
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
88 |
MODE mode = options.getMode(); |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
89 |
switch (mode) { |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
90 |
case QUERY_NOW: |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
91 |
processQueryNow(); |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
92 |
break; |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
93 |
case PREPARE_BATCH: |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
94 |
processPrepareBatch(); |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
95 |
break; |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
96 |
case EXECUTE_BATCH: |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
97 |
processExecuteBatch(); |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
98 |
break; |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
99 |
case JUST_SHOW_INFO: |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
100 |
// already done above |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
101 |
break; |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
102 |
default: |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
103 |
log.log(Level.SEVERE, "Unsupported mode: {0}", mode); |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
104 |
break; |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
105 |
} |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
106 |
} |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
107 |
|
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
108 |
private void processQueryNow() throws ConfigurationException, SQLException, FormatterException { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
109 |
DatabaseDefinition dd = getConfiguration().getDatabase(options.getDatabaseName()); |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
110 |
if (dd == null) { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
111 |
throw new ConfigurationException("Database is not configured: " + options.getDatabaseName()); |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
112 |
} else { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
113 |
FormatterDefinition fd = configuration.getFormatter(options.getFormatterName()); |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
114 |
if (fd == null) { |
36 | 115 |
throw new ConfigurationException("Formatter is not configured: " + options.getFormatterName()); |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
116 |
} else { |
42
6fdaa4db3943
DatabaseConnection implements AutoCloseable
František Kučera <franta-hg@frantovo.cz>
parents:
36
diff
changeset
|
117 |
try (DatabaseConnection c = dd.connect()) { |
55 | 118 |
log.log(Level.FINE, "Database connected"); |
42
6fdaa4db3943
DatabaseConnection implements AutoCloseable
František Kučera <franta-hg@frantovo.cz>
parents:
36
diff
changeset
|
119 |
Formatter f = fd.getInstance(new FormatterContext(options.getOutputStream())); |
6fdaa4db3943
DatabaseConnection implements AutoCloseable
František Kučera <franta-hg@frantovo.cz>
parents:
36
diff
changeset
|
120 |
c.executeQuery(options.getSQLCommand(), f); |
6fdaa4db3943
DatabaseConnection implements AutoCloseable
František Kučera <franta-hg@frantovo.cz>
parents:
36
diff
changeset
|
121 |
} |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
122 |
} |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
123 |
} |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
124 |
} |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
125 |
|
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
126 |
private void processPrepareBatch() { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
127 |
} |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
128 |
|
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
129 |
private void processExecuteBatch() { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
130 |
} |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
131 |
|
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
132 |
@Override |
33
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
133 |
public Configuration getConfiguration() throws ConfigurationException { |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
134 |
if (configuration == null) { |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
135 |
configuration = loadConfiguration(); |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
136 |
} |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
137 |
return configuration; |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
138 |
} |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
139 |
|
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
140 |
private void installDefaultConfiguration() throws ConfigurationException { |
33
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
141 |
Constants.DIR.mkdir(); |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
142 |
|
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
143 |
if (Constants.CONFIG_FILE.exists()) { |
55 | 144 |
log.log(Level.FINER, "Config file already exists: {0}", Constants.CONFIG_FILE); |
33
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
145 |
} else { |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
146 |
try { |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
147 |
Functions.installResource(Constants.EXAMPLE_CONFIG_FILE, Constants.CONFIG_FILE); |
55 | 148 |
log.log(Level.FINE, "Installing default config file: {0}", Constants.CONFIG_FILE); |
33
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
149 |
} catch (IOException e) { |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
150 |
throw new ConfigurationException("Unable to write example configuration to " + Constants.CONFIG_FILE, e); |
33
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
151 |
} |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
152 |
} |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
153 |
} |
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
154 |
|
33
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
155 |
private Configuration loadConfiguration() throws ConfigurationException { |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
156 |
try { |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
157 |
JAXBContext jaxb = JAXBContext.newInstance(Configuration.class); |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
158 |
Unmarshaller u = jaxb.createUnmarshaller(); |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
159 |
return (Configuration) u.unmarshal(Constants.CONFIG_FILE); |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
160 |
} catch (Exception e) { |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
161 |
throw new ConfigurationException("Unable to load configuration from " + Constants.CONFIG_FILE, e); |
04db6ccd6c48
configuration loading from XML
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
162 |
} |
20
e225bdcd260e
refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
163 |
} |
1
f32dac78d13a
WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
164 |
} |