Statistics
| Revision:

root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / utils / PropertyManager.java @ 3323

History | View | Annotate | Download (2.5 KB)

1 3323 ldiaz
package org.gvsig.remoteClient.utils;
2
3
import java.util.Properties;
4
import java.util.Hashtable;
5
import java.io.InputStream;
6
import java.io.FileOutputStream;
7
import java.io.IOException;
8
9
/**
10
 * Description: Loads the configuration files
11
 *
12
 * @author  Laura Diaz
13
 * @version 1.0
14
 */
15
public class PropertyManager
16
{
17
 public final static String LOGGER_PROPERTIES = "org/gvsig/remoteClient/conf/logger.properties";
18
19
 //The property file names to load
20
 private final static String[] s_propertyFileNames = new String[]{LOGGER_PROPERTIES};
21
22
23
 //Hashtable containing all properties objects that are loaded
24
 private static Hashtable s_propertyFiles = null;
25
26
 /**
27
 * Gets a properties object
28
 * If the the property files are not yet loaded, then loads them first
29
 *
30
 * @param propertyFileName, String
31
 * @return Properties
32
 * @throws java.io.IOException
33
 */
34
 public static Properties getProperties(String propertyFileName) throws IOException
35
 {
36
   if (s_propertyFiles == null)
37
   {
38
     loadProperties();
39
   }
40
41
   return (Properties)s_propertyFiles.get(propertyFileName);
42
 }
43
44
 //Loads the property files
45
 private static synchronized void loadProperties() throws IOException
46
 {
47
   s_propertyFiles = new Hashtable(s_propertyFileNames.length);
48
   ClassLoader loader = PropertyManager.class.getClassLoader();
49
50
   for (int i = 0; i < s_propertyFileNames.length; i++)
51
   {
52
     try
53
     {
54
       InputStream input = loader.getResourceAsStream(s_propertyFileNames[i]);
55
       Properties props = new Properties();
56
       props.load(input);
57
       s_propertyFiles.put(s_propertyFileNames[i], props);
58
     }
59
     catch(Exception e)
60
     {
61
             System.err.println("\n[PropertyManager] ERROR - Failed to read properties file \""
62
                          + s_propertyFileNames[i] + "\": "
63
                          + e.getMessage());
64
     }
65
   }
66
 }
67
68
 //Loads the property files
69
 /*
70
 public static synchronized void saveProperties(String propsName) throws IOException
71
 {
72
     try
73
     {
74
          //ClassLoader loader = PropertyManager.class.getClassLoader();
75
          //InputStream input = loader.getResourceAsStream(propsName);
76
           FileOutputStream output = new FileOutputStream(propsName);
77
           Properties props = new Properties();
78
           props.store(output, propsName);
79
           output.close();
80
     }
81
     catch(Exception e)
82
     {
83
             System.err.println("\n[PropertyManager] ERROR - Failed to save properties file \""
84
                          + propsName + "\": "
85
                          + e.getMessage());
86
     }
87
 }
88
*/
89
90
91
}