1 |
/* |
2 |
* i-scream central monitoring system |
3 |
* http://www.i-scream.org.uk |
4 |
* Copyright (C) 2000-2002 i-scream |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU General Public License |
8 |
* as published by the Free Software Foundation; either version 2 |
9 |
* of the License, or (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
*/ |
20 |
|
21 |
//---PACKAGE DECLARATION--- |
22 |
package uk.org.iscream.cms.server.core; |
23 |
|
24 |
//---IMPORTS--- |
25 |
import uk.org.iscream.cms.util.*; |
26 |
import uk.org.iscream.cms.server.componentmanager.*; |
27 |
import java.util.Properties; |
28 |
import java.util.Date; |
29 |
import java.text.DateFormat; |
30 |
|
31 |
/** |
32 |
* An implementation of the Configuration IDL |
33 |
* This class allows i-scream modules to read and even |
34 |
* set their configuration from a central location. |
35 |
* |
36 |
* When classes want their configuration, they contact |
37 |
* the ConfigurationManager, which will locate their config, |
38 |
* open it and pass it to a Configuration object which is |
39 |
* then passed back to the calling class. |
40 |
* |
41 |
* Essentially this class behaves in a similar fashion |
42 |
* to the java.util.Properties class. |
43 |
* |
44 |
* @author $Author: tdb $ |
45 |
* @version $Id: ConfigurationServant.java,v 1.22 2002/05/21 16:47:17 tdb Exp $ |
46 |
*/ |
47 |
class ConfigurationServant extends ConfigurationPOA { |
48 |
|
49 |
//---FINAL ATTRIBUTES--- |
50 |
|
51 |
/** |
52 |
* The current CVS revision of this class |
53 |
*/ |
54 |
public final String REVISION = "$Revision: 1.22 $"; |
55 |
|
56 |
//---STATIC METHODS--- |
57 |
|
58 |
//---CONSTRUCTORS--- |
59 |
|
60 |
/** |
61 |
* Creates a new ConfigurationServant taking a hook |
62 |
* to a Properties object containing the configuration. |
63 |
* |
64 |
* @param properties a Properties object that contains the full properties for this configuration |
65 |
* @param fileList the list of config files used to build this configuration |
66 |
* @param lastModified the most recent last modified value for the file list |
67 |
* @param logRef a reference to the logger system |
68 |
*/ |
69 |
ConfigurationServant(Properties properties, String fileList, long lastModified) { |
70 |
// assign local variables |
71 |
_properties = properties; |
72 |
_lastModified = lastModified; |
73 |
_fileList = fileList; |
74 |
_logger.write(toString(), Logger.SYSINIT, "created"); |
75 |
String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(getLastModified())); |
76 |
_logger.write(toString(), Logger.SYSMSG, "last modified - " + date); |
77 |
_logger.write(toString(), Logger.DEBUG, "file list - " + _fileList); |
78 |
} |
79 |
|
80 |
//---PUBLIC METHODS--- |
81 |
|
82 |
/** |
83 |
* A wrapper for java.util.Properties.getProperty |
84 |
* When given a key it returns the value of that key |
85 |
* ie, key = value |
86 |
* |
87 |
* @param key the key the value of which is wanted |
88 |
*/ |
89 |
public String getProperty(String key) { |
90 |
return _properties.getProperty(key); |
91 |
} |
92 |
|
93 |
/** |
94 |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
95 |
* method to provide clean logging (every class should have this). |
96 |
* |
97 |
* This uses the uk.org.iscream.cms.util.FormatName class |
98 |
* to format the toString() |
99 |
* |
100 |
* @return the name of this class and its CVS revision |
101 |
*/ |
102 |
public String toString() { |
103 |
return FormatName.getName( |
104 |
_name, |
105 |
getClass().getName(), |
106 |
REVISION); |
107 |
} |
108 |
|
109 |
/** |
110 |
* Unhooks this Configuration object from the ORB |
111 |
*/ |
112 |
public void disconnect() { |
113 |
try { |
114 |
byte[] oid = _refman.getRootPOA().servant_to_id(this); |
115 |
_refman.getRootPOA().deactivate_object(oid); |
116 |
} catch(Exception e) { |
117 |
_logger.write(this.toString(), Logger.ERROR, "disconnect failed: "+e); |
118 |
} |
119 |
} |
120 |
|
121 |
|
122 |
//---PRIVATE METHODS--- |
123 |
|
124 |
/** |
125 |
* Overridden for debugging purposes |
126 |
* to see when an instance of this class |
127 |
* is destroyed |
128 |
*/ |
129 |
protected void finalize() throws Throwable { |
130 |
_logger.write(this.toString(), Logger.DEBUG, "finalized"); |
131 |
} |
132 |
|
133 |
//---ACCESSOR/MUTATOR METHODS--- |
134 |
|
135 |
/** |
136 |
* Returns the date stamp of the configuration file |
137 |
* this object is using. |
138 |
* |
139 |
* @return the last modified time for the file |
140 |
*/ |
141 |
public long getLastModified() { |
142 |
return _lastModified; |
143 |
} |
144 |
|
145 |
/** |
146 |
* Returns the list of files used to build the Properties |
147 |
* this object is using. |
148 |
* |
149 |
* @return the list of files |
150 |
*/ |
151 |
public String getFileList() { |
152 |
return _fileList; |
153 |
} |
154 |
|
155 |
//---ATTRIBUTES--- |
156 |
|
157 |
/** |
158 |
* The properties object that this class provides a CORBA interface to |
159 |
*/ |
160 |
private Properties _properties = new Properties(); |
161 |
|
162 |
/** |
163 |
* This holds a reference to the |
164 |
* system logger that is being used. |
165 |
*/ |
166 |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
167 |
|
168 |
/** |
169 |
* A reference to the reference manager in use |
170 |
*/ |
171 |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
172 |
|
173 |
/** |
174 |
* This is the friendly identifier of the |
175 |
* component this class is running in. |
176 |
* eg, a Filter may be called "filter1", |
177 |
* If this class does not have an owning |
178 |
* component, a name from the configuration |
179 |
* can be placed here. This name could also |
180 |
* be changed to null for utility classes. |
181 |
*/ |
182 |
private String _name = Core.NAME; |
183 |
|
184 |
/** |
185 |
* The date stamp of the configuration file |
186 |
* this object is using |
187 |
*/ |
188 |
private long _lastModified; |
189 |
|
190 |
/** |
191 |
* The list of files that were used to build this configuration |
192 |
*/ |
193 |
private String _fileList; |
194 |
|
195 |
//---STATIC ATTRIBUTES--- |
196 |
|
197 |
} |