1 |
tdb |
1.11 |
//---PACKAGE DECLARATION--- |
2 |
ajm |
1.13 |
package uk.ac.ukc.iscream.core; |
3 |
tdb |
1.11 |
|
4 |
|
|
//---IMPORTS--- |
5 |
ajm |
1.14 |
import uk.ac.ukc.iscream.util.*; |
6 |
tdb |
1.15 |
import uk.ac.ukc.iscream.componentmanager.*; |
7 |
ajm |
1.14 |
import java.util.Properties; |
8 |
|
|
import java.util.Date; |
9 |
tdb |
1.11 |
import java.text.DateFormat; |
10 |
|
|
|
11 |
|
|
/** |
12 |
|
|
* An implementation of the Configuration IDL |
13 |
|
|
* This class allows i-scream modules to read and even |
14 |
|
|
* set their configuration from a central location. |
15 |
|
|
* |
16 |
|
|
* When classes want their configuration, they contact |
17 |
ajm |
1.12 |
* the ConfigurationManager, which will locate their config, |
18 |
tdb |
1.11 |
* open it and pass it to a Configuration object which is |
19 |
|
|
* then passed back to the calling class. |
20 |
|
|
* |
21 |
|
|
* Essentially this class behaves in a similar fashion |
22 |
|
|
* to the java.util.Properties class. |
23 |
|
|
* |
24 |
tdb |
1.16 |
* @author $Author: tdb1 $ |
25 |
|
|
* @version $Id: ConfigurationServant.java,v 1.15 2001/01/18 23:10:44 tdb1 Exp $ |
26 |
tdb |
1.11 |
*/ |
27 |
|
|
class ConfigurationServant extends ConfigurationPOA { |
28 |
|
|
|
29 |
|
|
//---FINAL ATTRIBUTES--- |
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
* The current CVS revision of this class |
33 |
|
|
*/ |
34 |
tdb |
1.16 |
public final String REVISION = "$Revision: 1.15 $"; |
35 |
tdb |
1.11 |
|
36 |
|
|
//---STATIC METHODS--- |
37 |
|
|
|
38 |
|
|
//---CONSTRUCTORS--- |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* Creates a new ConfigurationServant taking a hook |
42 |
ajm |
1.12 |
* to a Properties object containing the configuration. |
43 |
tdb |
1.11 |
* |
44 |
ajm |
1.12 |
* @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 |
tdb |
1.11 |
*/ |
49 |
ajm |
1.14 |
ConfigurationServant(Properties properties, String fileList, long lastModified) { |
50 |
ajm |
1.12 |
// assign local variables |
51 |
tdb |
1.11 |
_properties = properties; |
52 |
|
|
_lastModified = lastModified; |
53 |
|
|
_fileList = fileList; |
54 |
ajm |
1.14 |
_logger.write(toString(), Logger.SYSINIT, "created"); |
55 |
tdb |
1.11 |
String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(getLastModified())); |
56 |
ajm |
1.14 |
_logger.write(toString(), Logger.SYSMSG, "last modified - " + date); |
57 |
|
|
_logger.write(toString(), Logger.DEBUG, "file list - " + _fileList); |
58 |
tdb |
1.11 |
} |
59 |
|
|
|
60 |
|
|
//---PUBLIC METHODS--- |
61 |
|
|
|
62 |
|
|
/** |
63 |
|
|
* A wrapper for java.util.Properties.getProperty |
64 |
|
|
* When given a key it returns the value of that key |
65 |
|
|
* ie, key = value |
66 |
|
|
* |
67 |
|
|
* @param key the key the value of which is wanted |
68 |
|
|
*/ |
69 |
|
|
public String getProperty(String key) { |
70 |
|
|
return _properties.getProperty(key); |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
/** |
74 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
75 |
|
|
* method to provide clean logging (every class should have this). |
76 |
|
|
* |
77 |
ajm |
1.14 |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
78 |
|
|
* to format the toString() |
79 |
|
|
* |
80 |
tdb |
1.11 |
* @return the name of this class and its CVS revision |
81 |
|
|
*/ |
82 |
|
|
public String toString() { |
83 |
ajm |
1.14 |
return FormatName.getName( |
84 |
|
|
_name, |
85 |
|
|
getClass().getName(), |
86 |
|
|
REVISION); |
87 |
tdb |
1.11 |
} |
88 |
|
|
|
89 |
tdb |
1.16 |
public void disconnect() { |
90 |
|
|
try { |
91 |
|
|
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(this); |
92 |
|
|
_refman.getORB().disconnect(objRef); |
93 |
|
|
} catch(Exception e) { |
94 |
|
|
_logger.write(this.toString(), Logger.ERROR, "disconnect failed: "+e); |
95 |
|
|
} |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
|
99 |
tdb |
1.11 |
//---PRIVATE METHODS--- |
100 |
|
|
|
101 |
ajm |
1.12 |
/** |
102 |
|
|
* Overridden for debugging purposes |
103 |
|
|
* to see when an instance of this class |
104 |
|
|
* is destroyed |
105 |
|
|
*/ |
106 |
tdb |
1.11 |
protected void finalize() throws Throwable { |
107 |
ajm |
1.14 |
_logger.write(this.toString(), Logger.DEBUG, "finalized"); |
108 |
tdb |
1.11 |
} |
109 |
|
|
|
110 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
111 |
|
|
|
112 |
|
|
/** |
113 |
|
|
* Returns the date stamp of the configuration file |
114 |
|
|
* this object is using. |
115 |
|
|
* |
116 |
|
|
* @return the last modified time for the file |
117 |
|
|
*/ |
118 |
|
|
public long getLastModified() { |
119 |
|
|
return _lastModified; |
120 |
|
|
} |
121 |
|
|
|
122 |
ajm |
1.12 |
/** |
123 |
|
|
* Returns the list of files used to build the Properties |
124 |
|
|
* this object is using. |
125 |
|
|
* |
126 |
|
|
* @return the list of files |
127 |
|
|
*/ |
128 |
tdb |
1.11 |
public String getFileList() { |
129 |
|
|
return _fileList; |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
//---ATTRIBUTES--- |
133 |
|
|
|
134 |
|
|
/** |
135 |
|
|
* The properties object that this class provides a CORBA interface to |
136 |
|
|
*/ |
137 |
|
|
private Properties _properties = new Properties(); |
138 |
|
|
|
139 |
|
|
/** |
140 |
ajm |
1.14 |
* This holds a reference to the |
141 |
|
|
* system logger that is being used. |
142 |
tdb |
1.11 |
*/ |
143 |
ajm |
1.14 |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
144 |
tdb |
1.16 |
|
145 |
|
|
/** |
146 |
|
|
* A reference to the reference manager in use |
147 |
|
|
*/ |
148 |
|
|
private ReferenceManager _refman = ReferenceManager.getInstance(); |
149 |
ajm |
1.14 |
|
150 |
|
|
/** |
151 |
|
|
* This is the friendly identifier of the |
152 |
|
|
* component this class is running in. |
153 |
|
|
* eg, a Filter may be called "filter1", |
154 |
|
|
* If this class does not have an owning |
155 |
|
|
* component, a name from the configuration |
156 |
|
|
* can be placed here. This name could also |
157 |
|
|
* be changed to null for utility classes. |
158 |
|
|
*/ |
159 |
|
|
private String _name = Core.NAME; |
160 |
tdb |
1.11 |
|
161 |
|
|
/** |
162 |
|
|
* The date stamp of the configuration file |
163 |
|
|
* this object is using |
164 |
|
|
*/ |
165 |
|
|
private long _lastModified; |
166 |
ajm |
1.12 |
|
167 |
|
|
/** |
168 |
|
|
* The list of files that were used to build this configuration |
169 |
|
|
*/ |
170 |
tdb |
1.11 |
private String _fileList; |
171 |
|
|
|
172 |
|
|
//---STATIC ATTRIBUTES--- |
173 |
|
|
|
174 |
|
|
} |