amber.utility
Class PropertiesHandler

java.lang.Object
  |
  +--amber.utility.PropertiesHandler

public class PropertiesHandler
extends java.lang.Object

This class contains a series of utility functions which can be used to access properties files.


Constructor Summary
PropertiesHandler()
          Default constructor
PropertiesHandler(boolean loadSystemProperties)
          Allows the properties to be loaded with or without the system properties included.
PropertiesHandler(java.lang.String filename)
          Constructs a handler based on the specified filename.
PropertiesHandler(java.lang.String filename, boolean loadSystemProperties)
          Constructs a handler based on the specified filename.
 
Method Summary
protected  java.lang.String createCompositeName(java.lang.String group, java.lang.String name)
          This function is used by the group property functions.
 boolean doesGroupPropertyExist(java.lang.String group, java.lang.String name)
          Determines if the group property exists in the properties object.
 boolean doesPropertyExist(java.lang.String name)
          Determines if the property exists in the properties object.
 java.lang.String getFilename()
          This function returns the name of the properties file active.
 java.lang.String getGroupProperty(java.lang.String group, java.lang.String name, java.lang.String defaultValue)
          Get a property from the properties object.
 boolean getGroupPropertyBoolean(java.lang.String group, java.lang.String name, boolean defaultValue)
          Get a property boolean from the properties object.
 int getGroupPropertyInt(java.lang.String group, java.lang.String name, int defaultValue)
          Get a property integer from the properties object.
 long getGroupPropertyLong(java.lang.String group, java.lang.String name, long defaultValue)
          Get a property long from the properties object.
 java.util.Enumeration getGroupPropertyNames(java.lang.String groupName)
          Get an enumeration of all the property names in the properties object.
 java.lang.String getHeader()
          This function returns the name of the properties file active.
 java.lang.String getProperty(java.lang.String name, java.lang.String defaultValue)
          Get a property from the properties object.
 boolean getPropertyBoolean(java.lang.String name, boolean defaultValue)
          Get a property boolean from the properties object.
 int getPropertyInt(java.lang.String name, int defaultValue)
          Get a property integer from the properties object.
 long getPropertyLong(java.lang.String name, long defaultValue)
          Get a property long from the properties object.
 java.util.Enumeration getPropertyNames()
          Get an enumeration of all the property names in the properties object.
 boolean isFileValid()
          Returns the state of the file load.
 boolean isResource()
          This returns true if the properties file loaded the properties as a resource.
protected  void openPropertiesFile(java.lang.String filename, boolean loadSystemProperties)
          This function is used to actually read the properties from the file.
 void removeGroupProperty(java.lang.String group, java.lang.String name)
          Remove a property from the properties group object.
 void removeProperty(java.lang.String name)
          Remove a property from the properties object.
 void save()
          This function saves the properties file to the internal filename.
 void save(java.lang.String filename)
          This function saves the properties file to the specified filename.
 void setFilename(java.lang.String newName)
          This function sets the filename of the properties file and opens the corresponding properties.
 void setFilename(java.lang.String newName, boolean loadSystemProperties)
          This function sets the filename of the properties file and opens the corresponding properties.
 void setGroupProperty(java.lang.String group, java.lang.String name, java.lang.String value)
          Set a property in the properties object.
 void setGroupPropertyBoolean(java.lang.String group, java.lang.String name, boolean value)
          Set a boolean property in the properties object.
 void setGroupPropertyInt(java.lang.String group, java.lang.String name, int value)
          Set an integer property in the properties object.
 void setGroupPropertyLong(java.lang.String group, java.lang.String name, long value)
          Set an integer property in the properties object.
 void setHeader(java.lang.String header)
          This function sets the optional header for the properties file.
 void setProperty(java.lang.String name, java.lang.String value)
          Set a property in the properties object.
 void setPropertyBoolean(java.lang.String name, boolean value)
          Set an boolean property in the properties object.
 void setPropertyInt(java.lang.String name, int value)
          Set an integer property in the properties object.
 void setPropertyLong(java.lang.String name, long value)
          Set a long property in the properties object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesHandler

public PropertiesHandler()
Default constructor

PropertiesHandler

public PropertiesHandler(java.lang.String filename)
Constructs a handler based on the specified filename.
Parameters:
filename - String name of the properties file.

PropertiesHandler

public PropertiesHandler(java.lang.String filename,
                         boolean loadSystemProperties)
Constructs a handler based on the specified filename.
Parameters:
filename - String name of the properties file.
loadSystemProperties - boolean true if the system properties are to be loaded.

PropertiesHandler

public PropertiesHandler(boolean loadSystemProperties)
Allows the properties to be loaded with or without the system properties included.
Parameters:
loadSystemProperties - boolean true if the system properties are to be loaded.
Method Detail

createCompositeName

protected java.lang.String createCompositeName(java.lang.String group,
                                               java.lang.String name)
This function is used by the group property functions. It creates the required composite name from the two elements.
Parameters:
group - String containing the name of the group.
name - String name of the individual property entry.
Returns:
String containing the composite property name.

doesGroupPropertyExist

public boolean doesGroupPropertyExist(java.lang.String group,
                                      java.lang.String name)
Determines if the group property exists in the properties object.
Parameters:
group - String containing the name of the group. This is a base dotted notation string which is prepended to the name value. Do not add a trailing dot.
name - String property name to access.
Returns:
boolean true if the property exists.

doesPropertyExist

public boolean doesPropertyExist(java.lang.String name)
Determines if the property exists in the properties object.
Parameters:
name - String property name to access.
Returns:
boolean true if the property exists.

getFilename

public java.lang.String getFilename()
This function returns the name of the properties file active.
Returns:
String containing the filename.

getGroupProperty

public java.lang.String getGroupProperty(java.lang.String group,
                                         java.lang.String name,
                                         java.lang.String defaultValue)
Get a property from the properties object.
Parameters:
group - String containing the name of the group. This is a base dotted notation string which is prepended to the name value. Do not add a trailing dot.
name - String property name to access.
defaultValue - String value to return if the property does not exist.
Returns:
String containing the value.

getGroupPropertyBoolean

public boolean getGroupPropertyBoolean(java.lang.String group,
                                       java.lang.String name,
                                       boolean defaultValue)
Get a property boolean from the properties object.
Parameters:
group - String containing the name of the group. This is a base dotted notation string which is prepended to the name value. Do not add a trailing dot.
name - String property name to access.
defaultValue - boolean value to return if the property does not exist.
Returns:
boolean containing the value.

getGroupPropertyInt

public int getGroupPropertyInt(java.lang.String group,
                               java.lang.String name,
                               int defaultValue)
Get a property integer from the properties object.
Parameters:
group - String containing the name of the group. This is a base dotted notation string which is prepended to the name value. Do not add a trailing dot.
name - String property name to access.
defaultValue - int value to return if the property does not exist.
Returns:
int containing the value.

getGroupPropertyLong

public long getGroupPropertyLong(java.lang.String group,
                                 java.lang.String name,
                                 long defaultValue)
Get a property long from the properties object.
Parameters:
group - String containing the name of the group. This is a base dotted notation string which is prepended to the name value. Do not add a trailing dot.
name - String property name to access.
defaultValue - long value to return if the property does not exist.
Returns:
int containing the value.

getGroupPropertyNames

public java.util.Enumeration getGroupPropertyNames(java.lang.String groupName)
Get an enumeration of all the property names in the properties object.
Parameters:
groupName - String containing the name of the group to select.
Returns:
Enumeration containing the property names.

getHeader

public java.lang.String getHeader()
This function returns the name of the properties file active.
Returns:
String containing the header of the properties file.

getProperty

public java.lang.String getProperty(java.lang.String name,
                                    java.lang.String defaultValue)
Get a property from the properties object.
Parameters:
name - String property name to access.
defaultValue - String value to return if the property does not exist.
Returns:
String containing the value.

getPropertyBoolean

public boolean getPropertyBoolean(java.lang.String name,
                                  boolean defaultValue)
Get a property boolean from the properties object.
Parameters:
name - String property name to access.
defaultValue - boolean value to return if the property does not exist.
Returns:
boolean containing the value.

getPropertyInt

public int getPropertyInt(java.lang.String name,
                          int defaultValue)
Get a property integer from the properties object.
Parameters:
name - String property name to access.
defaultValue - int value to return if the property does not exist.
Returns:
int containing the value.

getPropertyLong

public long getPropertyLong(java.lang.String name,
                            long defaultValue)
Get a property long from the properties object.
Parameters:
name - String property name to access.
defaultValue - long value to return if the property does not exist.
Returns:
int containing the value.

getPropertyNames

public java.util.Enumeration getPropertyNames()
Get an enumeration of all the property names in the properties object.
Returns:
Enumeration containing the property names.

isFileValid

public boolean isFileValid()
Returns the state of the file load.
Returns:
boolean true if the specified properties file was correctly loaded.

isResource

public boolean isResource()
This returns true if the properties file loaded the properties as a resource. Creation date: (23/10/2001 8:53:37 a.m.)
Returns:
boolean true if this properties was a resource.

openPropertiesFile

protected void openPropertiesFile(java.lang.String filename,
                                  boolean loadSystemProperties)
                           throws java.io.IOException
This function is used to actually read the properties from the file.
Parameters:
filename - String containing the filename of the properties file.
loadSystemProperties - boolean true if the system properties are to be loaded.
Throws:
java.io.IOException - containing any errors.

removeGroupProperty

public void removeGroupProperty(java.lang.String group,
                                java.lang.String name)
Remove a property from the properties group object.
Parameters:
group - String containing the name of the group. This is a base dotted notation string which is prepended to the name value. Do not add a trailing dot.
name - String property name to remove.

removeProperty

public void removeProperty(java.lang.String name)
Remove a property from the properties object.
Parameters:
name - String property name to remove.

save

public void save()
          throws java.io.IOException
This function saves the properties file to the internal filename.
Throws:
java.io.IOException - containing errors saving the file.

save

public void save(java.lang.String filename)
          throws java.io.IOException
This function saves the properties file to the specified filename.
Parameters:
filename - String name of the file to save to.
Throws:
java.io.IOException - containing errors saving the file.

setFilename

public void setFilename(java.lang.String newName)
                 throws java.io.IOException
This function sets the filename of the properties file and opens the corresponding properties.
Parameters:
newName - String containing the filename of the properties file.
Throws:
java.io.IOException - containing any errors.

setFilename

public void setFilename(java.lang.String newName,
                        boolean loadSystemProperties)
                 throws java.io.IOException
This function sets the filename of the properties file and opens the corresponding properties.
Parameters:
newName - String containing the filename of the properties file.
loadSystemProperties - boolean true if the system properties are to be loaded.
Throws:
java.io.IOException - containing any errors.

setGroupProperty

public void setGroupProperty(java.lang.String group,
                             java.lang.String name,
                             java.lang.String value)
Set a property in the properties object.
Parameters:
group - String containing the name of the group. This is a base dotted notation string which is prepended to the name value. Do not add a trailing dot.
name - String property name to set.
value - String value to set the property to.

setGroupPropertyBoolean

public void setGroupPropertyBoolean(java.lang.String group,
                                    java.lang.String name,
                                    boolean value)
Set a boolean property in the properties object.
Parameters:
group - String containing the name of the group. This is a base dotted notation string which is prepended to the name value. Do not add a trailing dot.
name - String property name to set.
value - boolean value to set the property to.

setGroupPropertyInt

public void setGroupPropertyInt(java.lang.String group,
                                java.lang.String name,
                                int value)
Set an integer property in the properties object.
Parameters:
group - String containing the name of the group. This is a base dotted notation string which is prepended to the name value. Do not add a trailing dot.
name - String property name to set.
value - int value to set the property to.

setGroupPropertyLong

public void setGroupPropertyLong(java.lang.String group,
                                 java.lang.String name,
                                 long value)
Set an integer property in the properties object.
Parameters:
group - String containing the name of the group. This is a base dotted notation string which is prepended to the name value. Do not add a trailing dot.
name - String property name to set.
value - long value to set the property to.

setHeader

public void setHeader(java.lang.String header)
This function sets the optional header for the properties file.
Parameters:
header - String containing the header of the properties file.

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
Set a property in the properties object.
Parameters:
name - String property name to set.
value - String value to set the property to.

setPropertyBoolean

public void setPropertyBoolean(java.lang.String name,
                               boolean value)
Set an boolean property in the properties object.
Parameters:
name - String property name to set.
value - boolean value to set the property to.

setPropertyInt

public void setPropertyInt(java.lang.String name,
                           int value)
Set an integer property in the properties object.
Parameters:
name - String property name to set.
value - int value to set the property to.

setPropertyLong

public void setPropertyLong(java.lang.String name,
                            long value)
Set a long property in the properties object.
Parameters:
name - String property name to set.
value - int value to set the property to.


Copyright © 2002 Clearfield Research Ltd. All Rights Reserved.