Statistics
| Revision:

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

History | View | Annotate | Download (2.47 KB)

1
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.IOException;
7

    
8
/**
9
 * Description: Loads the configuration files
10
 *
11
 * @author  Laura Diaz
12
 * @version 1.0 
13
 */
14
public class PropertyManager
15
{
16
 public final static String LOGGER_PROPERTIES = "org/gvsig/remoteClient/conf/logger.properties";
17
 
18
 //The property file names to load
19
 private final static String[] s_propertyFileNames = new String[]{LOGGER_PROPERTIES};
20
                                                                                                                                         
21

    
22
 //Hashtable containing all properties objects that are loaded
23
 private static Hashtable s_propertyFiles = null;
24

    
25
 /**
26
 * Gets a properties object
27
 * If the the property files are not yet loaded, then loads them first
28
 *
29
 * @param propertyFileName, String
30
 * @return Properties
31
 * @throws java.io.IOException
32
 */
33
 public static Properties getProperties(String propertyFileName) throws IOException
34
 {
35
   if (s_propertyFiles == null)
36
   {
37
     loadProperties();
38
   }
39

    
40
   return (Properties)s_propertyFiles.get(propertyFileName);
41
 }
42

    
43
 //Loads the property files
44
 private static synchronized void loadProperties() throws IOException
45
 {
46
   s_propertyFiles = new Hashtable(s_propertyFileNames.length);
47
   ClassLoader loader = PropertyManager.class.getClassLoader();
48

    
49
   for (int i = 0; i < s_propertyFileNames.length; i++)
50
   {
51
     try
52
     {
53
       InputStream input = loader.getResourceAsStream(s_propertyFileNames[i]);
54
       Properties props = new Properties();
55
       props.load(input);
56
       s_propertyFiles.put(s_propertyFileNames[i], props);
57
     }
58
     catch(Exception e)
59
     {
60
             System.err.println("\n[PropertyManager] ERROR - Failed to read properties file \""
61
                          + s_propertyFileNames[i] + "\": "
62
                          + e.getMessage());       
63
     }
64
   }
65
 }
66
 
67
 //Loads the property files
68
 /*
69
 public static synchronized void saveProperties(String propsName) throws IOException
70
 {  
71
     try
72
     {         
73
          //ClassLoader loader = PropertyManager.class.getClassLoader();              
74
          //InputStream input = loader.getResourceAsStream(propsName);                          
75
           FileOutputStream output = new FileOutputStream(propsName);
76
           Properties props = new Properties();
77
           props.store(output, propsName);
78
           output.close();            
79
     }
80
     catch(Exception e)
81
     {
82
             System.err.println("\n[PropertyManager] ERROR - Failed to save properties file \""
83
                          + propsName + "\": "
84
                          + e.getMessage());       
85
     }
86
 }
87
*/
88
 
89
 
90
}