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.12 by tdb, Thu Mar 1 20:22:21 2001 UTC vs.
Revision 1.20 by tdb, Mon Dec 10 22:49:19 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.core;
2 > package uk.org.iscream.cms.server.core;
3  
4   //---IMPORTS---
5 < import uk.ac.ukc.iscream.util.*;
6 < import uk.ac.ukc.iscream.componentmanager.*;
5 > import uk.org.iscream.cms.server.util.*;
6 > import uk.org.iscream.cms.server.componentmanager.*;
7 > import java.net.InetAddress;
8 > import java.net.UnknownHostException;
9   import java.util.*;
10   import java.io.*;
11  
# Line 45 | Line 47 | class ConfigurationManagerServant extends Configuratio
47       */
48      ConfigurationManagerServant() {
49          // assign some local variables
50 <        _configPath = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation");
51 <        _systemConfigFile = System.getProperty("uk.ac.ukc.iscream.SystemConfigurationFile");
50 >        _configPath = System.getProperty("uk.org.iscream.cms.server.ConfigurationLocation");
51 >        _systemConfigFile = System.getProperty("uk.org.iscream.cms.server.SystemConfigurationFile");
52  
53          // load the system config
54          loadSystemConfig();
# Line 90 | Line 92 | class ConfigurationManagerServant extends Configuratio
92          }
93  
94          // search config for group membership
95 <        LinkedList groups = getGroupMembership(source);
96 <
95 >        // and obain a list of groups by name
96 >        LinkedList nameGroups = getGroupMembership(source);
97          // add the hosts individual config to the start of the list
98 <        groups.addFirst(source);
98 >        nameGroups.addFirst(source);
99 >        
100 >        // this list will be used to compile the groupings
101 >        LinkedList groups = new LinkedList();
102 >                    
103 >        // if we are dealing with a Host.<hostname> request, then we also
104 >        // want to look for ip address details, as configuration entries may relate to it
105 >        // if we can't resolve it, we don't look.
106 >        LinkedList ipGroups = null;
107 >        if (source.startsWith("Host.")) {
108 >            // hostname is after Host.
109 >            String hostname = source.substring(5);
110 >            try {
111 >                String ip = "Host." + InetAddress.getByName(hostname).getHostAddress();
112 >                ipGroups = getGroupMembership(ip);
113 >                ipGroups.addFirst(ip);
114 >                // add to our list of groups
115 >                groups.addAll(ipGroups);
116 >            } catch (UnknownHostException e) {
117 >                _logger.write(toString(), Logger.ERROR, "could not resolve hostname - " + hostname);
118 >            }
119 >        }
120 >        
121 >        // add the rest of the groups to the end        
122 >        groups.addAll(nameGroups);
123  
124          Iterator i = groups.iterator();
125          String fileList = "";
# Line 123 | Line 149 | class ConfigurationManagerServant extends Configuratio
149              }
150          }
151          // add the system config as the final check
152 <        fileList += _systemConfigFile + ";";
152 >        fileList = _systemConfigFile + ";" + fileList;
153          _logger.write(toString(), Logger.DEBUG, "config tree - " + fileList);
154          
155          // build the configuration
# Line 163 | Line 189 | class ConfigurationManagerServant extends Configuratio
189       * Overrides the {@link java.lang.Object#toString() Object.toString()}
190       * method to provide clean logging (every class should have this).
191       *
192 <     * This uses the uk.ac.ukc.iscream.util.FormatName class
192 >     * This uses the uk.org.iscream.cms.server.util.FormatName class
193       * to format the toString()
194       *
195       * @return the name of this class and its CVS revision
# Line 281 | Line 307 | class ConfigurationManagerServant extends Configuratio
307       * @return the list of groups that this source is a member of
308       */
309      private LinkedList getGroupMembership(String source) {
310 +        _logger.write(toString(), Logger.DEBUG, "searching groups for - " + source);
311          LinkedList groupMembership = new LinkedList();        
312          Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator();
313          while(i.hasNext()) {
314              String key = (String) i.next();
315              if (key.startsWith("group.")) {
316                  String group = _systemConfig.getProperty(key);
317 +                // if it is in the group
318                  if (group.indexOf(source) != -1) {
319                      groupMembership.add(key.substring(6));
320 +                    _logger.write(toString(), Logger.DEBUG, "group match found for - " + source + " in - " + key);
321 +                
322 +                // if there are wildcards in the group
323 +                } else if (group.indexOf("*") != -1) {
324 +                    // check the wildcards apply to this srce
325 +                    if(StringUtils.wildcardCheck(source, group)) {
326 +                        groupMembership.add(key.substring(6));
327 +                        _logger.write(toString(), Logger.DEBUG, "wildcard group match found for - " + source + " in - " + key);
328 +                    }
329                  }
330 +                
331              }  
332          }
333          return groupMembership;
334 <    }    
334 >    }
335  
336      /**
337       * Build the properties as a Configuration to be
# Line 315 | Line 353 | class ConfigurationManagerServant extends Configuratio
353                  
354                  // some holders for variables
355                  File currentFile;
356 <                long lastModified, newLastModified;
357 <                Properties properties, prevProperties;
356 >                long lastModified = 0, newLastModified = 0;
357 >                Properties properties = null, prevProperties = null;
358                  
359                  // the root of all configurations will be the system config
360                  // so we need to open the properties of that
361                  Properties defaultProperties = new Properties();
324                currentFile = new File(_configPath, _systemConfigFile);
325                lastModified = currentFile.lastModified();
326                defaultProperties.load(new FileInputStream(currentFile));
362                  
363                  // This loop then iterates over the file list
364                  // creates the properties to be passed to the
365                  // Configuration constructor
366 <                do {
366 >                while (st.hasMoreTokens()) {
367                      properties = new Properties(defaultProperties);
368                      currentFile = new File(_configPath, st.nextToken());
369                      newLastModified = currentFile.lastModified();
# Line 337 | Line 372 | class ConfigurationManagerServant extends Configuratio
372                      }
373                      properties.load(new FileInputStream(currentFile));
374                      defaultProperties = properties;
375 <                } while (st.hasMoreTokens());
375 >                }
376  
377                  // this creates the configuration, all nice, ready to be returned
378                  ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified);
379                  org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
380                  config = ConfigurationHelper.narrow(objRef);
381 <
381 >                _logger.write(toString(), Logger.DEBUG, "returning built configuration");
382              } catch (Exception e) {
383                  // not sure what to do here
384                  // so we just log the error

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines