peersim.config
Class ConfigContainer

java.lang.Object
  extended by peersim.config.ConfigContainer

public class ConfigContainer
extends java.lang.Object

This class is the container for the configuration data used in Configuration; see that class for more information.


Constructor Summary
ConfigContainer(java.util.Properties config, boolean check)
           
 
Method Summary
 boolean contains(java.lang.String name)
           
 boolean getBoolean(java.lang.String name)
          Reads given property.
 boolean getBoolean(java.lang.String name, boolean def)
          Reads given configuration property.
 java.lang.Class getClass(java.lang.String name)
          Reads given configuration property.
 java.lang.Class getClass(java.lang.String name, java.lang.Class def)
          Reads given configuration property.
 double getDouble(java.lang.String name)
          Reads given configuration property.
 double getDouble(java.lang.String name, double def)
          Reads given configuration property.
 java.lang.Object getInstance(java.lang.String name)
          Reads given configuration property for a class name.
 java.lang.Object getInstance(java.lang.String name, java.lang.Object def)
          Reads given configuration property for a class name.
 java.lang.Object[] getInstanceArray(java.lang.String name)
          It returns an array of class instances.
 int getInt(java.lang.String name)
          Reads given configuration property.
 int getInt(java.lang.String name, int def)
          Reads given configuration property.
 long getLong(java.lang.String name)
          Reads given configuration property.
 long getLong(java.lang.String name, long def)
          Reads given configuration property.
 java.lang.String[] getNames(java.lang.String name)
          Returns an array of names prefixed by the specified name.
 int getPid(java.lang.String name)
          Reads the given property from the configuration interpreting it as a protocol name.
 int getPid(java.lang.String name, int pid)
          Calls getPid(String), and returns the default if no property is defined with the given name.
 java.lang.String getString(java.lang.String name)
          Reads given configuration property.
 java.lang.String getString(java.lang.String name, java.lang.String def)
          Reads given configuration property.
 java.lang.String lookupPid(int pid)
          Returns the name of a protocol that has the given identifier.
 int lookupPid(java.lang.String protname)
          Returns the numeric protocol identifier of the given protocol name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigContainer

public ConfigContainer(java.util.Properties config,
                       boolean check)
Method Detail

contains

public boolean contains(java.lang.String name)
Returns:
true if and only if name is a specified (existing) property.

getBoolean

public boolean getBoolean(java.lang.String name,
                          boolean def)
Reads given configuration property. If not found, throws a MissingParameterException.

Parameters:
name - Name of configuration property
def - default value

getBoolean

public boolean getBoolean(java.lang.String name)
Reads given property. If not found, or the value is empty string then throws a MissingParameterException. Empty string is not accepted as false due to the similar function of contains(java.lang.String) which returns true in that case. True is returned if the lowercase value of the property is "true", otherwise false is returned.

Parameters:
name - Name of configuration property

getInt

public int getInt(java.lang.String name,
                  int def)
Reads given configuration property. If not found, returns the default value.

Parameters:
name - Name of configuration property
def - default value

getInt

public int getInt(java.lang.String name)
Reads given configuration property. If not found, throws a MissingParameterException.

Parameters:
name - Name of configuration property

getLong

public long getLong(java.lang.String name,
                    long def)
Reads given configuration property. If not found, returns the default value.

Parameters:
name - Name of configuration property
def - default value

getLong

public long getLong(java.lang.String name)
Reads given configuration property. If not found, throws a MissingParameterException.

Parameters:
name - Name of configuration property

getDouble

public double getDouble(java.lang.String name,
                        double def)
Reads given configuration property. If not found, returns the default value.

Parameters:
name - Name of configuration property
def - default value

getDouble

public double getDouble(java.lang.String name)
Reads given configuration property. If not found, throws a MissingParameterException.

Parameters:
name - Name of configuration property

getString

public java.lang.String getString(java.lang.String name,
                                  java.lang.String def)
Reads given configuration property. If not found, returns the default value.

Parameters:
name - Name of configuration property
def - default value

getString

public java.lang.String getString(java.lang.String name)
Reads given configuration property. If not found, throws a MissingParameterException. Removes trailing whitespace characters.

Parameters:
name - Name of configuration property

getPid

public int getPid(java.lang.String name)
Reads the given property from the configuration interpreting it as a protocol name. Returns the numeric protocol identifier of this protocol name. See the discussion of protocol name at Configuration for details on how this numeric id is calculated

Parameters:
name - Name of configuration property
Returns:
the numeric protocol identifier associated to the value of the property

getPid

public int getPid(java.lang.String name,
                  int pid)
Calls getPid(String), and returns the default if no property is defined with the given name.

Parameters:
name - Name of configuration property
pid - the default protocol identifier
Returns:
the numeric protocol identifier associated to the value of the property, or the default if not defined

lookupPid

public int lookupPid(java.lang.String protname)
Returns the numeric protocol identifier of the given protocol name.

Parameters:
protname - the protocol name.
Returns:
the numeric protocol identifier associated to the protocol name

lookupPid

public java.lang.String lookupPid(int pid)
Returns the name of a protocol that has the given identifier.

Note that this is not a constant time operation in the number of protocols, although typically there are very few protocols defined.

Parameters:
pid - numeric protocol identifier.
Returns:
name of the protocol that has the given id. null if no protocols have the given id.

getClass

public java.lang.Class getClass(java.lang.String name)
Reads given configuration property. If not found, throws a MissingParameterException. When creating the Class object, a few attempts are done to resolve the classname. See Configuration for details.

Parameters:
name - Name of configuration property

getClass

public java.lang.Class getClass(java.lang.String name,
                                java.lang.Class def)
Reads given configuration property. If not found, returns the default value.

Parameters:
name - Name of configuration property
def - default value
See Also:
getClass(String)

getInstance

public java.lang.Object getInstance(java.lang.String name)
Reads given configuration property for a class name. It returns an instance of the class. The class must implement a constructor that takes a String as an argument. The value of this string will be name. The constructor of the class can see the configuration so it can make use of this name to read its own parameters from it.

Parameters:
name - Name of configuration property
Throws:
MissingParameterException - if the given property is not defined
IllegalParameterException - if there is any problem creating the instance

getInstance

public java.lang.Object getInstance(java.lang.String name,
                                    java.lang.Object def)
Reads given configuration property for a class name. It returns an instance of the class. The class must implement a constructor that takes a String as an argument. The value of this string will be name. The constructor of the class can see the configuration so it can make use of this name to read its own parameters from it.

Parameters:
name - Name of configuration property
def - The default object that is returned if there is no property defined with the given name
Throws:
IllegalParameterException - if the given name is defined but there is a problem creating the instance.

getInstanceArray

public java.lang.Object[] getInstanceArray(java.lang.String name)
It returns an array of class instances. The instances are constructed by calling getInstance(String) on the names returned by getNames(String).

Parameters:
name - The component type (i.e. prefix of the list of configuration properties) which will be passed to getNames(String).

getNames

public java.lang.String[] getNames(java.lang.String name)
Returns an array of names prefixed by the specified name. The array is sorted as follows. If there is no config entry "include"+"."+name or "order"+"."+name then the order is alphabetical. Otherwise this entry defines the order. For more information see Configuration.

Parameters:
name - the component type (i.e., the prefix)
Returns:
the full property names in the order specified by the configuration