java/sql-dk/src/info/globalcode/sql/dk/configuration/Loader.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 16 May 2015 21:42:52 +0200
branchv_0
changeset 189 f4d879cbcee1
parent 179 java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java@236332caeb29
child 192 a32bfcbdee51
permissions -rw-r--r--
separate configuration loading into the Loader class
franta-hg@16
     1
/**
franta-hg@16
     2
 * SQL-DK
franta-hg@189
     3
 * Copyright © 2015 František Kučera (frantovo.cz)
franta-hg@16
     4
 *
franta-hg@16
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@16
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@16
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@16
     8
 * (at your option) any later version.
franta-hg@16
     9
 *
franta-hg@16
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@16
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@16
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@16
    13
 * GNU General Public License for more details.
franta-hg@16
    14
 *
franta-hg@16
    15
 * You should have received a copy of the GNU General Public License
franta-hg@16
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@16
    17
 */
franta-hg@189
    18
package info.globalcode.sql.dk.configuration;
franta-hg@1
    19
franta-hg@189
    20
import info.globalcode.sql.dk.*;
franta-hg@33
    21
import javax.xml.bind.JAXBContext;
franta-hg@33
    22
import javax.xml.bind.Unmarshaller;
franta-hg@13
    23
franta-hg@1
    24
/**
franta-hg@189
    25
 * Configuration loader – deserializes Configuration from the XML file.
franta-hg@1
    26
 *
franta-hg@1
    27
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@1
    28
 */
franta-hg@189
    29
public class Loader {
franta-hg@1
    30
franta-hg@189
    31
	public Configuration loadConfiguration() throws ConfigurationException {
franta-hg@33
    32
		try {
franta-hg@33
    33
			JAXBContext jaxb = JAXBContext.newInstance(Configuration.class);
franta-hg@33
    34
			Unmarshaller u = jaxb.createUnmarshaller();
franta-hg@33
    35
			return (Configuration) u.unmarshal(Constants.CONFIG_FILE);
franta-hg@33
    36
		} catch (Exception e) {
franta-hg@33
    37
			throw new ConfigurationException("Unable to load configuration from " + Constants.CONFIG_FILE, e);
franta-hg@33
    38
		}
franta-hg@20
    39
	}
franta-hg@80
    40
franta-hg@1
    41
}