com.sun.jini.compat.harness
Class SysConfig

java.lang.Object
  extended bycom.sun.jini.compat.harness.SysConfig

public class SysConfig
extends java.lang.Object

A class used to simplify the access to properties in property files.


Constructor Summary
SysConfig(java.lang.String configFilename)
          This constructor will attempt to open the properties file corresponding to the path and filename supplied in configFilename.
 
Method Summary
 boolean getBooleanConfigVal(java.lang.String propertyName, boolean defaultVal)
          This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'boolean'.
 double getDoubleConfigVal(java.lang.String propertyName, double defaultVal)
          This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'double'.
 float getFloatConfigVal(java.lang.String propertyName, float defaultVal)
          This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'float'.
 int getIntConfigVal(java.lang.String propertyName, int defaultVal)
          This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'int'.
 long getLongConfigVal(java.lang.String propertyName, long defaultVal)
          This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'long'.
 java.lang.String getPathConfigVal(java.lang.String propertyName, java.lang.String defaultVal)
          This method will retrieve from the locally stored property list, the String value of a "propertyName".
 java.lang.String getStringConfigVal(java.lang.String propertyName, java.lang.String defaultVal)
          This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'String'.
 java.lang.String relativeToAbsolutePath(java.lang.String path)
          This method constructs a well-formed, absolute path/filename from the given path parameter.
 java.lang.String relativeToAbsolutePath(java.lang.String installDir, java.lang.String path)
          This method constructs a well-formed, absolute path/filename from the given installDir and path parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SysConfig

public SysConfig(java.lang.String configFilename)
          throws java.io.IOException
This constructor will attempt to open the properties file corresponding to the path and filename supplied in configFilename. If the file does not exist, or for any reason the file can not be opened, the constructor will return without instantiating the properties list. Note that the methods of this class which retrieve values from the properties list will test for the existence of the list prior to attempting to retrieve a property value. Those methods will return the default value if the list or the property value itself does not exist. In this way, a process can use this class with or without a configuration file; the absence of a configuration file will result in the process using its default values.

Parameters:
configFilename - the property file name
Method Detail

getIntConfigVal

public int getIntConfigVal(java.lang.String propertyName,
                           int defaultVal)
This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'int'.

If the property list does not exist, or if the string value of the property can not be "cast" to the expected data type, then the default value will be returned.


getLongConfigVal

public long getLongConfigVal(java.lang.String propertyName,
                             long defaultVal)
This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'long'.

If the property list does not exist, or if the string value of the property can not be "cast" to the expected data type, then the default value will be returned.


getFloatConfigVal

public float getFloatConfigVal(java.lang.String propertyName,
                               float defaultVal)
This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'float'.

If the property list does not exist, or if the string value of the property can not be "cast" to the expected data type, then the default value will be returned.


getDoubleConfigVal

public double getDoubleConfigVal(java.lang.String propertyName,
                                 double defaultVal)
This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'double'.

If the property list does not exist, or if the string value of the property can not be "cast" to the expected data type, then the default value will be returned.


getStringConfigVal

public java.lang.String getStringConfigVal(java.lang.String propertyName,
                                           java.lang.String defaultVal)
This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'String'.

If the property list does not exist, or if the string value of the property can not be "cast" to the expected data type, then the default value will be returned.


getBooleanConfigVal

public boolean getBooleanConfigVal(java.lang.String propertyName,
                                   boolean defaultVal)
This method will retrieve from the locally stored property list, the value of a property whose name corresponds to the string contained in the input argument "propertyName" and whose value is of type 'boolean'.

If the property list does not exist, or if the string value of the property can not be "cast" to the expected data type, then the default value will be returned.


getPathConfigVal

public java.lang.String getPathConfigVal(java.lang.String propertyName,
                                         java.lang.String defaultVal)
This method will retrieve from the locally stored property list, the String value of a "propertyName". The value is assumed to be a path and (possibly) a filename.

If the property list does not exist then the default value will be returned.

The goal of this method is to take the path/filename String represented in the property corresponding to the given propertyName and "compute" a well-formed absolute path/filename. This method is intended to be sensitive to file system dependencies. For example, if the property is written in DOS file format (ex. C:\aaa\bbb\ccc\), but this method is executed on a system with a unix file system, this method will build a String in the unix file system format from the contents of the given String (/aaa/bbb/ccc).

In addition to being sensitive to file system differences, this method is also designed to handle both absolute and relative paths in a well-defined manner.

Parameters:
propertyName - String containing the name of the property whose value should be retrieved and converted to the appropriate format
defaultVal - the String value to use if the property given in the propertyName parameter does not exist, or cannot be retrieved.
Returns:
a String containing a path/filename constructed from the value of the propertyName parameter and the "com.sun.jini.compat.installDir" property in a format that is appropriate to the current file system.

relativeToAbsolutePath

public java.lang.String relativeToAbsolutePath(java.lang.String path)
This method constructs a well-formed, absolute path/filename from the given path parameter. If the path parameter is not already absolute, the OS-dependent absolute path constructed from the current directory is pre-pended to the path parameter, and the adjustments are made to the format of the output for the current file system.

Parameters:
path - String containing the name of the path/filename to process
Returns:
a String containing a path/filename constructed from the value of the input parameter in a format that is appropriate to the current file system.

relativeToAbsolutePath

public java.lang.String relativeToAbsolutePath(java.lang.String installDir,
                                               java.lang.String path)
This method constructs a well-formed, absolute path/filename from the given installDir and path parameters. This method is intended to be sensitive to file system dependencies. For example, if the property is written in DOS file format (ex. C:\aaa\bbb\ccc\), but this method is executed on a system with a unix file system, this method will build a String in the unix file system format from the contents of the given String (/aaa/bbb/ccc).

In addition to being sensitive to file system differences, this method is also designed to handle both absolute and relative paths in a well-defined manner. If the path/filename corresponding to the given path parameter is absolute, that path/filename will be converted to the appropriate file system format with no other modifications or additions applied. On the other hand, if the path parameter is relative, then the value contained in installDir parameter will be prepended to the path parameter, and the result will be returned in the appropriate file system format.

Whether a given path/filename is viewed as relative or absolute is based on the following criteria:

  non-DOS file systems  abs/rel    DOS file systems  abs/rel
  --------------------  --------   ----------------  --------
     /aaa/bbb/ccc       absolute    c:\aaa\bbb\ccc   absolute
     aaa/bbb/ccc        relative      \aaa\bbb\ccc   relative
                                      \\aaa\bbb\ccc  relative
                                        aaa\bbb\ccc  relative
 

Note that this method also attempts to handle the case where the format of the given path parameter is different than the current file system's format. For example,

 file sys installDir      path      abs/rel         output 
 -------- ---------- -------------- --------  --------------------
   DOS     c:\files  c:\aaa\bbb\ccc absolute  c:\aaa\bbb\ccc
   unix    c:\files  c:\aaa\bbb\ccc absolute    /aaa/bbb/ccc
   DOS     c:\files     aaa\bbb\ccc relative  c:\files\aaa\bbb\ccc
   unix    c:\files     aaa\bbb\ccc relative    /files/aaa/bbb/ccc
 

Parameters:
installDir - String containing the name of the directory to prepend to the path parameter; if not an absolute path, it will be made one using File.getAbsolutePath()
path - String containing the name of the path/filename to modify (if necessary); if not an absolute path, it will be made one by prepending the absolute path of installDir
Returns:
a String containing an absolute path/filename constructed from the value of the input parameters in a format that is appropriate to the current file system.


Copyright 2005, Sun Microsystems, Inc.
Licensed under the Apache License, Version 2.0.