View Javadoc

1   /*
2    * JarInspector - Copyright (C) 2004 Che Inc., Rosario Argentina
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Library General Public
6    * License as published by the Free Software Foundation; either
7    * version 2 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Library General Public License for more details.
13   *
14   * You should have received a copy of the GNU Library General Public
15   * License along with this library; if not, write to the Free
16   * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17   */
18  
19  package inc.che.common.config;
20  
21  // Imports
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 &lt;stevemcmee@users.sourceforge.net&gt;</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       * factorymethod
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 }