01: /**
02: * com.mckoi.database.control.AbstractDBConfig 29 Mar 2002
03: *
04: * Mckoi SQL Database ( http://www.mckoi.com/database )
05: * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * Version 2 as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License Version 2 for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * Version 2 along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: * Change Log:
21: *
22: *
23: */package com.mckoi.database.control;
24:
25: import java.io.File;
26: import java.util.Hashtable;
27:
28: /**
29: * An abstract implementation of DBConfig.
30: *
31: * @author Tobias Downer
32: */
33:
34: public class AbstractDBConfig implements DBConfig {
35:
36: /**
37: * The current base path of the database configuration.
38: */
39: private File current_path;
40:
41: /**
42: * The Hashtable mapping from configuration key to value for the key.
43: */
44: private Hashtable key_map;
45:
46: /**
47: * Constructs the DBConfig.
48: */
49: public AbstractDBConfig(File current_path) {
50: this .current_path = current_path;
51: this .key_map = new Hashtable();
52: }
53:
54: /**
55: * Returns the default value for the configuration property with the given
56: * key.
57: */
58: protected String getDefaultValue(String property_key) {
59: // This abstract implementation returns null for all default keys.
60: return null;
61: }
62:
63: /**
64: * Sets the configuration value for the key property key.
65: */
66: protected void setValue(String property_key, String val) {
67: key_map.put(property_key, val);
68: }
69:
70: // ---------- Implemented from DBConfig ----------
71:
72: public File currentPath() {
73: return current_path;
74: }
75:
76: public String getValue(String property_key) {
77: // If the key is in the map, return it here
78: String val = (String) key_map.get(property_key);
79: if (val == null) {
80: return getDefaultValue(property_key);
81: }
82: return val;
83: }
84:
85: public DBConfig immutableCopy() {
86: AbstractDBConfig immutable_copy = new AbstractDBConfig(
87: current_path);
88: immutable_copy.key_map = (Hashtable) key_map.clone();
89: return immutable_copy;
90: }
91:
92: }
|