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.7 by tdb, Thu Jan 18 23:10:44 2001 UTC vs.
Revision 1.8 by ajm, Thu Mar 1 19:18:38 2001 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines