1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package inc.che.common.config;
20
21
22 import inc.che.common.resource.ResourceManager;
23 import inc.che.common.resource.StringResources;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.util.Properties;
28
29 import org.apache.log4j.Logger;
30
31 /***
32 * <b>Klasse zum Laden und Speichern der Konfigurationseinstellungen</b>
33 * @version $Id: ConfigLoader.java,v 1.1 2005/03/06 12:56:50 stevemcmee Exp $
34 * @author <address> Steve McMee <stevemcmee@users.sourceforge.net></address>
35 */
36
37 public abstract class ConfigLoader {
38
39 /*** CVS ID of this file */
40 public static final String CVS_ID =
41 "$Id: ConfigLoader.java,v 1.1 2005/03/06 12:56:50 stevemcmee Exp $";
42
43 /***
44 * logger instance for this class
45 */
46
47 private static Logger log = Logger.getLogger(ConfigLoader.class);
48
49 /***
50 * The ResourceManager
51 */
52 private static ResourceManager resourceManager =
53 ResourceManager.getResourceManager(StringResources.TEXT_RESOURCES);
54
55 /***
56 * loads Properties from a File
57 *@param configFile File holds the properties
58 *@return all properties in configFile
59 */
60 public abstract Properties loadProperties(File configFile)
61 throws IOException;
62
63 /***
64 * stores Properties into a File
65 *@param configFile File holds the properties
66 *@param properties Properties to store
67 */
68 public abstract void storeProperties(
69 File configFile,
70 Properties properties)
71 throws IOException;
72
73
74
75
76
77 public static ConfigLoader createLoader(File confFile) {
78 if (log.isDebugEnabled()) {
79 log.debug("createLoader(" + confFile + ")");
80 }
81 if (confFile == null) {
82 log.error(resourceManager.getText("config_file_null"));
83 throw new RuntimeException(
84 resourceManager.getText("config_file_null"));
85 }
86 String path = confFile.getAbsolutePath();
87 if (path.endsWith(".properties")) {
88 return new PropertyConfigLoader();
89 }
90
91 log.error(
92 resourceManager.getText(
93 "confile_unknown",
94 new String[] {String.valueOf(confFile.getAbsolutePath())}));
95 throw new RuntimeException(
96 resourceManager.getText(
97 "configuration_file",
98 new String[] {confFile.getAbsolutePath()}));
99
100 }
101
102 }