--- projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationServant.java 2000/11/20 15:49:46 1.9 +++ projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationServant.java 2000/11/20 17:11:44 1.10 @@ -1,123 +1,114 @@ -//---PACKAGE DECLARATION--- - -//---IMPORTS--- -import uk.ac.ukc.iscream.core.*; -import java.util.*; -import java.io.*; -import java.text.DateFormat; - -/** - * An implementation of the Configuration IDL - * This class allows i-scream modules to read and even - * set their configuration from a central location. - * - * When classes want their configuration, they contact - * the Configurator, which will locate their config, - * open it and pass it to a Configuration object which is - * then passed back to the calling class. - * - * Essentially this class behaves in a similar fashion - * to the java.util.Properties class. - * - * @author $Author: tdb $ - * @version $Id: ConfigurationServant.java,v 1.9 2000/11/20 15:49:46 tdb Exp $ - */ -class ConfigurationServant extends ConfigurationPOA { - -//---FINAL ATTRIBUTES--- - - /** - * The current CVS revision of this class - */ - public final String REVISION = "$Revision: 1.9 $"; - -//---STATIC METHODS--- - -//---CONSTRUCTORS--- - - /** - * Creates a new ConfigurationServant taking a hook - * to a file containing the configuration. - * - * @param propertiesStream an InputStream connected to the configuration - */ - ConfigurationServant(File configurationFile, Logger logRef) { - _lastModified = configurationFile.lastModified(); - _logRef = logRef; - - String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(getLastModified())); - _logRef.write(this.toString(), Logger.SYSMSG, "created: " + configurationFile.getName() + "(" + date + ")" ); - - try { - InputStream configurationStream = new FileInputStream(configurationFile); - _properties.load(configurationStream); - } catch (Exception e) { - // **************************************** - // either IOException from the .load() or - // a SecurityException or FileNotFoundException from - // the inputStream, not sure what to do yet!!! - } - } - -//---PUBLIC METHODS--- - - /** - * A wrapper for java.util.Properties.getProperty - * When given a key it returns the value of that key - * ie, key = value - * - * @param key the key the value of which is wanted - */ - public String getProperty(String key) { - return _properties.getProperty(key); - } - - /** - * Overrides the {@link java.lang.Object#toString() Object.toString()} - * method to provide clean logging (every class should have this). - * - * @return the name of this class and its CVS revision - */ - public String toString() { - return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; - } - -//---PRIVATE METHODS--- - - protected void finalize() throws Throwable { - _logRef.write(this.toString(), Logger.DEBUG, "finalized (ick, us english!)"); - } - -//---ACCESSOR/MUTATOR METHODS--- - - /** - * Returns the date stamp of the configuration file - * this object is using. - * - * @return the last modified time for the file - */ - public long getLastModified() { - return _lastModified; - } - -//---ATTRIBUTES--- - - /** - * The properties object that this class provides a CORBA interface to - */ - private Properties _properties = new Properties(); - - /** - * Reference to a Logger - */ - private Logger _logRef; - - /** - * The date stamp of the configuration file - * this object is using - */ - private long _lastModified; - -//---STATIC ATTRIBUTES--- - -} +//---PACKAGE DECLARATION--- + +//---IMPORTS--- +import uk.ac.ukc.iscream.core.*; +import java.util.*; +import java.io.*; +import java.text.DateFormat; + +/** + * An implementation of the Configuration IDL + * This class allows i-scream modules to read and even + * set their configuration from a central location. + * + * When classes want their configuration, they contact + * the Configurator, which will locate their config, + * open it and pass it to a Configuration object which is + * then passed back to the calling class. + * + * Essentially this class behaves in a similar fashion + * to the java.util.Properties class. + * + * @author $Author: ajm $ + * @version $Id: ConfigurationServant.java,v 1.10 2000/11/20 17:11:44 ajm Exp $ + */ +class ConfigurationServant extends ConfigurationPOA { + +//---FINAL ATTRIBUTES--- + + /** + * The current CVS revision of this class + */ + public final String REVISION = "$Revision: 1.10 $"; + +//---STATIC METHODS--- + +//---CONSTRUCTORS--- + + /** + * Creates a new ConfigurationServant taking a hook + * to a file containing the configuration. + * + * @param propertiesStream an InputStream connected to the configuration + */ + ConfigurationServant(Properties properties, long lastModified, Logger logRef) { + _properties = properties; + _lastModified = lastModified; + _logRef = logRef; + _logRef.write(this.toString(), Logger.SYSINIT, "created"); + String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(getLastModified())); + _logRef.write(this.toString(), Logger.SYSMSG, "last modified - " + date); + } + +//---PUBLIC METHODS--- + + /** + * A wrapper for java.util.Properties.getProperty + * When given a key it returns the value of that key + * ie, key = value + * + * @param key the key the value of which is wanted + */ + public String getProperty(String key) { + return _properties.getProperty(key); + } + + /** + * Overrides the {@link java.lang.Object#toString() Object.toString()} + * method to provide clean logging (every class should have this). + * + * @return the name of this class and its CVS revision + */ + public String toString() { + return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; + } + +//---PRIVATE METHODS--- + + protected void finalize() throws Throwable { + _logRef.write(this.toString(), Logger.DEBUG, "finalized (ick, us english!)"); + } + +//---ACCESSOR/MUTATOR METHODS--- + + /** + * Returns the date stamp of the configuration file + * this object is using. + * + * @return the last modified time for the file + */ + public long getLastModified() { + return _lastModified; + } + +//---ATTRIBUTES--- + + /** + * The properties object that this class provides a CORBA interface to + */ + private Properties _properties = new Properties(); + + /** + * Reference to a Logger + */ + private Logger _logRef; + + /** + * The date stamp of the configuration file + * this object is using + */ + private long _lastModified; + +//---STATIC ATTRIBUTES--- + +}