001: /*
002: This file is part of the PolePosition database benchmark
003: http://www.polepos.org
004:
005: This program is free software; you can redistribute it and/or
006: modify it under the terms of the GNU General Public License
007: as published by the Free Software Foundation; either version 2
008: of the License, or (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public
016: License along with this program; if not, write to the Free
017: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
018: MA 02111-1307, USA. */
019:
020: package org.polepos.framework;
021:
022: public class Settings {
023:
024: protected final static String KEY_CONNECTURL = "connecturl";
025: protected final static String KEY_DESCRIPTION = "description";
026: protected final static String KEY_DRIVERCLASS = "driverclass";
027: protected final static String KEY_FACTORY = "factory";
028: protected final static String KEY_PASSWORD = "password";
029: protected final static String KEY_URL = "url";
030: protected final static String KEY_USER = "user";
031: protected final static String KEY_HIBERNATE = "hibernate";
032: protected final static String KEY_JDBC = "jdbc";
033: protected final static String KEY_JDO = "jdo";
034: protected final static String KEY_NAME = "name";
035: protected final static String KEY_WEBSITE = "website";
036:
037: protected final PropertiesHandler mProperties;
038:
039: private final String mFile;
040:
041: public Settings(String file) {
042: mFile = file;
043: mProperties = new PropertiesHandler(file);
044: }
045:
046: /**
047: * Persist the custom settings.
048: */
049: public boolean save() {
050: return mProperties.save();
051: }
052:
053: public String get(String key) {
054: return mProperties.get(key);
055: }
056:
057: public String get(String key, String defaultValue) {
058: return mProperties.get(key, defaultValue);
059: }
060:
061: public void put(String key, String value) {
062: mProperties.put(key, value);
063: }
064:
065: protected String[] getArray(String key) {
066: return mProperties.getArray(key);
067: }
068:
069: public String getFactory(String name) {
070: return get(name + "." + KEY_FACTORY);
071: }
072:
073: public String[] getJdbc(String name) {
074: return getArray(name + "." + KEY_JDBC);
075: }
076:
077: public String getUsername(String name) {
078: return get(name + "." + KEY_USER);
079: }
080:
081: public String getPassword(String name) {
082: return get(name + "." + KEY_PASSWORD);
083: }
084:
085: public String getURL(String name) {
086: return get(name + "." + KEY_URL);
087: }
088:
089: public String getDriverClass(String dbtype) {
090: return get(dbtype + "." + KEY_DRIVERCLASS);
091: }
092:
093: public String getHibernateDialect(String dbtype) {
094: return get(dbtype + "." + KEY_HIBERNATE);
095: }
096:
097: public String getConnectUrl(String dbtype) {
098: return get(dbtype + "." + KEY_CONNECTURL);
099: }
100:
101: public String getWebsite(String dbtype) {
102: return get(dbtype + "." + KEY_WEBSITE);
103: }
104:
105: public String getName(String dbtype) {
106: return get(dbtype + "." + KEY_NAME);
107: }
108:
109: public String getDescription(String dbtype) {
110: return get(dbtype + "." + KEY_DESCRIPTION);
111: }
112:
113: public boolean getBoolean(String key) {
114: String str = get(key);
115: if (str == null || str.length() == 0) {
116: return false;
117: }
118: String[] canstartwith = new String[] { "1", "y", "Y", "t", "T" };
119: for (String start : canstartwith) {
120: if (str.startsWith(start)) {
121: return true;
122: }
123: }
124: return false;
125: }
126:
127: }
|