1 |
|
//---PACKAGE DECLARATION--- |
2 |
+ |
package uk.ac.ukc.iscream.core; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.core.*; |
6 |
< |
import java.util.*; |
7 |
< |
import java.io.*; |
5 |
> |
import uk.ac.ukc.iscream.util.*; |
6 |
> |
import uk.ac.ukc.iscream.componentmanager.*; |
7 |
> |
import java.util.Properties; |
8 |
> |
import java.util.Date; |
9 |
> |
import java.text.DateFormat; |
10 |
|
|
11 |
|
/** |
12 |
|
* An implementation of the Configuration IDL |
14 |
|
* set their configuration from a central location. |
15 |
|
* |
16 |
|
* When classes want their configuration, they contact |
17 |
< |
* the Configurator, which will locate their config, |
17 |
> |
* the ConfigurationManager, which will locate their config, |
18 |
|
* open it and pass it to a Configuration object which is |
19 |
|
* then passed back to the calling class. |
20 |
|
* |
39 |
|
|
40 |
|
/** |
41 |
|
* Creates a new ConfigurationServant taking a hook |
42 |
< |
* to a file containing the configuration. |
42 |
> |
* to a Properties object containing the configuration. |
43 |
|
* |
44 |
< |
* @param propertiesStream an InputStream connected to the configuration |
44 |
> |
* @param properties a Properties object that contains the full properties for this configuration |
45 |
> |
* @param fileList the list of config files used to build this configuration |
46 |
> |
* @param lastModified the most recent last modified value for the file list |
47 |
> |
* @param logRef a reference to the logger system |
48 |
|
*/ |
49 |
< |
ConfigurationServant(File configurationFile, Logger logRef) { |
50 |
< |
_lastModified = configurationFile.lastModified(); |
51 |
< |
|
52 |
< |
_logRef = logRef; |
53 |
< |
_logRef.write(this.toString(), "created - last modified:" + getLastModified()); |
54 |
< |
|
55 |
< |
try { |
56 |
< |
InputStream configurationStream = new FileInputStream(configurationFile); |
57 |
< |
_properties.load(configurationStream); |
52 |
< |
} catch (Exception e) { |
53 |
< |
// **************************************** |
54 |
< |
// either IOException from the .load() or |
55 |
< |
// a SecurityException or FileNotFoundException from |
56 |
< |
// the inputStream, not sure what to do yet!!! |
57 |
< |
} |
49 |
> |
ConfigurationServant(Properties properties, String fileList, long lastModified) { |
50 |
> |
// assign local variables |
51 |
> |
_properties = properties; |
52 |
> |
_lastModified = lastModified; |
53 |
> |
_fileList = fileList; |
54 |
> |
_logger.write(toString(), Logger.SYSINIT, "created"); |
55 |
> |
String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(getLastModified())); |
56 |
> |
_logger.write(toString(), Logger.SYSMSG, "last modified - " + date); |
57 |
> |
_logger.write(toString(), Logger.DEBUG, "file list - " + _fileList); |
58 |
|
} |
59 |
|
|
60 |
|
//---PUBLIC METHODS--- |
71 |
|
} |
72 |
|
|
73 |
|
/** |
74 |
< |
* Overrides the {@link #java.lang.Object.toString() Object.toString()} |
74 |
> |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
75 |
|
* method to provide clean logging (every class should have this). |
76 |
|
* |
77 |
+ |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
78 |
+ |
* to format the toString() |
79 |
+ |
* |
80 |
|
* @return the name of this class and its CVS revision |
81 |
|
*/ |
82 |
|
public String toString() { |
83 |
< |
return this.getClass().getName() + ":" + REVISION; |
83 |
> |
return FormatName.getName( |
84 |
> |
_name, |
85 |
> |
getClass().getName(), |
86 |
> |
REVISION); |
87 |
|
} |
88 |
|
|
89 |
|
//---PRIVATE METHODS--- |
90 |
|
|
91 |
+ |
/** |
92 |
+ |
* Overridden for debugging purposes |
93 |
+ |
* to see when an instance of this class |
94 |
+ |
* is destroyed |
95 |
+ |
*/ |
96 |
+ |
protected void finalize() throws Throwable { |
97 |
+ |
_logger.write(this.toString(), Logger.DEBUG, "finalized"); |
98 |
+ |
} |
99 |
+ |
|
100 |
|
//---ACCESSOR/MUTATOR METHODS--- |
101 |
|
|
102 |
|
/** |
109 |
|
return _lastModified; |
110 |
|
} |
111 |
|
|
112 |
+ |
/** |
113 |
+ |
* Returns the list of files used to build the Properties |
114 |
+ |
* this object is using. |
115 |
+ |
* |
116 |
+ |
* @return the list of files |
117 |
+ |
*/ |
118 |
+ |
public String getFileList() { |
119 |
+ |
return _fileList; |
120 |
+ |
} |
121 |
+ |
|
122 |
|
//---ATTRIBUTES--- |
123 |
|
|
124 |
|
/** |
127 |
|
private Properties _properties = new Properties(); |
128 |
|
|
129 |
|
/** |
130 |
< |
* Reference to a Logger |
130 |
> |
* This holds a reference to the |
131 |
> |
* system logger that is being used. |
132 |
|
*/ |
133 |
< |
private Logger _logRef; |
133 |
> |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
134 |
> |
|
135 |
> |
/** |
136 |
> |
* This is the friendly identifier of the |
137 |
> |
* component this class is running in. |
138 |
> |
* eg, a Filter may be called "filter1", |
139 |
> |
* If this class does not have an owning |
140 |
> |
* component, a name from the configuration |
141 |
> |
* can be placed here. This name could also |
142 |
> |
* be changed to null for utility classes. |
143 |
> |
*/ |
144 |
> |
private String _name = Core.NAME; |
145 |
|
|
146 |
|
/** |
147 |
|
* The date stamp of the configuration file |
148 |
|
* this object is using |
149 |
|
*/ |
150 |
|
private long _lastModified; |
151 |
+ |
|
152 |
+ |
/** |
153 |
+ |
* The list of files that were used to build this configuration |
154 |
+ |
*/ |
155 |
+ |
private String _fileList; |
156 |
|
|
157 |
|
//---STATIC ATTRIBUTES--- |
158 |
|
|