KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nl > justobjects > pushlet > core > Config


1 // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
2
// Distributable under LGPL license. See terms of license at gnu.org.
3

4 package nl.justobjects.pushlet.core;
5
6 import nl.justobjects.pushlet.util.Log;
7 import nl.justobjects.pushlet.util.Sys;
8
9 import java.util.Properties JavaDoc;
10
11 /**
12  * Loads and maintains overall configuration.
13  *
14  * @version $Id: Config.java,v 1.1 2005/02/18 12:36:47 justb Exp $
15  * @author Just van den Broecke - Just Objects &copy;
16  **/

17 public class Config implements ConfigDefs {
18     private static final String JavaDoc PROPERTIES_RESOURCE = "pushlet.properties";
19     private static Properties JavaDoc properties;
20
21     /**
22      * Initialize event sources from properties file.
23      */

24     public static void load() {
25         // Load Event sources using properties file.
26
Log.info("Config: loading");
27         try {
28             properties = Sys.loadPropertiesResource(PROPERTIES_RESOURCE);
29         } catch (Throwable JavaDoc t) {
30             Log.warn("Config: cannot find properties file: " + PROPERTIES_RESOURCE, t);
31             return;
32         }
33         Log.info("Config: loaded values=" + properties);
34
35     }
36
37     public static String JavaDoc getProperty(String JavaDoc aName) {
38         String JavaDoc value = properties.getProperty(aName);
39         if (value == null) {
40             throw new IllegalArgumentException JavaDoc("Unknown property: " + aName);
41         }
42         return value;
43     }
44
45     public static boolean getBoolProperty(String JavaDoc aName) {
46         String JavaDoc value = getProperty(aName);
47         try {
48             return value.equals("true");
49         } catch (Throwable JavaDoc t) {
50             throw new IllegalArgumentException JavaDoc("Illegal property value: " + aName + " val=" + value);
51         }
52     }
53
54     public static int getIntProperty(String JavaDoc aName) {
55         String JavaDoc value = getProperty(aName);
56         try {
57             return Integer.parseInt(value);
58         } catch (Throwable JavaDoc t) {
59             throw new IllegalArgumentException JavaDoc("Illegal property value: " + aName + " val=" + value);
60         }
61     }
62
63     public static long getLongProperty(String JavaDoc aName) {
64         String JavaDoc value = getProperty(aName);
65         try {
66             return Long.parseLong(value);
67         } catch (Throwable JavaDoc t) {
68             throw new IllegalArgumentException JavaDoc("Illegal property value: " + aName + " val=" + value);
69         }
70     }
71
72     public static boolean hasProperty(String JavaDoc aName) {
73         return properties.containsKey(aName);
74     }
75
76
77 }
78
79 /*
80  * $Log: Config.java,v $
81  * Revision 1.1 2005/02/18 12:36:47 justb
82  * changes for renaming and configurability
83  *
84
85  *
86  */

87
Popular Tags