KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > polepos > framework > Settings


1 /*
2 This file is part of the PolePosition database benchmark
3 http://www.polepos.org
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 MA 02111-1307, USA. */

19
20 package org.polepos.framework;
21
22 public class Settings {
23
24     protected final static String JavaDoc KEY_CONNECTURL = "connecturl";
25     protected final static String JavaDoc KEY_DESCRIPTION = "description";
26     protected final static String JavaDoc KEY_DRIVERCLASS = "driverclass";
27     protected final static String JavaDoc KEY_FACTORY = "factory";
28     protected final static String JavaDoc KEY_PASSWORD = "password";
29     protected final static String JavaDoc KEY_URL = "url";
30     protected final static String JavaDoc KEY_USER = "user";
31     protected final static String JavaDoc KEY_HIBERNATE = "hibernate";
32     protected final static String JavaDoc KEY_JDBC = "jdbc";
33     protected final static String JavaDoc KEY_JDO = "jdo";
34     protected final static String JavaDoc KEY_NAME = "name";
35     protected final static String JavaDoc KEY_WEBSITE = "website";
36
37     protected final PropertiesHandler mProperties;
38
39     private final String JavaDoc mFile;
40
41     public Settings(String JavaDoc file) {
42         mFile = file;
43         mProperties = new PropertiesHandler(file);
44     }
45
46     /**
47      * Persist the custom settings.
48      */

49     public boolean save() {
50         return mProperties.save();
51     }
52
53     public String JavaDoc get(String JavaDoc key) {
54         return mProperties.get(key);
55     }
56
57     public String JavaDoc get(String JavaDoc key, String JavaDoc defaultValue) {
58         return mProperties.get(key, defaultValue);
59     }
60
61     public void put(String JavaDoc key, String JavaDoc value) {
62         mProperties.put(key, value);
63     }
64
65     protected String JavaDoc[] getArray(String JavaDoc key) {
66         return mProperties.getArray(key);
67     }
68     
69     public String JavaDoc getFactory(String JavaDoc name) {
70         return get(name + "." + KEY_FACTORY);
71     }
72     
73     public String JavaDoc[] getJdbc(String JavaDoc name){
74         return getArray(name + "." + KEY_JDBC);
75     }
76
77
78     public String JavaDoc getUsername(String JavaDoc name) {
79         return get(name + "." + KEY_USER);
80     }
81
82
83     public String JavaDoc getPassword(String JavaDoc name) {
84         return get(name + "." + KEY_PASSWORD);
85     }
86     
87     public String JavaDoc getURL(String JavaDoc name) {
88         return get(name + "." + KEY_URL);
89     }
90     
91     public String JavaDoc getDriverClass( String JavaDoc dbtype ){
92         return get( dbtype + "." + KEY_DRIVERCLASS );
93     }
94     
95     public String JavaDoc getHibernateDialect( String JavaDoc dbtype ){
96         return get( dbtype + "." + KEY_HIBERNATE );
97     }
98     
99     public String JavaDoc getConnectUrl( String JavaDoc dbtype ){
100         return get( dbtype + "." + KEY_CONNECTURL );
101     }
102     
103     public String JavaDoc getWebsite( String JavaDoc dbtype ){
104         return get( dbtype + "." + KEY_WEBSITE );
105     }
106     
107     public String JavaDoc getName( String JavaDoc dbtype ){
108         return get( dbtype + "." + KEY_NAME );
109     }
110
111     public String JavaDoc getDescription(String JavaDoc dbtype) {
112         return get( dbtype + "." + KEY_DESCRIPTION );
113     }
114     
115     public boolean getBoolean(String JavaDoc key){
116         String JavaDoc str = get(key);
117         if(str == null || str.length() == 0){
118             return false;
119         }
120         String JavaDoc[] canstartwith = new String JavaDoc[]{
121             "1",
122             "y",
123             "Y",
124             "t",
125             "T"
126         };
127         for( String JavaDoc start : canstartwith){
128             if(str.startsWith(start)){
129                 return true;
130             }
131         }
132         return false;
133     }
134     
135
136
137
138 }
139
Popular Tags