KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jester > RealConfiguration


1 package jester;
2
3 import java.io.*;
4 import java.util.Properties JavaDoc;
5
6 public class RealConfiguration implements Configuration {
7     public static final String JavaDoc DEFAULT_CONFIGURATION_FILENAME = "jester.cfg";
8
9     private Logger myLogger = new RealLogger();
10     private Properties JavaDoc myProperties;
11     
12     public RealConfiguration(String JavaDoc configFileName, PrintStream errorStream) throws IOException {
13         super();
14         myProperties = new Properties JavaDoc();
15         InputStream configPropertyFile = ClassLoader.getSystemResourceAsStream(configFileName);
16         if (configPropertyFile == null) {
17             configPropertyFile = getClass().getResourceAsStream(configFileName);
18         }
19         if (configPropertyFile != null) {
20             myProperties.load(configPropertyFile);
21         }else{
22             errorStream.println("Warning - could not find "+DEFAULT_CONFIGURATION_FILENAME+" so using default configuration values.");
23         }
24     }
25     
26     public RealConfiguration(String JavaDoc configFileName) throws IOException {
27         this(configFileName, System.err);
28     }
29     
30     public String JavaDoc compilationCommand() {
31         return stringProperty("compilationCommand", "javac");
32     }
33     private boolean isTrue(String JavaDoc value) {
34         return value.toLowerCase().equals("true");
35     }
36     private boolean isTrueProperty(String JavaDoc propertyName, boolean defaultValue) {
37         String JavaDoc propertyValue = myProperties.getProperty(propertyName);
38         if(propertyValue==null){
39             return defaultValue;
40         }
41         return isTrue(propertyValue);
42     }
43     public boolean shouldReportEagerly() {
44         return isTrueProperty("shouldReportEagerly", false);
45     }
46     public String JavaDoc sourceFileExtension() {
47         return stringProperty("sourceFileExtension", ".java");
48     }
49     private String JavaDoc stringProperty(String JavaDoc propertyName, String JavaDoc defaultValue) {
50         String JavaDoc result = myProperties.getProperty(propertyName);
51         if (result == null) {
52             return defaultValue;
53         }
54         return result;
55     }
56     public String JavaDoc testRunningCommand() {
57         return stringProperty("testRunningCommand", "java jester.TestRunnerImpl");
58     }
59     public String JavaDoc testsPassString() {
60         return stringProperty("testsPassString", "PASSED");
61     }
62     public Logger getLogger() {
63         return myLogger;
64     }
65     public String JavaDoc xmlReportFileName() {
66         return stringProperty("xmlReportFileName", "jesterReport.xml");
67     }
68     
69     public boolean closeUIOnFinish() {
70         return isTrueProperty("closeUIOnFinish", true);
71     }
72 }
Popular Tags