KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > configuration > xml > XMLConfiguration


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * XMLConfiguration.java
20  *
21  * The class containing the configuration information for a specific class.
22  */

23
24 // package
25
package com.rift.coad.lib.configuration.xml;
26
27 // java imports
28
import java.util.Map JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Set JavaDoc;
31
32 // coadunation imports
33
import com.rift.coad.lib.configuration.Configuration;
34 import com.rift.coad.lib.configuration.ConfigurationException;
35
36 /**
37  * The class containing the configuration information for a specific class.
38  *
39  * @author Brett Chaldecott
40  */

41 public class XMLConfiguration implements Configuration {
42     
43     // the classes member varialbes
44
private String JavaDoc className = null;
45     private Map JavaDoc entries = null;
46     
47     /**
48      * Creates a new instance of XMLConfiguration
49      *
50      * @param className The name of the class.
51      */

52     public XMLConfiguration(String JavaDoc className) {
53         this.className = className;
54         this.entries = new HashMap JavaDoc();
55     }
56     
57     
58     /**
59      * This method returns the name of the class.
60      *
61      * @return The string containing the name of the class.
62      */

63     public String JavaDoc getClassName() {
64         return className;
65     }
66     
67     /**
68      * This method returns TRUE if the key supplied is present in the data.
69      *
70      * @return TRUE if the key has been found.
71      * @param key The key to perform the search for.
72      * @exception ConfigurationException
73      */

74     public boolean containsKey(String JavaDoc key) throws ConfigurationException {
75         return entries.containsKey(key);
76     }
77     
78     
79     /**
80      * This method returns the list of keys
81      *
82      * @return The set containing the list of keys.
83      * @exception ConfigurationException
84      */

85     public Set JavaDoc getKeys() throws ConfigurationException {
86         return entries.keySet();
87     }
88     
89     
90     /**
91      * This method returns true if the object is a string.
92      *
93      * @return TRUE if string, FALSE if not.
94      * @param key The key to check the string type of.
95      * @exception ConfigurationException
96      */

97     public boolean isString(String JavaDoc key) throws ConfigurationException {
98         XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key);
99         if (entry == null) {
100             throw new ConfigurationException("The entry [" + key
101                     + "] does not exist");
102         }
103         if (entry.getType().getType() == XMLConfigurationType.STRING_VALUE) {
104             return true;
105         }
106         return false;
107     }
108     
109     
110     /**
111      * The method that returns the string value for the requested key
112      *
113      * @return The string containing the configuration information.
114      * @param key The key to retrieve the value for.
115      * @exception ConfigurationException
116      */

117     public String JavaDoc getString(String JavaDoc key) throws ConfigurationException {
118         XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key);
119         if (entry == null) {
120             throw new ConfigurationException("The entry [" + key
121                     + "] does not exist");
122         }
123         return entry.getStringValue();
124     }
125     
126     
127     /**
128      * The method that returns the string value for the requested key
129      *
130      * @return The string containing the configuration information.
131      * @param key The key to retrieve the value for.
132      * @param defValue The default value.
133      * @exception ConfigurationException
134      */

135     public String JavaDoc getString(String JavaDoc key,String JavaDoc defValue)
136         throws ConfigurationException {
137         XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key);
138         if (entry == null) {
139             return defValue;
140         }
141         return entry.getStringValue();
142     }
143     
144     
145     /**
146      * This method set the configuration value for the key.
147      *
148      * @param key The key to set the value for.
149      * @param value The new value to set.
150      * @exception ConfigurationException
151      */

152     public void setString(String JavaDoc key, String JavaDoc value)
153         throws ConfigurationException {
154         throw new ConfigurationException("Not Implemented");
155     }
156     
157     
158     /**
159      * This method returns true if the object is a long.
160      *
161      * @return TRUE if long, FALSE if not.
162      * @param key The key to check the long type of.
163      * @exception ConfigurationException
164      */

165     public boolean isLong(String JavaDoc key) throws ConfigurationException {
166         XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key);
167         if (entry == null) {
168             throw new ConfigurationException("The entry [" + key
169                     + "] does not exist");
170         }
171         if (entry.getType().getType() == XMLConfigurationType.LONG_VALUE) {
172             return true;
173         }
174         return false;
175     }
176     
177     
178     /**
179      * The method that will retrieve the long value from the configuration file.
180      *
181      * @return The long value.
182      * @param key identifying the long value.
183      * @exception ConfigurationException
184      */

185     public long getLong(String JavaDoc key) throws ConfigurationException {
186         XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key);
187         if (entry == null) {
188             throw new ConfigurationException("The entry [" + key
189                     + "] does not exist");
190         }
191         return entry.getLongValue();
192     }
193     
194     
195     /**
196      * The method that will retrieve the long value from the configuration file.
197      *
198      * @return The long value.
199      * @param key identifying the long value.
200      * @param defValue The default long value.
201      * @exception ConfigurationException
202      */

203     public long getLong(String JavaDoc key,long defValue) throws ConfigurationException {
204         XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key);
205         if (entry == null) {
206             return defValue;
207         }
208         return entry.getLongValue();
209     }
210     
211     
212     /**
213      * The method to set a configuration key value.
214      *
215      * @param key The key to set the value for.
216      * @param value The value for the key.
217      * @exception ConfigurationException
218      */

219     public void setLong(String JavaDoc key,long value) throws ConfigurationException {
220         throw new ConfigurationException("Not Implemented");
221     }
222     
223     
224     /**
225      * This method returns true if the object is a boolean.
226      *
227      * @return TRUE if long, FALSE if not.
228      * @param key The key to check the long type of.
229      * @exception ConfigurationException
230      */

231     public boolean isBoolean(String JavaDoc key) throws ConfigurationException {
232         XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key);
233         if (entry == null) {
234             throw new ConfigurationException("The entry [" + key
235                     + "] does not exist");
236         }
237         if (entry.getType().getType() == XMLConfigurationType.BOOLEAN_VALUE) {
238             return true;
239         }
240         return false;
241     }
242     
243     
244     /**
245      * The method that will retrieve the boolean value from the configuration.
246      *
247      * @return TRUE of FALSE
248      * @param key identifying the boolean value.
249      * @exception ConfigurationException
250      */

251     public boolean getBoolean(String JavaDoc key) throws ConfigurationException {
252         XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key);
253         if (entry == null) {
254             throw new ConfigurationException("The entry [" + key
255                     + "] does not exist");
256         }
257         return entry.getBooleanValue();
258     }
259     
260     
261     /**
262      * The method that will retrieve the boolean value from the configuration.
263      *
264      * @return The boolean value.
265      * @param key identifying the boolean value.
266      * @param defValue The default boolean value.
267      * @exception ConfigurationException
268      */

269     public boolean getBoolean(String JavaDoc key,boolean defValue) throws
270             ConfigurationException {
271         XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key);
272         if (entry == null) {
273             return defValue;
274         }
275         return entry.getBooleanValue();
276     }
277     
278     
279     /**
280      * The method to set a configuration key value.
281      *
282      * @param key The key to set the value for.
283      * @param value The value for the key.
284      * @exception ConfigurationException
285      */

286     public void setBoolean(String JavaDoc key,boolean value) throws
287             ConfigurationException {
288         throw new ConfigurationException("Not implemented");
289     }
290     
291     
292     /**
293      * This method will save the configuration information.
294      *
295      * @exception ConfigurationException
296      */

297     public void saveConfiguration() throws ConfigurationException {
298         throw new ConfigurationException("Not Implemented");
299     }
300     
301     
302     /**
303      * This method adds the configuration entry to the list.
304      *
305      * @param entry The entry to add to the configuration list.
306      */

307     public void addConfigurationEntry(XMLConfigurationEntry entry){
308         entries.put(entry.getKey(),entry);
309     }
310 }
311
Popular Tags