peersim.config
Class ConfigProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<java.lang.Object,java.lang.Object>
          extended by java.util.Properties
              extended by peersim.config.ConfigProperties
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>
Direct Known Subclasses:
ParsedProperties

public class ConfigProperties
extends java.util.Properties

Class for handling configuration files. Extends the functionality of Properties by handling files, system resources and command lines.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
ConfigProperties()
          Calls super constructor.
ConfigProperties(java.util.Properties props)
          Calls super constructor.
ConfigProperties(java.lang.String fileName)
          Constructs a ConfigProperty object by loading a file by calling load(java.lang.String).
ConfigProperties(java.lang.String[] pars)
          Calls ConfigProperties(String[],String) with resource set to null.
ConfigProperties(java.lang.String[] pars, java.lang.String resource)
          Constructs a ConfigProperty object from a parameter list.
 
Method Summary
 void load(java.lang.String fileName)
          Loads given file.
 void loadPropertyString(java.lang.String prop)
          Appends a property defined in the given string.
 void loadSystemResource(java.lang.String n)
          Adds the properties from the given property file.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
 
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

ConfigProperties

public ConfigProperties()
Calls super constructor.


ConfigProperties

public ConfigProperties(java.lang.String[] pars,
                        java.lang.String resource)
Constructs a ConfigProperty object from a parameter list. The algorithm is as follows: first resource is used to attempt loading default values from the given system resource. Then all Strings in pars are processed in the order they appear in the array. For pars[i], first a property file with the name pars[i] is attempted to be loaded. If the file does not exist or loading produces any other IOException, pars[i] is interpreted as a property definition, and it is set.

A little inconvenience is that if pars[i] is supposed to be a command line argument, but it is a valid filename at the same time by accident, the algorithm will process it as a file instead of a command line argument. The caller must take care of that.

No exceptions are thrown, instead error messages are written to the standard error. Users who want a finer control should use the public methods of this class.

Parameters:
pars - The (probably command line) parameter list.
resource - The name of the system resource that contains the defaults. null if there isn't any.

ConfigProperties

public ConfigProperties(java.lang.String fileName)
                 throws java.io.IOException
Constructs a ConfigProperty object by loading a file by calling load(java.lang.String).

Parameters:
fileName - The name of the configuration file.
Throws:
java.io.IOException

ConfigProperties

public ConfigProperties(java.util.Properties props)
Calls super constructor.


ConfigProperties

public ConfigProperties(java.lang.String[] pars)
Calls ConfigProperties(String[],String) with resource set to null.

Method Detail

load

public void load(java.lang.String fileName)
          throws java.io.IOException
Loads given file. Calls Properties.load with a file input stream to the given file.

Throws:
java.io.IOException

loadSystemResource

public void loadSystemResource(java.lang.String n)
                        throws java.io.IOException
Adds the properties from the given property file. Searches in the class path for the file with the given name.

Throws:
java.io.IOException

loadPropertyString

public void loadPropertyString(java.lang.String prop)
                        throws java.io.IOException
Appends a property defined in the given string. The string is considered as a property file line. It is converted to a byte array according to the default character encoding and then loaded by the Properties.load method. This means that the ISO-8859-1 (or compatible) encoding is assumed.

Throws:
java.io.IOException