KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > control > AbstractDBConfig


1 /**
2  * com.mckoi.database.control.AbstractDBConfig 29 Mar 2002
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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  */

24
25 package com.mckoi.database.control;
26
27 import java.io.File JavaDoc;
28 import java.util.Hashtable JavaDoc;
29
30 /**
31  * An abstract implementation of DBConfig.
32  *
33  * @author Tobias Downer
34  */

35
36 public class AbstractDBConfig implements DBConfig {
37
38   /**
39    * The current base path of the database configuration.
40    */

41   private File JavaDoc current_path;
42
43   /**
44    * The Hashtable mapping from configuration key to value for the key.
45    */

46   private Hashtable JavaDoc key_map;
47
48   /**
49    * Constructs the DBConfig.
50    */

51   public AbstractDBConfig(File JavaDoc current_path) {
52     this.current_path = current_path;
53     this.key_map = new Hashtable JavaDoc();
54   }
55
56   /**
57    * Returns the default value for the configuration property with the given
58    * key.
59    */

60   protected String JavaDoc getDefaultValue(String JavaDoc property_key) {
61     // This abstract implementation returns null for all default keys.
62
return null;
63   }
64
65   /**
66    * Sets the configuration value for the key property key.
67    */

68   protected void setValue(String JavaDoc property_key, String JavaDoc val) {
69     key_map.put(property_key, val);
70   }
71
72   // ---------- Implemented from DBConfig ----------
73

74   public File JavaDoc currentPath() {
75     return current_path;
76   }
77
78   public String JavaDoc getValue(String JavaDoc property_key) {
79     // If the key is in the map, return it here
80
String JavaDoc val = (String JavaDoc) key_map.get(property_key);
81     if (val == null) {
82       return getDefaultValue(property_key);
83     }
84     return val;
85   }
86
87   public DBConfig immutableCopy() {
88     AbstractDBConfig immutable_copy = new AbstractDBConfig(current_path);
89     immutable_copy.key_map = (Hashtable JavaDoc) key_map.clone();
90     return immutable_copy;
91   }
92
93 }
94
Popular Tags