net.spy.util
Class SpyConfig

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<Object,Object>
          extended by java.util.Properties
              extended by net.spy.util.SpyConfig
All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public class SpyConfig
extends Properties

SpyConfig - an abstracted config file maintainer. The current config file format is that of a java Properties file. This class makes it easier to load them, caches them, and gives a good base for extensions that load default config files for projects that are hard to pass config filepaths into.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
SpyConfig()
          Construct a new SpyConfig object without a config file.
SpyConfig(File conffile)
          Construct a new SpyConfig object describing a config file.
 
Method Summary
 String get(String key)
          Get the value for a given config entry.
 String get(String key, String def)
          Get the value for a given config entry, with default.
 int getInt(String key, int def)
          Get an int value for a given config entry.
 boolean loadConfig(File conffile)
          Try to load a config file.
 boolean loadConfig(File[] confFiles)
          Try to load a config file.
 void orput(String key, String value)
          Assign a value to the config only if it doesn't already exist.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, loadFromXML, propertyNames, save, setProperty, store, storeToXML, storeToXML
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpyConfig

public SpyConfig(File conffile)
Construct a new SpyConfig object describing a config file.

Parameters:
conffile - The config file we are describing.

SpyConfig

public SpyConfig()
Construct a new SpyConfig object without a config file.

Method Detail

loadConfig

public boolean loadConfig(File conffile)
Try to load a config file. This function exists primarily for classes that extend SpyConfig and want to have multiple default locations for config files.

Parameters:
conffile - Path to the configuration file to load.
Returns:
true if the config loaded successfully.

loadConfig

public boolean loadConfig(File[] confFiles)
Try to load a config file. This function allows an object to load a config file from a list of files. Only the first file in the list that works is actually loaded.

Parameters:
confFiles - an array of config file paths to attempt to load
Returns:
true if a config file was loaded

get

public String get(String key)
Get the value for a given config entry.

Parameters:
key - which config entry to return.

get

public String get(String key,
                  String def)
Get the value for a given config entry, with default.

Parameters:
key - which config entry to return.
def - default in case the entry doesn't exist.

getInt

public int getInt(String key,
                  int def)
Get an int value for a given config entry. Please note, a default is *required* because undefined ints suck.

Parameters:
key - which config entry to return.
def - default in case the entry doesn't exist.

orput

public void orput(String key,
                  String value)
Assign a value to the config only if it doesn't already exist. Useful for setting defaults.

Parameters:
key - config key
value - config value


Copyright © 1995-2007 SPY Internetworking. All Rights Reserved.