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