blob: 1ac9039d6d67bc2341c8ae206fad74ee368f7c29 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*
* Oreka -- A media capture and retrieval platform
*
* Copyright (C) 2005, orecx LLC
*
* http://www.orecx.com
*
* This program is free software, distributed under the terms of
* the GNU General Public License.
* Please refer to http://www.gnu.org/copyleft/gpl.html
*
*/
/**
*
*/
package net.sf.oreka.orktrack;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import net.sf.oreka.OrkException;
import net.sf.oreka.serializers.DomSerializer;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
/**
* This singleton class manages all application configuration parameters
*/
public class ConfigManager {
static ConfigManager configManager = null;
Logger log = null;
OrkTrackConfig config = null;
private ConfigManager() {
config = new OrkTrackConfig();
log = LogManager.getInstance().getConfigLogger();
}
public static ConfigManager getInstance()
{
if (configManager == null)
{
configManager = new ConfigManager();
}
return configManager;
}
public void load(String filename) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
File file = new File(filename);
DocumentBuilder builder = factory.newDocumentBuilder();
InputStream is = new FileInputStream(file);
Document doc = builder.parse(is);
DomSerializer ser = new DomSerializer();
config = (OrkTrackConfig)ser.deSerialize(doc.getFirstChild());
}
catch (OrkException e) {
log.error("ConfigManager.load: deserialization error:" + e.getMessage());
}
catch (FileNotFoundException e) {
log.error("ConfigManager.load config file does not exist:" + filename + " check your web.xml");
}
catch (Exception e) {
log.error("ConfigManager.load: exception:" + e.getMessage());
}
}
public OrkTrackConfig getConfig() {
return config;
}
public void setConfig(OrkTrackConfig config) {
this.config = config;
}
}
|