Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.cantaloop.tools
Class Configuration  view Configuration download Configuration.java

java.lang.Object
  extended byorg.cantaloop.tools.Configuration

public class Configuration
extends java.lang.Object

This class reads the main configuration file cantaloop.properties and resolves the properties found in this configuration file.

How the location of the configuration file is detected:

Starting with the current directory, the algorithm searches for a directory called etc and checks if it contains the file cantaloop.properties. The algorithm searches up the directory tree until the configuration file is found or the root of the filesystem is reached. In the latter case, it checks if the configuration file can be accessed with getClass().getResource("/etc/cantaloop.properties").

It is also possible to set the configuration file directly with the method setConfigurationFile.

How properties are set:

Properties are grouped in levels. A level is the fully qualified name of a package or a class. The name of the top-level is the empty string. A property is set by appending the name of the property to a level, separated by a period. This so called fully-qualified name of the property is followed by a equal sign and the value of the property. For further information on the syntax of this configuration file, have a look at the api documentation of java.util.Properties.

Properties are resolved in the following way: Let l be the level and p the name of the property.

  1. If the value of p is found on level l, the value is returned.
  2. If l is the root-level, null is returned. Otherwise, the level is set to the ancestor of l. Return to step 1.)

Version:
@version@ ($Revision: 1.4 $)

Field Summary
private  java.lang.String m_configFileName
           
private  java.util.Properties m_properties
           
private static java.io.File s_configFile
           
private static Configuration s_instance
           
 
Constructor Summary
private Configuration()
           
 
Method Summary
private  java.io.File findConfigFile(java.io.File dir)
           
 boolean getBoolean(java.lang.Class clazz, java.lang.String id)
          Shorthand for getBoolean(clazz, id, false).
 boolean getBoolean(java.lang.Class clazz, java.lang.String id, boolean def)
          Returns the value of a property as a boolean.
static Configuration getInstance()
          Returns the sole instance of this class.
 int getInt(java.lang.Class clazz, java.lang.String id)
          Shorthand for getInt(clazz, id, 0).
 int getInt(java.lang.Class clazz, java.lang.String id, int def)
          Returns the value of a property as a int.
 java.lang.String getString(java.lang.Class clazz, java.lang.String id)
          Shorthand for getString(clazz, id, null).
 java.lang.String getString(java.lang.Class clazz, java.lang.String id, java.lang.String def)
          Returns the value of a property as a string.
private  java.lang.String internGet(java.lang.Class clazz, java.lang.String id)
           
private  boolean isRoot(java.io.File dir)
           
static void setConfigurationFile(java.io.File f)
          Sets the configuration file directly.
 void setup()
          Searches for the configuration file and rereads the properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_instance

private static Configuration s_instance

s_configFile

private static java.io.File s_configFile

m_configFileName

private java.lang.String m_configFileName

m_properties

private java.util.Properties m_properties
Constructor Detail

Configuration

private Configuration()
Method Detail

getInstance

public static Configuration getInstance()
Returns the sole instance of this class.


setConfigurationFile

public static void setConfigurationFile(java.io.File f)
Sets the configuration file directly.


setup

public void setup()
           throws java.io.IOException
Searches for the configuration file and rereads the properties. For a description of the algorithm that is used to detect the location of the configuration file have a look at the documentation at the beginning of this class.


findConfigFile

private java.io.File findConfigFile(java.io.File dir)

isRoot

private boolean isRoot(java.io.File dir)

getBoolean

public final boolean getBoolean(java.lang.Class clazz,
                                java.lang.String id)
Shorthand for getBoolean(clazz, id, false).


getBoolean

public final boolean getBoolean(java.lang.Class clazz,
                                java.lang.String id,
                                boolean def)
Returns the value of a property as a boolean. If the property is not found, def is returned. true, yes, on is interpreted as true.


getString

public final java.lang.String getString(java.lang.Class clazz,
                                        java.lang.String id)
Shorthand for getString(clazz, id, null).


getString

public final java.lang.String getString(java.lang.Class clazz,
                                        java.lang.String id,
                                        java.lang.String def)
Returns the value of a property as a string. If the property is not found, def is returned. You should also have a look at the main configuration file (etc/cantaloop.properties) as it explains how properties are resolved).


getInt

public final int getInt(java.lang.Class clazz,
                        java.lang.String id)
Shorthand for getInt(clazz, id, 0).


getInt

public final int getInt(java.lang.Class clazz,
                        java.lang.String id,
                        int def)
Returns the value of a property as a int. If the property is not found, def is returned.


internGet

private java.lang.String internGet(java.lang.Class clazz,
                                   java.lang.String id)