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.21
Committed: Sat May 18 18:16:01 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.20: +22 -3 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

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