KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > perf > Configuration


1 package perf;
2
3 import java.io.InputStream JavaDoc;
4 import java.util.Properties JavaDoc;
5
6
7 /**
8  * Class Configuration.
9  *
10  * @author Mika Riekkinen
11  */

12 class Configuration {
13     private String JavaDoc resource;
14
15     Configuration() {
16         this.resource = "/jiapi.properties";
17     }
18
19     Configuration(String JavaDoc resource) {
20         this.resource = resource;
21     }
22
23
24     boolean getBoolean(String JavaDoc key) {
25         if (key == null) {
26             return false;
27         }
28
29         Properties JavaDoc p = getProperties(resource);
30         String JavaDoc s = p.getProperty(key);
31
32         boolean b = false;
33         try {
34             b = Boolean.valueOf(s).booleanValue();
35         }
36         catch(Exception JavaDoc e) {
37         }
38         
39         return b;
40     }
41
42
43     private Properties JavaDoc getProperties(String JavaDoc name) {
44         Properties JavaDoc properties = new Properties JavaDoc();
45
46         try {
47             InputStream JavaDoc is = getClass().getResourceAsStream(name);
48             if (is != null) {
49                 properties.load(is);
50             }
51             else {
52                 System.out.println("Could not find resource: " + name);
53             }
54         }
55         catch (Exception JavaDoc e) {
56             System.out.println("Failed to get property file " + name +
57                                ", " + e);
58         }
59
60         return properties;
61     }
62 }
63
Popular Tags