uk.org.iscream.cms.conient
Class Configuration

java.lang.Object
  extended byuk.org.iscream.cms.conient.Configuration

public class Configuration
extends Object

Provides configuration details to Conient This class is a Singleton class. It handles all the configuration for Conient. Once a connection has been made, it is told that it can get configuration from the server, thus allowing other components access to the servers configuration. It also shows the ConfigurationDialog on request, which allows local configuration options to be changed. It also has support for a variety of methods of saving the config in different files and in the default file.

Version:
$Id: Configuration.java,v 1.14 2004/08/01 10:40:05 tdb Exp $
Author:
$Author: tdb $

Nested Class Summary
private  class Configuration.SuffixFileFilter
          An inner class for the file filter.
 
Field Summary
private  File _configFile
          The file that the current configuration is loaded from
private  ConnectionHandler _connectionHandler
          A reference to the ConnectionHandler, this allows this class to obtain configuration from the server
private  File _defaultConfigFile
          The file containing the default configuration
private static Configuration _instance
          The reference to the singleton instance of this class
private  Properties _properties
          The current configuration in use
private  boolean _usingSpecificConfig
          A value to indicate whether a specific config is in use or not
static String CONFIG_HEADER
           
private  JFileChooser fc
          A file chooser to prompt for file names when saving configuration
private  FileFilter filter
          A file filter for the file chooser dialog boxes
static String REVISION
          The current CVS revision of this class
 
Constructor Summary
private Configuration(String configFile)
          The private constructor, ensures that this is a singleton.
 
Method Summary
static Configuration getInstance()
          Returns the singleton instance of this class.
 String getProperty(String key)
          A wrapper for java.util.Properties.getProperty When given a key it returns the value of that key ie, key = value
 String getServerProperty(String configName, String propertyName)
          This method is called by any part of the system that requires configuration from the server.
 boolean getUsingSpecificConfig()
          Returns whether a specific config is in use rather than a default one
 void GUIReconfiguration()
          Tells the configuration class that it should perform user re-configuration through displaying a gui.
static void initialise(String configFile)
          Creates and initialises a the Configuration system for Conient.
 void loadConfiguration()
          Loads in a configuration that is chosen by the user after displaying a dialog.
private  Properties readFileConfiguration(File inputFile)
          Reads in the specified file and parses its properties.
 void saveConfiguration()
          This method saves the currently saves the current config, if the config has not been saved before at it is not the default, then it prompts for a file name by calling saveNewConfiguration().
 void saveDefaultConfiguration()
          This method saves the currently loaded config as the default config
private  void saveFileConfiguration(File outputFile)
          This method writes out the current configuration to a file using the Properties.store() method.
 void saveNewConfiguration()
          Prompts the user for a box to save the configuration to a specific filename.
 void setConnectionHandler(ConnectionHandler connectionHandler)
          When the connection handler class starts up it notifys this class that it is up, so that we can obtain configuration through the open connections, should there be any.
 void setProperty(String key, String value)
          A wrapper for java.util.Properties.setProperty When given a key and a value, it writes it to the current properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
The current CVS revision of this class

See Also:
Constant Field Values

CONFIG_HEADER

public static final String CONFIG_HEADER
See Also:
Constant Field Values

_properties

private Properties _properties
The current configuration in use


_connectionHandler

private ConnectionHandler _connectionHandler
A reference to the ConnectionHandler, this allows this class to obtain configuration from the server


_usingSpecificConfig

private boolean _usingSpecificConfig
A value to indicate whether a specific config is in use or not


_configFile

private File _configFile
The file that the current configuration is loaded from


_defaultConfigFile

private File _defaultConfigFile
The file containing the default configuration


filter

private final FileFilter filter
A file filter for the file chooser dialog boxes


fc

private final JFileChooser fc
A file chooser to prompt for file names when saving configuration


_instance

private static Configuration _instance
The reference to the singleton instance of this class

Constructor Detail

Configuration

private Configuration(String configFile)
The private constructor, ensures that this is a singleton. Simply reads in the local configuration from the file. Then sets the current properties to be this configuration. Later the system will obtain further configuration from the server.

Parameters:
configFile - the path to the file that this configuration should load
Method Detail

initialise

public static void initialise(String configFile)
Creates and initialises a the Configuration system for Conient. This calls the private constructor and ensures this class is a singleton.

Parameters:
configFile - the path to the file that this configuration should load

getInstance

public static Configuration getInstance()
Returns the singleton instance of this class. This will throw a runtime exception if it is called at the wrong time!

Returns:
the singleton instance

getServerProperty

public String getServerProperty(String configName,
                                String propertyName)
This method is called by any part of the system that requires configuration from the server. It should be passed the configuration name: eg, "Host.raptor.ukc.ac.uk" and the property required: eg, "Host.UDPUpdateTime" This method will then ask the ConnectionHandler to talk to the server and return the property. If the server fails to get the property, or the ConnectionHandler is not started, this method returns null.


GUIReconfiguration

public void GUIReconfiguration()
Tells the configuration class that it should perform user re-configuration through displaying a gui. This passes control to a dialog to handle re-configuration. Basically this is the nicer alternative to hacking the config file. The ConientConfiguration class is responsible for handling the re-configuration.


saveNewConfiguration

public void saveNewConfiguration()
Prompts the user for a box to save the configuration to a specific filename.


saveConfiguration

public void saveConfiguration()
This method saves the currently saves the current config, if the config has not been saved before at it is not the default, then it prompts for a file name by calling saveNewConfiguration().


saveDefaultConfiguration

public void saveDefaultConfiguration()
This method saves the currently loaded config as the default config


loadConfiguration

public void loadConfiguration()
Loads in a configuration that is chosen by the user after displaying a dialog.


readFileConfiguration

private Properties readFileConfiguration(File inputFile)
                                  throws FileNotFoundException,
                                         IOException
Reads in the specified file and parses its properties.

Returns:
the parsed properties
Throws:
FileNotFoundException
IOException

saveFileConfiguration

private void saveFileConfiguration(File outputFile)
This method writes out the current configuration to a file using the Properties.store() method. It uses the CONFIG_HEADER attribute to head the file.


getProperty

public String getProperty(String key)
A wrapper for java.util.Properties.getProperty When given a key it returns the value of that key ie, key = value

Parameters:
key - the key the value of which is wanted

setProperty

public void setProperty(String key,
                        String value)
A wrapper for java.util.Properties.setProperty When given a key and a value, it writes it to the current properties.

Parameters:
key - the key to write
value - the value to assign it

getUsingSpecificConfig

public boolean getUsingSpecificConfig()
Returns whether a specific config is in use rather than a default one

Returns:
yay or nay

setConnectionHandler

public void setConnectionHandler(ConnectionHandler connectionHandler)
When the connection handler class starts up it notifys this class that it is up, so that we can obtain configuration through the open connections, should there be any.

Parameters:
connectionHandler - a handle on the instance of the connnection handler


Copyright © 2000-2003 i-scream. All Rights Reserved.