DLESE Tools
v1.6.0

org.dlese.dpc.propertiesmgr
Class PropertiesManager

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<Object,Object>
          extended by java.util.Properties
              extended by org.dlese.dpc.propertiesmgr.PropertiesManager
All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public class PropertiesManager
extends Properties

Reads and writes Java properties files. Properties files can be on disc or contained within a Jar file.

Version:
$Id: PropertiesManager.java,v 1.6 2009/03/20 23:33:54 jweather Exp $
Author:
John Weatherley
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
PropertiesManager()
          Create an unloaded Properties object.
PropertiesManager(String propsFileName)
          Create and load this Properties hash map from the given Properties file or properties resource located in the jar.
 
Method Summary
 String getProp(String property, String defaultValue)
          Retrieves the property value from this object's property file.
 boolean getPropAsBoolean(String property, String defaultValue)
          Same as the getProp(String,String) method only it returns it's parameter as a boolean.
 int getPropAsInt(String property, String defaultValue)
          Same as the getProp(String,String) method only it returns it's parameter as an integer.
 void loadPropertiesFile()
          Loads or re-loads the properties from its file or JAR, replacing all previously loaded properties, if any.
 void writePropsFile()
          Writes the properties to the same file that was used to read them, preserving any comments in the file.
 void writePropsFile(String propsFilePath)
          Writes the properties to the given file path.
 
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

PropertiesManager

public PropertiesManager()
Create an unloaded Properties object. Same as Properties().


PropertiesManager

public PropertiesManager(String propsFileName)
                  throws IOException
Create and load this Properties hash map from the given Properties file or properties resource located in the jar.

Parameters:
propsFileName - The name of the Properties file to load or URL to the properties location inside a jar
Throws:
IOException - If unable to load the properties.
Method Detail

loadPropertiesFile

public void loadPropertiesFile()
                        throws IOException
Loads or re-loads the properties from its file or JAR, replacing all previously loaded properties, if any. If the file or JAR is not configured, does nothing.

Throws:
IOException - If error

writePropsFile

public void writePropsFile()
                    throws IOException
Writes the properties to the same file that was used to read them, preserving any comments in the file. If the original file was contained in a jar then an I/O excetion is thrown.

Throws:
IOException - If error in input/output

writePropsFile

public void writePropsFile(String propsFilePath)
                    throws IOException
Writes the properties to the given file path. If the file path is the same as the one used to upen this file, then all comments in the file are preserved.

Parameters:
propsFilePath - The full path to the props file to be written.
Throws:
IOException - If error in input/output

getProp

public String getProp(String property,
                      String defaultValue)
               throws Exception
Retrieves the property value from this object's property file. If the property does not exist and a default value is specified, the default is set in the Properties and is returned.

Parameters:
property - The property sting to retrieve
defaultValue - The default value for this property, if none is found
Returns:
The prop value
Throws:
Exception - If error

getPropAsInt

public int getPropAsInt(String property,
                        String defaultValue)
                 throws Exception
Same as the getProp(String,String) method only it returns it's parameter as an integer.

Parameters:
property - The property sting to retrieve
defaultValue - The default value for this property, if none is found
Returns:
The prop value
Throws:
Exception - If error

getPropAsBoolean

public boolean getPropAsBoolean(String property,
                                String defaultValue)
                         throws Exception
Same as the getProp(String,String) method only it returns it's parameter as a boolean. Possible inputs are [yes|no|true|false|on|off|enabled|disabled].

Parameters:
property - The property sting to retrieve
defaultValue - The default value for this property, if none is found
Returns:
The prop value
Throws:
Exception - If error

DLESE Tools
v1.6.0