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.11 by ajm, Thu Mar 1 19:42:20 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);
102 <
103 <            } catch (Exception e) {
104 <                // not sure what to do here
105 <                // so we just log the error
106 <                _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
107 <            }
108 <            
109 <        // if there isn't an entry for the requested config
110 <        } else {
111 <            _logger.write(toString(), Logger.DEBUG, "no configured config, returning " + _systemConfigFile);
112 <            config = _systemConfig;
98 >        Iterator i = groups.iterator();
99 >        String fileList = "";
100 >        while (i.hasNext()) {
101 >            String groupName = (String) i.next();
102 >            _logger.write(toString(), Logger.DEBUG, "looking for config entry for - " + groupName);
103 >            // we look for this entry in the systemConfig
104 >            String configFile = _systemConfig.getProperty("config." + groupName);
105 >            // if there is a config entry then
106 >            if (configFile != null) {
107 >                _logger.write(toString(), Logger.DEBUG, "looking for config tree in - " + configFile);
108 >    
109 >                // get the file list of includes etc + the system config
110 >                String groupFileList = null;
111 >                try {
112 >                    groupFileList = getIncludedFiles(configFile, "") + ";";
113 >                } catch (Exception e) {
114 >                    // not sure what to do here
115 >                    // so we just log the error
116 >                    _logger.write(toString(), Logger.ERROR, "ERROR - " + e);
117 >                }
118 >                if (groupFileList != null) {
119 >                    fileList += groupFileList;
120 >                }
121 >            } else {
122 >                _logger.write(toString(), Logger.DEBUG, "no config entry for - " + groupName);
123          }
124 +        // add the system config as the final check
125 +        fileList += _systemConfigFile + ";";
126 +        _logger.write(toString(), Logger.DEBUG, "config tree - " + fileList);
127          
128 +        // build the configuration
129 +        Configuration config = buildConfiguration(fileList);
130 +        
131          // if this is null at this point, then there will have been an error
132          return config;
133      }
# Line 270 | Line 253 | class ConfigurationManagerServant extends Configuratio
253          try {
254              // create the properties for the configuration
255              File systemConfigFile = new File(_configPath, _systemConfigFile);
256 <            Properties systemConfigHolder = new Properties();
257 <            systemConfigHolder.load(new FileInputStream(systemConfigFile));
258 <                        
256 >            _systemConfigHolder = new Properties();
257 >            _systemConfigHolder.load(new FileInputStream(systemConfigFile));
258 >            
259              // create the servant
260 <            ConfigurationServant ref = new ConfigurationServant(systemConfigHolder, _systemConfigFile, systemConfigFile.lastModified());
260 >            ConfigurationServant ref = new ConfigurationServant(_systemConfigHolder, _systemConfigFile, systemConfigFile.lastModified());
261              org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
262              
263              // narrow it to a Configuration
# Line 285 | Line 268 | class ConfigurationManagerServant extends Configuratio
268          }
269      }
270  
271 +    /**
272 +     * Parses the system configuration file
273 +     * for group membership entries.
274 +     *
275 +     * It looks for all entries of group.<name>
276 +     * which contain the given source name
277 +     *
278 +     * @param source the source to find membership for
279 +     *
280 +     * @return the list of groups that this source is a member of
281 +     */
282 +    private LinkedList getGroupMembership(String source) {
283 +        LinkedList groupMembership = new LinkedList();        
284 +        Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator();
285 +        while(i.hasNext()) {
286 +            String key = (String) i.next();
287 +            if (key.startsWith("group.")) {
288 +                String group = _systemConfig.getProperty(key);
289 +                if (group.indexOf(source) != -1) {
290 +                    groupMembership.add(key.substring(6));
291 +                }
292 +            }  
293 +        }
294 +        return groupMembership;
295 +    }    
296 +
297 +    /**
298 +     * Build the properties as a Configuration to be
299 +     * returned to the caller
300 +     *
301 +     * @param fileList the list of files to build the configuration from
302 +     *
303 +     * @return the built Configuration
304 +     */
305 +    private Configuration buildConfiguration(String fileList) {
306 +        Configuration config = null;
307 +
308 +        // if there is an entry
309 +        if (!fileList.equals("")) {
310 +            try {
311 +                
312 +                // build the properites here from the filelist....
313 +                StringTokenizer st = new StringTokenizer(fileList, ";");
314 +                
315 +                // some holders for variables
316 +                File currentFile;
317 +                long lastModified, newLastModified;
318 +                Properties properties, prevProperties;
319 +                
320 +                // the root of all configurations will be the system config
321 +                // so we need to open the properties of that
322 +                Properties defaultProperties = new Properties();
323 +                currentFile = new File(_configPath, _systemConfigFile);
324 +                lastModified = currentFile.lastModified();
325 +                defaultProperties.load(new FileInputStream(currentFile));
326 +                
327 +                // This loop then iterates over the file list
328 +                // creates the properties to be passed to the
329 +                // Configuration constructor
330 +                do {
331 +                    properties = new Properties(defaultProperties);
332 +                    currentFile = new File(_configPath, st.nextToken());
333 +                    newLastModified = currentFile.lastModified();
334 +                    if (newLastModified > lastModified) {
335 +                        lastModified = newLastModified;
336 +                    }
337 +                    properties.load(new FileInputStream(currentFile));
338 +                    defaultProperties = properties;
339 +                } while (st.hasMoreTokens());
340 +
341 +                // this creates the configuration, all nice, ready to be returned
342 +                ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified);
343 +                org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
344 +                config = ConfigurationHelper.narrow(objRef);
345 +
346 +            } catch (Exception e) {
347 +                // not sure what to do here
348 +                // so we just log the error
349 +                _logger.write(toString(), Logger.ERROR, "ERROR - " + e);
350 +            }
351 +            
352 +        // if there isn't an entry for the requested config
353 +        } else {
354 +            _logger.write(toString(), Logger.DEBUG, "no configured config, returning " + _systemConfigFile);
355 +            config = _systemConfig;
356 +        }
357 +        return config;
358 +    }
359 +
360   //---ACCESSOR/MUTATOR METHODS---
361  
362   //---ATTRIBUTES---
# Line 325 | Line 397 | class ConfigurationManagerServant extends Configuratio
397       * An instance of the system config
398       */
399      private Configuration _systemConfig;
400 +    
401 +    /**
402 +     * The system config file represented by a
403 +     * properties object.
404 +     */
405 +    private Properties _systemConfigHolder;
406      
407   //---STATIC ATTRIBUTES---
408      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines