ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationServant.java
Revision: 1.23
Committed: Wed Feb 5 16:43:47 2003 UTC (21 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.22: +4 -4 lines
Log Message:
Changed the server to use the external util package. Quite a minor change,
but does affect a lot of files.

File Contents

# User Rev Content
1 tdb 1.21 /*
2     * i-scream central monitoring system
3 tdb 1.22 * http://www.i-scream.org.uk
4 tdb 1.21 * 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 tdb 1.11 //---PACKAGE DECLARATION---
22 tdb 1.20 package uk.org.iscream.cms.server.core;
23 tdb 1.11
24     //---IMPORTS---
25 tdb 1.23 import uk.org.iscream.cms.util.*;
26 tdb 1.20 import uk.org.iscream.cms.server.componentmanager.*;
27 ajm 1.14 import java.util.Properties;
28     import java.util.Date;
29 tdb 1.11 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 ajm 1.12 * the ConfigurationManager, which will locate their config,
38 tdb 1.11 * 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 tdb 1.21 * @author $Author: tdb $
45 tdb 1.23 * @version $Id: ConfigurationServant.java,v 1.22 2002/05/21 16:47:17 tdb Exp $
46 tdb 1.11 */
47     class ConfigurationServant extends ConfigurationPOA {
48    
49     //---FINAL ATTRIBUTES---
50    
51     /**
52     * The current CVS revision of this class
53     */
54 tdb 1.23 public final String REVISION = "$Revision: 1.22 $";
55 tdb 1.11
56     //---STATIC METHODS---
57    
58     //---CONSTRUCTORS---
59    
60     /**
61     * Creates a new ConfigurationServant taking a hook
62 ajm 1.12 * to a Properties object containing the configuration.
63 tdb 1.11 *
64 ajm 1.12 * @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 tdb 1.11 */
69 ajm 1.14 ConfigurationServant(Properties properties, String fileList, long lastModified) {
70 ajm 1.12 // assign local variables
71 tdb 1.11 _properties = properties;
72     _lastModified = lastModified;
73     _fileList = fileList;
74 ajm 1.14 _logger.write(toString(), Logger.SYSINIT, "created");
75 tdb 1.11 String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(getLastModified()));
76 ajm 1.14 _logger.write(toString(), Logger.SYSMSG, "last modified - " + date);
77     _logger.write(toString(), Logger.DEBUG, "file list - " + _fileList);
78 tdb 1.11 }
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 tdb 1.23 * This uses the uk.org.iscream.cms.util.FormatName class
98 ajm 1.14 * to format the toString()
99     *
100 tdb 1.11 * @return the name of this class and its CVS revision
101     */
102     public String toString() {
103 ajm 1.14 return FormatName.getName(
104     _name,
105     getClass().getName(),
106     REVISION);
107 tdb 1.11 }
108 tdb 1.17
109     /**
110     * Unhooks this Configuration object from the ORB
111     */
112 tdb 1.16 public void disconnect() {
113     try {
114 tdb 1.18 byte[] oid = _refman.getRootPOA().servant_to_id(this);
115     _refman.getRootPOA().deactivate_object(oid);
116 tdb 1.16 } catch(Exception e) {
117     _logger.write(this.toString(), Logger.ERROR, "disconnect failed: "+e);
118     }
119     }
120    
121    
122 tdb 1.11 //---PRIVATE METHODS---
123    
124 ajm 1.12 /**
125     * Overridden for debugging purposes
126     * to see when an instance of this class
127     * is destroyed
128     */
129 tdb 1.11 protected void finalize() throws Throwable {
130 ajm 1.14 _logger.write(this.toString(), Logger.DEBUG, "finalized");
131 tdb 1.11 }
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 ajm 1.12 /**
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 tdb 1.11 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 ajm 1.14 * This holds a reference to the
164     * system logger that is being used.
165 tdb 1.11 */
166 ajm 1.14 private Logger _logger = ReferenceManager.getInstance().getLogger();
167 tdb 1.16
168     /**
169     * A reference to the reference manager in use
170     */
171     private ReferenceManager _refman = ReferenceManager.getInstance();
172 ajm 1.14
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 tdb 1.11
184     /**
185     * The date stamp of the configuration file
186     * this object is using
187     */
188     private long _lastModified;
189 ajm 1.12
190     /**
191     * The list of files that were used to build this configuration
192     */
193 tdb 1.11 private String _fileList;
194    
195     //---STATIC ATTRIBUTES---
196    
197     }