KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > myvietnam > mvncore > configuration > Configuration


1 package net.myvietnam.mvncore.configuration;
2
3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if
22  * any, must include the following acknowledgement:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgement may appear in the software itself,
26  * if and wherever such third-party acknowledgements normally appear.
27  *
28  * 4. The names "The Jakarta Project", "Commons", and "Apache Software
29  * Foundation" must not be used to endorse or promote products derived
30  * from this software without prior written permission. For written
31  * permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache"
34  * nor may "Apache" appear in their names without prior written
35  * permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation. For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  */

56
57 import java.util.Iterator JavaDoc;
58 import java.util.Properties JavaDoc;
59 import java.util.Vector JavaDoc;
60
61 /**
62  * Configuration interface.
63  * The general idea here is to make something that will work like our
64  * extended properties and be compatible with the preferences API if at all
65  * possible.
66  *
67  * @author <a HREF="mailto:jvanzyl@apache.org">Jason van Zyl</a>
68  * @author <a HREF="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
69  * @version $Id: Configuration.java,v 1.3 2004/06/27 01:20:38 skoehler Exp $
70  */

71 public interface Configuration
72 {
73     /**
74      * Create an Configuration object that is a subset
75      * of this one. The new Configuration object contains every key from
76      * the current Configuration that starts with prefix. The prefix is
77      * removed from the keys in the subset.
78      *
79      * @param prefix The prefix used to select the properties.
80      */

81     Configuration subset(String JavaDoc prefix);
82
83     /**
84      * Check if the configuration is empty.
85      *
86      * @return true is the configuration contains no key/value pair, false otherwise
87      */

88     boolean isEmpty();
89
90     /**
91      * Check if the configuration contains the key.
92      *
93      * @return true is the configuration contains a value for this key, false otherwise
94      */

95     boolean containsKey(String JavaDoc key);
96
97     /**
98      * Add a property to the configuration. If it already exists then the value
99      * stated here will be added to the configuration entry. For example, if
100      *
101      * resource.loader = file
102      *
103      * is already present in the configuration and you
104      *
105      * addProperty("resource.loader", "classpath")
106      *
107      * Then you will end up with a Vector like the following:
108      *
109      * ["file", "classpath"]
110      *
111      * @param key The Key to add the property to.
112      * @param value The Value to add.
113      */

114     void addProperty(String JavaDoc key, Object JavaDoc value);
115
116     /**
117      * Set a property, this will replace any previously
118      * set values. Set values is implicitly a call
119      * to clearProperty(key), addProperty(key,value).
120      *
121      * @param key The key of the property to change
122      * @param value The new value
123      */

124     void setProperty(String JavaDoc key, Object JavaDoc value);
125
126     /**
127      * Clear a property in the configuration.
128      *
129      * @param key the key to remove along with corresponding value.
130      */

131     void clearProperty(String JavaDoc key);
132
133     /**
134      * Gets a property from the configuration.
135      *
136      * @param key property to retrieve
137      * @return value as object. Will return user value if exists,
138      * if not then default value if exists, otherwise null
139      */

140     Object JavaDoc getProperty(String JavaDoc key);
141
142     /**
143      * Get the list of the keys contained in the configuration
144      * repository that match the specified prefix.
145      *
146      * @param prefix The prefix to test against.
147      * @return An Iterator of keys that match the prefix.
148      */

149     Iterator JavaDoc getKeys(String JavaDoc prefix);
150
151     /**
152      * Get the list of the keys contained in the configuration
153      * repository.
154      *
155      * @return An Iterator.
156      */

157     Iterator JavaDoc getKeys();
158
159     /**
160      * Get a list of properties associated with the given
161      * configuration key.
162      *
163      * @param key The configuration key.
164      * @return The associated properties if key is found.
165      * @exception ClassCastException is thrown if the key maps to an
166      * object that is not a String/Vector.
167      * @exception IllegalArgumentException if one of the tokens is
168      * malformed (does not contain an equals sign).
169      */

170     Properties JavaDoc getProperties(String JavaDoc key);
171
172     // We probably want to at least try to be compatible with
173
// the new preferences API.
174

175     /**
176      * Get a boolean associated with the given configuration key.
177      *
178      * @param key The configuration key.
179      * @return The associated boolean.
180      * @exception java.util.NoSuchElementException is thrown if the key doesn't
181      * map to an existing object.
182      * @exception ClassCastException is thrown if the key maps to an
183      * object that is not a Boolean.
184      */

185     boolean getBoolean(String JavaDoc key);
186
187     /**
188      * Get a boolean associated with the given configuration key.
189      *
190      * @param key The configuration key.
191      * @param defaultValue The default value.
192      * @return The associated boolean.
193      * @exception ClassCastException is thrown if the key maps to an
194      * object that is not a Boolean.
195      */

196     boolean getBoolean(String JavaDoc key, boolean defaultValue);
197
198     /**
199      * Get a boolean associated with the given configuration key.
200      *
201      * @param key The configuration key.
202      * @param defaultValue The default value.
203      * @return The associated boolean if key is found and has valid
204      * format, default value otherwise.
205      * @exception ClassCastException is thrown if the key maps to an
206      * object that is not a Boolean.
207      */

208     Boolean JavaDoc getBoolean(String JavaDoc key, Boolean JavaDoc defaultValue);
209
210     /**
211      * Get a byte associated with the given configuration key.
212      *
213      * @param key The configuration key.
214      * @return The associated byte.
215      * @exception java.util.NoSuchElementException is thrown if the key doesn't
216      * map to an existing object.
217      * @exception ClassCastException is thrown if the key maps to an
218      * object that is not a Byte.
219      * @exception NumberFormatException is thrown if the value mapped
220      * by the key has not a valid number format.
221      */

222     byte getByte(String JavaDoc key);
223
224     /**
225      * Get a byte associated with the given configuration key.
226      *
227      * @param key The configuration key.
228      * @param defaultValue The default value.
229      * @return The associated byte.
230      * @exception ClassCastException is thrown if the key maps to an
231      * object that is not a Byte.
232      * @exception NumberFormatException is thrown if the value mapped
233      * by the key has not a valid number format.
234      */

235     byte getByte(String JavaDoc key, byte defaultValue);
236
237     /**
238      * Get a byte associated with the given configuration key.
239      *
240      * @param key The configuration key.
241      * @param defaultValue The default value.
242      * @return The associated byte if key is found and has valid format, default
243      * value otherwise.
244      * @exception ClassCastException is thrown if the key maps to an object that
245      * is not a Byte.
246      * @exception NumberFormatException is thrown if the value mapped by the key
247      * has not a valid number format.
248      */

249     Byte JavaDoc getByte(String JavaDoc key, Byte JavaDoc defaultValue);
250
251     /**
252      * Get a double associated with the given configuration key.
253      *
254      * @param key The configuration key.
255      * @return The associated double.
256      * @exception java.util.NoSuchElementException is thrown if the key doesn't
257      * map to an existing object.
258      * @exception ClassCastException is thrown if the key maps to an
259      * object that is not a Double.
260      * @exception NumberFormatException is thrown if the value mapped
261      * by the key has not a valid number format.
262      */

263     double getDouble(String JavaDoc key);
264
265     /**
266      * Get a double associated with the given configuration key.
267      *
268      * @param key The configuration key.
269      * @param defaultValue The default value.
270      * @return The associated double.
271      * @exception ClassCastException is thrown if the key maps to an
272      * object that is not a Double.
273      * @exception NumberFormatException is thrown if the value mapped
274      * by the key has not a valid number format.
275      */

276     double getDouble(String JavaDoc key, double defaultValue);
277
278     /**
279      * Get a double associated with the given configuration key.
280      *
281      * @param key The configuration key.
282      * @param defaultValue The default value.
283      * @return The associated double if key is found and has valid
284      * format, default value otherwise.
285      * @exception ClassCastException is thrown if the key maps to an
286      * object that is not a Double.
287      * @exception NumberFormatException is thrown if the value mapped
288      * by the key has not a valid number format.
289      */

290     Double JavaDoc getDouble(String JavaDoc key, Double JavaDoc defaultValue);
291
292     /**
293      * Get a float associated with the given configuration key.
294      *
295      * @param key The configuration key.
296      * @return The associated float.
297      * @exception java.util.NoSuchElementException is thrown if the key doesn't
298      * map to an existing object.
299      * @exception ClassCastException is thrown if the key maps to an
300      * object that is not a Float.
301      * @exception NumberFormatException is thrown if the value mapped
302      * by the key has not a valid number format.
303      */

304     float getFloat(String JavaDoc key);
305
306     /**
307      * Get a float associated with the given configuration key.
308      *
309      * @param key The configuration key.
310      * @param defaultValue The default value.
311      * @return The associated float.
312      * @exception ClassCastException is thrown if the key maps to an
313      * object that is not a Float.
314      * @exception NumberFormatException is thrown if the value mapped
315      * by the key has not a valid number format.
316      */

317     float getFloat(String JavaDoc key, float defaultValue);
318
319     /**
320      * Get a float associated with the given configuration key.
321      *
322      * @param key The configuration key.
323      * @param defaultValue The default value.
324      * @return The associated float if key is found and has valid
325      * format, default value otherwise.
326      * @exception ClassCastException is thrown if the key maps to an
327      * object that is not a Float.
328      * @exception NumberFormatException is thrown if the value mapped
329      * by the key has not a valid number format.
330      */

331     Float JavaDoc getFloat(String JavaDoc key, Float JavaDoc defaultValue);
332
333     /**
334      * Get a int associated with the given configuration key.
335      *
336      * @param key The configuration key.
337      * @return The associated int.
338      * @exception java.util.NoSuchElementException is thrown if the key doesn't
339      * map to an existing object.
340      * @exception ClassCastException is thrown if the key maps to an
341      * object that is not a Integer.
342      * @exception NumberFormatException is thrown if the value mapped
343      * by the key has not a valid number format.
344      */

345     int getInt(String JavaDoc key);
346
347     /**
348      * Get a int associated with the given configuration key.
349      *
350      * @param key The configuration key.
351      * @param defaultValue The default value.
352      * @return The associated int.
353      * @exception ClassCastException is thrown if the key maps to an
354      * object that is not a Integer.
355      * @exception NumberFormatException is thrown if the value mapped
356      * by the key has not a valid number format.
357      */

358     int getInt(String JavaDoc key, int defaultValue);
359
360     /**
361      * Get a int associated with the given configuration key.
362      *
363      * @param key The configuration key.
364      * @param defaultValue The default value.
365      * @return The associated int if key is found and has valid format, default
366      * value otherwise.
367      * @exception ClassCastException is thrown if the key maps to an object that
368      * is not a Integer.
369      * @exception NumberFormatException is thrown if the value mapped by the key
370      * has not a valid number format.
371      */

372     Integer JavaDoc getInteger(String JavaDoc key, Integer JavaDoc defaultValue);
373
374     /**
375      * Get a long associated with the given configuration key.
376      *
377      * @param key The configuration key.
378      * @return The associated long.
379      * @exception java.util.NoSuchElementException is thrown if the key doesn't
380      * map to an existing object.
381      * @exception ClassCastException is thrown if the key maps to an
382      * object that is not a Long.
383      * @exception NumberFormatException is thrown if the value mapped
384      * by the key has not a valid number format.
385      */

386     long getLong(String JavaDoc key);
387
388     /**
389      * Get a long associated with the given configuration key.
390      *
391      * @param key The configuration key.
392      * @param defaultValue The default value.
393      * @return The associated long.
394      * @exception ClassCastException is thrown if the key maps to an
395      * object that is not a Long.
396      * @exception NumberFormatException is thrown if the value mapped
397      * by the key has not a valid number format.
398      */

399     long getLong(String JavaDoc key, long defaultValue);
400
401     /**
402      * Get a long associated with the given configuration key.
403      *
404      * @param key The configuration key.
405      * @param defaultValue The default value.
406      * @return The associated long if key is found and has valid
407      * format, default value otherwise.
408      * @exception ClassCastException is thrown if the key maps to an
409      * object that is not a Long.
410      * @exception NumberFormatException is thrown if the value mapped
411      * by the key has not a valid number format.
412      */

413     Long JavaDoc getLong(String JavaDoc key, Long JavaDoc defaultValue);
414
415     /**
416      * Get a short associated with the given configuration key.
417      *
418      * @param key The configuration key.
419      * @return The associated short.
420      * @exception java.util.NoSuchElementException is thrown if the key doesn't
421      * map to an existing object.
422      * @exception ClassCastException is thrown if the key maps to an
423      * object that is not a Short.
424      * @exception NumberFormatException is thrown if the value mapped
425      * by the key has not a valid number format.
426      */

427     short getShort(String JavaDoc key);
428
429     /**
430      * Get a short associated with the given configuration key.
431      *
432      * @param key The configuration key.
433      * @param defaultValue The default value.
434      * @return The associated short.
435      * @exception ClassCastException is thrown if the key maps to an
436      * object that is not a Short.
437      * @exception NumberFormatException is thrown if the value mapped
438      * by the key has not a valid number format.
439      */

440     short getShort(String JavaDoc key, short defaultValue);
441
442     /**
443      * Get a short associated with the given configuration key.
444      *
445      * @param key The configuration key.
446      * @param defaultValue The default value.
447      * @return The associated short if key is found and has valid
448      * format, default value otherwise.
449      * @exception ClassCastException is thrown if the key maps to an
450      * object that is not a Short.
451      * @exception NumberFormatException is thrown if the value mapped
452      * by the key has not a valid number format.
453      * @exception java.util.NoSuchElementException is thrown if the key doesn't
454      * map to an existing object.
455      */

456     Short JavaDoc getShort(String JavaDoc key, Short JavaDoc defaultValue);
457
458     /**
459      * Get a string associated with the given configuration key.
460      *
461      * @param key The configuration key.
462      * @return The associated string.
463      * @exception ClassCastException is thrown if the key maps to an object that
464      * is not a String.
465      * @exception java.util.NoSuchElementException is thrown if the key doesn't
466      * map to an existing object.
467      */

468     String JavaDoc getString(String JavaDoc key);
469
470     /**
471      * Get a string associated with the given configuration key.
472      *
473      * @param key The configuration key.
474      * @param defaultValue The default value.
475      * @return The associated string if key is found and has valid
476      * format, default value otherwise.
477      * @exception ClassCastException is thrown if the key maps to an object that
478      * is not a String.
479      */

480     String JavaDoc getString(String JavaDoc key, String JavaDoc defaultValue);
481
482     /**
483      * Get an array of strings associated with the given configuration
484      * key.
485      *
486      * @param key The configuration key.
487      * @return The associated string array if key is found.
488      * @exception ClassCastException is thrown if the key maps to an
489      * object that is not a String/Vector of Strings.
490      */

491     String JavaDoc[] getStringArray(String JavaDoc key);
492
493     /**
494      * Get a Vector of strings associated with the given configuration key.
495      *
496      * @param key The configuration key.
497      * @return The associated Vector.
498      * @exception ClassCastException is thrown if the key maps to an
499      * object that is not a Vector.
500      */

501     Vector JavaDoc getVector(String JavaDoc key);
502
503     /**
504      * Get a Vector of strings associated with the given configuration key.
505      *
506      * @param key The configuration key.
507      * @param defaultValue The default value.
508      * @return The associated Vector.
509      * @exception ClassCastException is thrown if the key maps to an
510      * object that is not a Vector.
511      */

512     Vector JavaDoc getVector(String JavaDoc key, Vector JavaDoc defaultValue);
513 }
514
Popular Tags