vmassol     2004/06/27 08:23:30

  Modified:    framework/src/java/share-12-13-14/org/apache/cactus/server/runner
                        ServletTestRunner.java
               
framework/src/java/share-12-13-14/org/apache/cactus/internal/configuration
                        ConfigurationInitializer.java
  Log:
  Second try at supporting re-initialization of the Cactus config files. Thanks to 
Kazuhito for noticing the flaw in the first attempt... :-)
  
  Revision  Changes    Path
  1.4       +2 -5      
jakarta-cactus/framework/src/java/share-12-13-14/org/apache/cactus/server/runner/ServletTestRunner.java
  
  Index: ServletTestRunner.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share-12-13-14/org/apache/cactus/server/runner/ServletTestRunner.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ServletTestRunner.java    27 Jun 2004 10:46:37 -0000      1.3
  +++ ServletTestRunner.java    27 Jun 2004 15:23:30 -0000      1.4
  @@ -110,10 +110,7 @@
           // Reset the Cactus initialization so that multiple web application can 
           // work with different Cactus configurations. Otherwise, as the Cactus 
           // initialization is JVM-wide, the config is not read again.
  -        ConfigurationInitializer.setIsInitialized(false);
  -        
  -        // Initialize Cactus configuration
  -        ConfigurationInitializer.initialize();
  +        ConfigurationInitializer.initialize(true);
   
           // Check whether XSLT transformations should be done server-side and
           // build the templates if an XSLT processor is available
  
  
  
  1.4       +32 -21    
jakarta-cactus/framework/src/java/share-12-13-14/org/apache/cactus/internal/configuration/ConfigurationInitializer.java
  
  Index: ConfigurationInitializer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share-12-13-14/org/apache/cactus/internal/configuration/ConfigurationInitializer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConfigurationInitializer.java     27 Jun 2004 15:02:56 -0000      1.3
  +++ ConfigurationInitializer.java     27 Jun 2004 15:23:30 -0000      1.4
  @@ -62,28 +62,29 @@
        * Have the Cactus configuration files been initialized?
        */
       private static boolean isInitialized;
  -
  +    
       /**
  -     * @param isInitializedFlag if false consider the system as uninitialized 
  -     *        so that next time the [EMAIL PROTECTED] #initialize()} method is 
called the
  -     *        Cactus configurations will be read again
  +     * Read Cactus configuration files.
  +     * 
  +     * @param isReinitialization if true then force a re-read of the Cactus 
  +     *        configuration files
        */
  -    public static void setIsInitialized(boolean isInitializedFlag)
  +    public static synchronized void initialize(boolean isReinitialization)
       {
  -        isInitialized = isInitializedFlag;
  +        if (!isInitialized)
  +        {    
  +            initializeConfig(isReinitialization);
  +            initializeLoggingConfig(isReinitialization);
  +            isInitialized = true;
  +        }
       }
  -    
  +
       /**
        * Read Cactus configuration files.
        */
       public static synchronized void initialize()
       {
  -        if (!isInitialized)
  -        {    
  -            initializeConfig();
  -            initializeLoggingConfig();
  -            setIsInitialized(true);
  -        }
  +        initialize(false);
       }
       
       /**
  @@ -92,8 +93,11 @@
        * (named CACTUS_CONFIG_PROPERTY) and if none has been defined tries to 
        * read the DEFAULT_CONFIG_NAME file from the classpath. All properties 
        * found are exported as java system properties.
  +     * 
  +     * @param isReinitialization if true then force a re-read of the Cactus 
  +     *        configuration files
        */
  -    private static void initializeConfig()
  +    private static void initializeConfig(boolean isReinitialization)
       {
           ResourceBundle config;
   
  @@ -132,13 +136,16 @@
               }
           }
   
  -        addSystemProperties(config);
  +        addSystemProperties(config, isReinitialization);
       }
   
       /**
        * Initialize logging configuration.
  +     * 
  +     * @param isReinitialization if true then force a re-read of the Cactus 
  +     *        configuration files
        */
  -    private static void initializeLoggingConfig()
  +    private static void initializeLoggingConfig(boolean isReinitialization)
       {
           String logConfig = System.getProperty(CACTUS_LOGGING_CONFIG_PROPERTY);
           if (logConfig != null)
  @@ -154,7 +161,7 @@
                   throw new ChainedRuntimeException("Failed to load logging "
                       + "configuration file [" + logConfig + "]");
               }
  -            addSystemProperties(bundle);
  +            addSystemProperties(bundle, isReinitialization);
           }
       }
   
  @@ -164,19 +171,23 @@
        *
        * @param theBundle the resource bundle containing the properties to
        *        set as system properties
  +     * @param isReinitialization if true then force a re-read of the Cactus 
  +     *        configuration files
        */
  -    private static void addSystemProperties(ResourceBundle theBundle)
  +    private static void addSystemProperties(ResourceBundle theBundle,
  +            boolean isReinitialization)
       {
           Enumeration keys = theBundle.getKeys();
   
           while (keys.hasMoreElements())
           {
               String key = (String) keys.nextElement();
  +
               // Only set the system property if it does not already exist.
               // This allows system properties defined on the command line
               // override Cactus properties located in the Cactus configuration
  -            // files
  -            if (System.getProperty(key) == null)
  +            // files.
  +            if ((System.getProperty(key) == null) || isReinitialization)
               {
                   System.setProperty(key, theBundle.getString(key));
               }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to