KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > PropertiesConfigManager


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 /******************************** Package */
7 package com.raptus.owxv3;
8
9 /******************************** Imports */
10 import java.util.*;
11
12 /******************************** Raptus-Header */
13 /**
14  * This is a specialised ConfigManager which handles properties-files, which are
15  * used by default. This class reads in the properties-file and maps it to an
16  * OWX-config-object. The filename is handed over through a Hashtable given to
17  * the initialize-method. The filename-key is constructed of the PARAM_PREFIX ow
18  * the ConfigManager-class plus the name in the constant below.
19  *
20  * @see com.raptus.owxv3.ConfigManagerIFace ConfigManagerIFace
21  * @see com.raptus.owxv3.ConfigManager ConfigManager
22  *
23  * <hr>
24  * <table width="100%" border="0">
25  * <tr>
26  * <td width="24%"><b>Filename</b></td><td width="76%">ConfigManagerIFace.java</td>
27  * </tr>
28  * <tr>
29  * <td width="24%"><b>Author</b></td><td width="76%">Pascal Mainini (pmainini@raptus.com)</td>
30  * </tr>
31  * <tr>
32  * <td width="24%"><b>Date</b></td><td width="76%">27th of March 2001</td>
33  * </tr>
34  * </table>
35  * <hr>
36  * <table width="100%" border="0">
37  * <tr>
38  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
39  * </tr>
40  * <tr>
41  * <td width="24%">2001-03-27/pm</td><td width="76%">created</td>
42  * </tr>
43  * </table>
44  * <hr>
45  */

46 public class PropertiesConfigManager extends Object JavaDoc implements ConfigManagerIFace
47 {
48
49 /******************************** Constants */
50     /**
51      * This constant specifies the prefix which identifies a key in the
52      * servlet-params-hash belonging to this class.
53      *
54      * <b>Change this only if you know exactly why!</b>
55      */

56     public static final String JavaDoc PARAM_PREFIX = "PropertiesConfigManager.";
57
58     /**
59      * This key is used when retrieving the filename of the file to open.
60      *
61      * <b>Change this only if you know exactly why!</b>
62      */

63     protected static final String JavaDoc FILENAME_KEY = "FileName";
64
65
66 /******************************** Members */
67     /**
68      * This holds the filename of the properties-file
69      */

70     protected String JavaDoc myFileName;
71
72     /**
73      * This is an instance of the Configuration-object to which the properties-file
74      * is mapped.
75      */

76     protected Configuration myConfiguration;
77
78
79
80 /******************************** Constructors */
81     /**
82      * The default constructor just does nothing....
83      */

84     public PropertiesConfigManager()
85     {
86     }
87
88
89 /******************************** Methods */
90     /**
91      * @see com.raptus.owxv3.ConfigManagerIFace#initialize(Hashtable hash) Definition
92      */

93     public boolean initialize(Hashtable hash)
94     {
95         myFileName = (String JavaDoc) hash.get(ConfigManager.PARAM_PREFIX + PARAM_PREFIX + FILENAME_KEY);
96         return load();
97     }
98
99     /**
100      * @see com.raptus.owxv3.ConfigManagerIFace#refresh() Definition
101      */

102     public void refresh()
103     {
104         load();
105     }
106
107     /**
108      * @see com.raptus.owxv3.ConfigManagerIFace#saveConfiguration() Definition
109      */

110     public boolean saveConfiguration(Configuration cfg)
111     {
112         PropertiesFile pf = new PropertiesFile(myFileName);
113         if(!pf.load())
114             return false;
115
116         pf.setPropertiesHash(myConfiguration.getConfigHash());
117
118         if(!pf.store())
119             return false;
120
121         return true;
122     }
123
124     /**
125      * @see com.raptus.owxv3.ConfigManagerIFace#getConfiguration() Definition
126      */

127     public Configuration getConfiguration()
128     {
129         return myConfiguration;
130     }
131
132     /**
133      * This initialises the myConfiguration-member whith the properties from
134      * the file specified in myFileName
135      *
136      * @return true if successful, false if not...
137      */

138     public boolean load()
139     {
140         PropertiesFile pf = new PropertiesFile(myFileName);
141         if(pf.load())
142         {
143             myConfiguration = new Configuration(pf.getPropertiesHash());
144             return true;
145         }
146
147         return false;
148     }
149 }
150
Popular Tags