com.zwares.base.util
Class Configuration

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--com.zwares.base.util.Configuration
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class Configuration
extends java.util.Properties

This class reads the configuration file and returns requested data types. It extends Properties. It provides a richer set of methods that convert the configuration value to other data types.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
Configuration(java.lang.String name)
          Creates a new Configuration.
 
Method Summary
 boolean doesFileExist()
          Returns if the configuration file exists.
 java.lang.String get(java.lang.String key)
          Returns the string value associated to the given key.
 boolean getB(java.lang.String key)
          Returns the boolean value associated to the given key.
 boolean getB(java.lang.String key, boolean defaultVal)
          Returns the boolean value associated to the given key using the specified default.
 char getC(java.lang.String key)
          Returns the character value associated to the given key.
 double getD(java.lang.String key)
          Returns the double value associated to the given key.
 double getD(java.lang.String key, double defaultVal)
          Returns the double value associated to the given key using the specified default.
 double[] getDoubleArray(java.lang.String key)
          Returns the double array value associated to the given key.
 double[] getDoubleArray(java.lang.String key, java.lang.String delimiter)
          Returns the double array value associated to the given key.
 int getI(java.lang.String key)
          Returns the integer value associated to the given key.
 int getI(java.lang.String key, int defaultVal)
          Returns the integer value associated to the given key using the specified default
 java.io.InputStream getInputStream(java.lang.String filePath)
          This routine returns an InputStream matching the filePath.
 java.lang.String getS(java.lang.String key)
          Returns the string value associated to the given key.
 java.lang.String getS(java.lang.String key, java.lang.String defaultVal)
          Returns the string value associated to the given key using the specified default.
 java.lang.String[] getStringArray(java.lang.String key)
          Returns the string array value associated to the given key.
 java.lang.String[] getStringArray(java.lang.String key, java.lang.String delimiter)
          Returns the string array value associated to the given key.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, propertyNames, save, setProperty, store
 
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

Configuration

public Configuration(java.lang.String name)
Creates a new Configuration.

Parameters:
name - The configuration file can be found at the file name.
Method Detail

doesFileExist

public boolean doesFileExist()
Returns if the configuration file exists.


get

public java.lang.String get(java.lang.String key)
Returns the string value associated to the given key.


getS

public java.lang.String getS(java.lang.String key)
Returns the string value associated to the given key.


getS

public java.lang.String getS(java.lang.String key,
                             java.lang.String defaultVal)
Returns the string value associated to the given key using the specified default.


getStringArray

public java.lang.String[] getStringArray(java.lang.String key)
Returns the string array value associated to the given key.


getStringArray

public java.lang.String[] getStringArray(java.lang.String key,
                                         java.lang.String delimiter)
Returns the string array value associated to the given key.


getDoubleArray

public double[] getDoubleArray(java.lang.String key)
Returns the double array value associated to the given key.


getDoubleArray

public double[] getDoubleArray(java.lang.String key,
                               java.lang.String delimiter)
Returns the double array value associated to the given key.


getC

public char getC(java.lang.String key)
Returns the character value associated to the given key.


getI

public int getI(java.lang.String key)
Returns the integer value associated to the given key.


getI

public int getI(java.lang.String key,
                int defaultVal)
Returns the integer value associated to the given key using the specified default


getB

public boolean getB(java.lang.String key)
Returns the boolean value associated to the given key.


getB

public boolean getB(java.lang.String key,
                    boolean defaultVal)
Returns the boolean value associated to the given key using the specified default.


getD

public double getD(java.lang.String key)
Returns the double value associated to the given key.


getD

public double getD(java.lang.String key,
                   double defaultVal)
Returns the double value associated to the given key using the specified default.


getInputStream

public java.io.InputStream getInputStream(java.lang.String filePath)
This routine returns an InputStream matching the filePath. It searches for the file using classPath entries in following order: 1. If the entry of classPath is a directory. 1.1 it searches for the file in that directory matching the file name 1.2 it searches for the sub-directories in the classPath which matches the filePath. 2. If the entry of classPath is a jar file, it search the entries in the jar file which match the filePath.

Parameters:
filePath - Could be any of the following 1. absoulate path (/com/zwares/config/init.prop) 2. relative path (com/zwares/config/init.prop) 3. file name (init.prop)