1 |
tdb |
1.11 |
//---PACKAGE DECLARATION--- |
2 |
|
|
|
3 |
|
|
//---IMPORTS--- |
4 |
|
|
import uk.ac.ukc.iscream.core.*; |
5 |
|
|
import java.util.*; |
6 |
|
|
import java.io.*; |
7 |
|
|
import java.text.DateFormat; |
8 |
|
|
|
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 |
|
|
* @author $Author: ajm4 $ |
23 |
|
|
* @version $Id: ConfigurationServant.java,v 1.10 2000/11/20 17:11:44 ajm4 Exp $ |
24 |
|
|
*/ |
25 |
|
|
class ConfigurationServant extends ConfigurationPOA { |
26 |
|
|
|
27 |
|
|
//---FINAL ATTRIBUTES--- |
28 |
|
|
|
29 |
|
|
/** |
30 |
|
|
* The current CVS revision of this class |
31 |
|
|
*/ |
32 |
|
|
public final String REVISION = "$Revision: 1.10 $"; |
33 |
|
|
|
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 |
|
|
ConfigurationServant(Properties properties, String fileList, long lastModified, Logger logRef) { |
45 |
|
|
_properties = properties; |
46 |
|
|
_lastModified = lastModified; |
47 |
|
|
_fileList = fileList; |
48 |
|
|
_logRef = logRef; |
49 |
|
|
_logRef.write(this.toString(), Logger.SYSINIT, "created"); |
50 |
|
|
String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(getLastModified())); |
51 |
|
|
_logRef.write(this.toString(), Logger.SYSMSG, "last modified - " + date); |
52 |
|
|
_logRef.write(this.toString(), Logger.DEBUG, "file list - " + _fileList); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
//---PUBLIC METHODS--- |
56 |
|
|
|
57 |
|
|
/** |
58 |
|
|
* A wrapper for java.util.Properties.getProperty |
59 |
|
|
* When given a key it returns the value of that key |
60 |
|
|
* ie, key = value |
61 |
|
|
* |
62 |
|
|
* @param key the key the value of which is wanted |
63 |
|
|
*/ |
64 |
|
|
public String getProperty(String key) { |
65 |
|
|
return _properties.getProperty(key); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
/** |
69 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
70 |
|
|
* method to provide clean logging (every class should have this). |
71 |
|
|
* |
72 |
|
|
* @return the name of this class and its CVS revision |
73 |
|
|
*/ |
74 |
|
|
public String toString() { |
75 |
|
|
return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
//---PRIVATE METHODS--- |
79 |
|
|
|
80 |
|
|
protected void finalize() throws Throwable { |
81 |
|
|
_logRef.write(this.toString(), Logger.DEBUG, "finalized (ick, us english!)"); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
85 |
|
|
|
86 |
|
|
/** |
87 |
|
|
* Returns the date stamp of the configuration file |
88 |
|
|
* this object is using. |
89 |
|
|
* |
90 |
|
|
* @return the last modified time for the file |
91 |
|
|
*/ |
92 |
|
|
public long getLastModified() { |
93 |
|
|
return _lastModified; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
public String getFileList() { |
97 |
|
|
return _fileList; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
//---ATTRIBUTES--- |
101 |
|
|
|
102 |
|
|
/** |
103 |
|
|
* The properties object that this class provides a CORBA interface to |
104 |
|
|
*/ |
105 |
|
|
private Properties _properties = new Properties(); |
106 |
|
|
|
107 |
|
|
/** |
108 |
|
|
* Reference to a Logger |
109 |
|
|
*/ |
110 |
|
|
private Logger _logRef; |
111 |
|
|
|
112 |
|
|
/** |
113 |
|
|
* The date stamp of the configuration file |
114 |
|
|
* this object is using |
115 |
|
|
*/ |
116 |
|
|
private long _lastModified; |
117 |
|
|
|
118 |
|
|
private String _fileList; |
119 |
|
|
|
120 |
|
|
//---STATIC ATTRIBUTES--- |
121 |
|
|
|
122 |
|
|
} |