ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationServant.java
Revision: 1.8
Committed: Thu Nov 16 18:02:11 2000 UTC (23 years, 6 months ago) by tdb
Branch: MAIN
Changes since 1.7: +3 -3 lines
Log Message:
Added support for the new verbosity features in the loggers.

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2    
3     //---IMPORTS---
4 tdb 1.4 import uk.ac.ukc.iscream.core.*;
5 ajm 1.1 import java.util.*;
6     import java.io.*;
7 tdb 1.7 import java.text.DateFormat;
8 ajm 1.1
9     /**
10     * An implementation of the Configuration IDL
11     * This class allows i-scream modules to read and even
12     * set their configuration from a central location.
13     *
14     * When classes want their configuration, they contact
15     * the Configurator, which will locate their config,
16     * open it and pass it to a Configuration object which is
17     * then passed back to the calling class.
18     *
19     * Essentially this class behaves in a similar fashion
20     * to the java.util.Properties class.
21     *
22 tdb 1.3 * @author $Author: tdb1 $
23 tdb 1.8 * @version $Id: ConfigurationServant.java,v 1.7 2000/11/13 18:34:12 tdb1 Exp $
24 ajm 1.1 */
25     class ConfigurationServant extends ConfigurationPOA {
26    
27     //---FINAL ATTRIBUTES---
28    
29     /**
30     * The current CVS revision of this class
31     */
32 tdb 1.8 public final String REVISION = "$Revision: 1.7 $";
33 ajm 1.1
34     //---STATIC METHODS---
35    
36     //---CONSTRUCTORS---
37    
38     /**
39     * Creates a new ConfigurationServant taking a hook
40     * to a file containing the configuration.
41     *
42     * @param propertiesStream an InputStream connected to the configuration
43     */
44 tdb 1.2 ConfigurationServant(File configurationFile, Logger logRef) {
45 tdb 1.3 _lastModified = configurationFile.lastModified();
46 tdb 1.7 _logRef = logRef;
47 tdb 1.3
48 tdb 1.7 String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(getLastModified()));
49 tdb 1.8 _logRef.write(this.toString(), Logger.SYSMSG, "created: " + configurationFile.getName() + "(" + date + ")" );
50 tdb 1.3
51 ajm 1.1 try {
52     InputStream configurationStream = new FileInputStream(configurationFile);
53 tdb 1.2 _properties.load(configurationStream);
54 ajm 1.1 } catch (Exception e) {
55     // ****************************************
56     // either IOException from the .load() or
57     // a SecurityException or FileNotFoundException from
58     // the inputStream, not sure what to do yet!!!
59     }
60     }
61    
62     //---PUBLIC METHODS---
63    
64     /**
65     * A wrapper for java.util.Properties.getProperty
66     * When given a key it returns the value of that key
67     * ie, key = value
68     *
69     * @param key the key the value of which is wanted
70     */
71     public String getProperty(String key) {
72 tdb 1.2 return _properties.getProperty(key);
73 ajm 1.1 }
74    
75     /**
76 tdb 1.5 * Overrides the {@link java.lang.Object#toString() Object.toString()}
77 ajm 1.1 * method to provide clean logging (every class should have this).
78     *
79     * @return the name of this class and its CVS revision
80     */
81     public String toString() {
82 tdb 1.6 return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
83 ajm 1.1 }
84    
85     //---PRIVATE METHODS---
86    
87     //---ACCESSOR/MUTATOR METHODS---
88    
89 tdb 1.3 /**
90     * Returns the date stamp of the configuration file
91     * this object is using.
92     *
93     * @return the last modified time for the file
94     */
95     public long getLastModified() {
96     return _lastModified;
97     }
98    
99 ajm 1.1 //---ATTRIBUTES---
100    
101     /**
102     * The properties object that this class provides a CORBA interface to
103     */
104 tdb 1.2 private Properties _properties = new Properties();
105    
106     /**
107     * Reference to a Logger
108     */
109     private Logger _logRef;
110 ajm 1.1
111 tdb 1.3 /**
112     * The date stamp of the configuration file
113     * this object is using
114     */
115     private long _lastModified;
116    
117 ajm 1.1 //---STATIC ATTRIBUTES---
118    
119 tdb 1.2 }