org.moyoman.framework
Class ServerConfig

java.lang.Object
  |
  +--org.moyoman.framework.ServerConfig

public class ServerConfig
extends Object

This class allows for the reading and writing of configuration information. The information is stored in a Properties file in a well known location.


Field Summary
private  Properties properties
          The system environment variables.
private static ServerConfig sc
          The singleton ServerConfig object.
private  String topdir
          The top level directory name.
 
Constructor Summary
private ServerConfig()
          Create the ServerConfig object.
 
Method Summary
protected  void cancel()
          Cancel any changes that have occurred since the last call to save() or cancel().
private  void createDirectories()
           
private  void createDirectoryIfNecessary(String dirname)
           
 String[] getAllProperties()
          Return an array of all of the property names.
private  String getFileName()
          Get the file name of the system.properties file.
 String getProperty(String name)
          Get the value for a specific property.
static ServerConfig getServerConfig()
          Get the singleton ServerConfig object.
 String getTopDirectory()
          Get the top level directory name.
private  void processCommandLineArguments()
          Override system parameters from the system.properties file with ones from the command line.
private  Properties readFile()
          Read the system.properties file.
protected  void save()
          Save any changes that have occurred since the last call to save() or cancel().
 void setProperty(String name, String value)
          Set a given property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

private Properties properties
The system environment variables.


topdir

private String topdir
The top level directory name.


sc

private static final ServerConfig sc
The singleton ServerConfig object.

Constructor Detail

ServerConfig

private ServerConfig()
Create the ServerConfig object. This method causes the properties file to be read, and all of the properties to be stored in the object. The software cannot operate if this object cannot be created, so SystemLog.fatal() is called on error.

Method Detail

readFile

private Properties readFile()
                     throws InternalErrorException
Read the system.properties file.

Returns:
A Properties object containing the system properties.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

processCommandLineArguments

private void processCommandLineArguments()
Override system parameters from the system.properties file with ones from the command line. Properties are only replaced. Properties that are not in the system.properties file are not added to the properties variable.


createDirectories

private void createDirectories()
                        throws InternalErrorException
InternalErrorException

createDirectoryIfNecessary

private void createDirectoryIfNecessary(String dirname)
                                 throws InternalErrorException
InternalErrorException

getProperty

public String getProperty(String name)
                   throws NoSuchDataException
Get the value for a specific property.

Parameters:
name - The name of the property to retrieve.
Returns:
The value for the property.
Throws:
NoSuchDataException - Thrown if there is no entry for the property.

setProperty

public void setProperty(String name,
                        String value)
Set a given property. If the property already has a value, it is replaced.

Parameters:
name - The property to set.
value - The value for that property.

cancel

protected void cancel()
               throws InternalErrorException
Cancel any changes that have occurred since the last call to save() or cancel().

Throws:
InternalErrorException - Thrown if the operation fails for any reason.

getFileName

private String getFileName()
Get the file name of the system.properties file.

Returns:
A String which is the filename.

save

protected void save()
             throws InternalErrorException
Save any changes that have occurred since the last call to save() or cancel().

Throws:
InternalErrorException - Thrown if the operation fails for any reason.

getAllProperties

public String[] getAllProperties()
Return an array of all of the property names.

Returns:
An array of String objects.

getTopDirectory

public String getTopDirectory()
Get the top level directory name. The last character is the directory separator character.

Returns:
The name of the top level directory.

getServerConfig

public static final ServerConfig getServerConfig()
Get the singleton ServerConfig object.

Returns:
The ServerConfig object.