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/ConfigurationManagerServant.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationManagerServant.java (file contents):
Revision 1.6 by ajm, Tue Dec 12 18:26:52 2000 UTC vs.
Revision 1.10 by ajm, Thu Mar 1 19:36:08 2001 UTC

# Line 3 | Line 3 | package uk.ac.ukc.iscream.core;
3  
4   //---IMPORTS---
5   import uk.ac.ukc.iscream.util.*;
6 + import uk.ac.ukc.iscream.componentmanager.*;
7   import java.util.*;
8   import java.io.*;
9  
# Line 79 | Line 80 | class ConfigurationManagerServant extends Configuratio
80       */
81      public Configuration getConfiguration(String source) {
82          _logger.write(toString(), Logger.SYSMSG, "got request for " + source);
83 <        Configuration config = null;
83 >
84          
85          // check to see if we need to reload the system config
86          // because it has changed
# Line 88 | Line 89 | class ConfigurationManagerServant extends Configuratio
89              loadSystemConfig();
90          }
91  
92 <        // we look for this entry in the systemConfig
93 <        String configFile = _systemConfig.getProperty("config." + source);
93 <        _logger.write(toString(), Logger.DEBUG, "looking for config tree in - " + configFile);
92 >        // search config for group membership
93 >        LinkedList groups = getGroupMembership(source);
94  
95 <        // if there is an entry
96 <        if (configFile != null) {
97 <            try {
98 <                // get the file list of includes etc + the system config
99 <                String fileList = _systemConfigFile + ";" + getIncludedFiles(configFile, "");            
100 <                _logger.write(toString(), Logger.DEBUG, "config tree - " + fileList);
101 <                
102 <                // build the properites here from the filelist....
103 <                StringTokenizer st = new StringTokenizer(fileList, ";");
104 <                
105 <                // some holders for variables
106 <                File currentFile;
107 <                long lastModified, newLastModified;
108 <                Properties properties, prevProperties;
109 <                
110 <                // the root of all configurations will be the system config
111 <                // so we need to open the properties of that
112 <                Properties defaultProperties = new Properties();
113 <                currentFile = new File(_configPath, _systemConfigFile);
114 <                lastModified = currentFile.lastModified();
115 <                defaultProperties.load(new FileInputStream(currentFile));
116 <                
117 <                // This loop then iterates over the file list
118 <                // creates the properties to be passed to the
119 <                // Configuration constructor
120 <                do {
121 <                    properties = new Properties(defaultProperties);
122 <                    currentFile = new File(_configPath, st.nextToken());
123 <                    newLastModified = currentFile.lastModified();
124 <                    if (newLastModified > lastModified) {
125 <                        lastModified = newLastModified;
126 <                    }
127 <                    properties.load(new FileInputStream(currentFile));
128 <                    defaultProperties = properties;
129 <                } while (st.hasMoreTokens());
95 >        // add the hosts individual config to the start of the list
96 >        groups.addFirst(source);
97  
98 <                // this creates the configuration, all nice, ready to be returned
99 <                ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified);
100 <                org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
101 <                config = ConfigurationHelper.narrow(objRef);
98 >        Iterator i = groups.iterator();
99 >        String fileList = "";
100 >        while (i.hasNext()) {
101 >            String groupName = (String) i.next();
102  
103 +            // we look for this entry in the systemConfig
104 +            String configFile = _systemConfig.getProperty("config." + groupName);
105 +            _logger.write(toString(), Logger.DEBUG, "looking for config tree in - " + configFile);
106 +
107 +            // get the file list of includes etc + the system config
108 +            String groupFileList = null;
109 +            try {
110 +                groupFileList = getIncludedFiles(configFile, "") + ";";
111              } catch (Exception e) {
112                  // not sure what to do here
113                  // so we just log the error
114 <                _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
114 >                _logger.write(toString(), Logger.ERROR, "ERROR - " + e);
115              }
116 <            
117 <        // if there isn't an entry for the requested config
118 <        } else {
144 <            _logger.write(toString(), Logger.DEBUG, "no configured config, returning " + _systemConfigFile);
145 <            config = _systemConfig;
116 >            if (groupFileList != null) {
117 >                fileList += groupFileList;
118 >            }
119          }
120 +        // add the system config as the final check
121 +        fileList += _systemConfigFile + ";";
122 +        _logger.write(toString(), Logger.DEBUG, "config tree - " + fileList);
123          
124 +        // build the configuration
125 +        Configuration config = buildConfiguration(fileList);
126 +        
127          // if this is null at this point, then there will have been an error
128          return config;
129      }
# Line 270 | Line 249 | class ConfigurationManagerServant extends Configuratio
249          try {
250              // create the properties for the configuration
251              File systemConfigFile = new File(_configPath, _systemConfigFile);
252 <            Properties systemConfigHolder = new Properties();
253 <            systemConfigHolder.load(new FileInputStream(systemConfigFile));
254 <                        
252 >            _systemConfigHolder = new Properties();
253 >            _systemConfigHolder.load(new FileInputStream(systemConfigFile));
254 >            
255              // create the servant
256 <            ConfigurationServant ref = new ConfigurationServant(systemConfigHolder, _systemConfigFile, systemConfigFile.lastModified());
256 >            ConfigurationServant ref = new ConfigurationServant(_systemConfigHolder, _systemConfigFile, systemConfigFile.lastModified());
257              org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
258              
259              // narrow it to a Configuration
# Line 285 | Line 264 | class ConfigurationManagerServant extends Configuratio
264          }
265      }
266  
267 +    /**
268 +     * Parses the system configuration file
269 +     * for group membership entries.
270 +     *
271 +     * It looks for all entries of group.<name>
272 +     * which contain the given source name
273 +     *
274 +     * @param source the source to find membership for
275 +     *
276 +     * @return the list of groups that this source is a member of
277 +     */
278 +    private LinkedList getGroupMembership(String source) {
279 +        LinkedList groupMembership = new LinkedList();        
280 +        Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator();
281 +        while(i.hasNext()) {
282 +            String key = (String) i.next();
283 +            if (key.startsWith("group.")) {
284 +                String group = _systemConfig.getProperty(key);
285 +                if (group.indexOf(source) != -1) {
286 +                    groupMembership.add(key.substring(6));
287 +                }
288 +            }  
289 +        }
290 +        return groupMembership;
291 +    }    
292 +
293 +    /**
294 +     * Build the properties as a Configuration to be
295 +     * returned to the caller
296 +     *
297 +     * @param fileList the list of files to build the configuration from
298 +     *
299 +     * @return the built Configuration
300 +     */
301 +    private Configuration buildConfiguration(String fileList) {
302 +        Configuration config = null;
303 +
304 +        // if there is an entry
305 +        if (!fileList.equals("")) {
306 +            try {
307 +                
308 +                // build the properites here from the filelist....
309 +                StringTokenizer st = new StringTokenizer(fileList, ";");
310 +                
311 +                // some holders for variables
312 +                File currentFile;
313 +                long lastModified, newLastModified;
314 +                Properties properties, prevProperties;
315 +                
316 +                // the root of all configurations will be the system config
317 +                // so we need to open the properties of that
318 +                Properties defaultProperties = new Properties();
319 +                currentFile = new File(_configPath, _systemConfigFile);
320 +                lastModified = currentFile.lastModified();
321 +                defaultProperties.load(new FileInputStream(currentFile));
322 +                
323 +                // This loop then iterates over the file list
324 +                // creates the properties to be passed to the
325 +                // Configuration constructor
326 +                do {
327 +                    properties = new Properties(defaultProperties);
328 +                    currentFile = new File(_configPath, st.nextToken());
329 +                    newLastModified = currentFile.lastModified();
330 +                    if (newLastModified > lastModified) {
331 +                        lastModified = newLastModified;
332 +                    }
333 +                    properties.load(new FileInputStream(currentFile));
334 +                    defaultProperties = properties;
335 +                } while (st.hasMoreTokens());
336 +
337 +                // this creates the configuration, all nice, ready to be returned
338 +                ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified);
339 +                org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
340 +                config = ConfigurationHelper.narrow(objRef);
341 +
342 +            } catch (Exception e) {
343 +                // not sure what to do here
344 +                // so we just log the error
345 +                _logger.write(toString(), Logger.ERROR, "ERROR - " + e);
346 +            }
347 +            
348 +        // if there isn't an entry for the requested config
349 +        } else {
350 +            _logger.write(toString(), Logger.DEBUG, "no configured config, returning " + _systemConfigFile);
351 +            config = _systemConfig;
352 +        }
353 +        return config;
354 +    }
355 +
356   //---ACCESSOR/MUTATOR METHODS---
357  
358   //---ATTRIBUTES---
# Line 325 | Line 393 | class ConfigurationManagerServant extends Configuratio
393       * An instance of the system config
394       */
395      private Configuration _systemConfig;
396 +    
397 +    /**
398 +     * The system config file represented by a
399 +     * properties object.
400 +     */
401 +    private Properties _systemConfigHolder;
402      
403   //---STATIC ATTRIBUTES---
404      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines