commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject cvs commit: jakarta-commons/configuration project.xml
Date Sun, 14 Nov 2004 19:06:32 GMT
oheger      2004/11/14 11:06:32

  Modified:    configuration/xdocs changes.xml
               configuration/src/test/org/apache/commons/configuration
                        TestConfigurationFactory.java
               configuration/src/java/org/apache/commons/configuration
                        ConfigurationFactory.java
               configuration project.xml
  Added:       configuration/conf testDigesterOptionalConfiguration.xml
  Log:
  Added support for optional configurations in configuration definition files for ConfigurationFactory.
  
  Revision  Changes    Path
  1.69      +9 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- changes.xml	21 Oct 2004 18:36:14 -0000	1.68
  +++ changes.xml	14 Nov 2004 19:06:32 -0000	1.69
  @@ -71,6 +71,15 @@
           AppletConfiguration, ServletConfiguration, ServletContextConfiguration,
           ServletRequestConfiguration, ServletFilterConfiguration.
         </action>
  +	  <action dev="oheger" type="fix" issue="32236">
  +		Fixed NPE that where caused in the constructors of file based
  +		configurations if an invalid file name was specified.
  +	  </action>
  +	  <action dev="oheger" type="add" issue="31797">
  +		Added support for optional configuration sources in definition files for
  +		ConfigurationFactory. A new required attribute allows to specify whether a
  +		configuration source is mandatory or optional.
  +	  </action>
       </release>
   
       <release version="1.0.1-dev" date="in CVS">
  
  
  
  1.17      +12 -1     jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationFactory.java
  
  Index: TestConfigurationFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationFactory.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- TestConfigurationFactory.java	18 Oct 2004 12:50:41 -0000	1.16
  +++ TestConfigurationFactory.java	14 Nov 2004 19:06:32 -0000	1.17
  @@ -44,6 +44,8 @@
               new File("conf/testDigesterConfiguration2.xml");
       private File testDigesterFileComplete =
               new File("conf/testDigesterConfiguration3.xml");
  +    private File testDigesterFileOptional =
  +            new File("conf/testDigesterOptionalConfiguration.xml");
   
       private File testDigesterBadXML = new File("conf/testDigesterBadXML.xml");
   
  @@ -237,6 +239,15 @@
           // test SystemConfiguration
           assertNotNull(config.getProperty("java.version"));
           assertEquals(System.getProperty("java.version"), config.getString("java.version"));
  +    }
  +    
  +    // Checks if optional configurations work
  +    public void testOptionalConfigurations() throws Exception
  +    {
  +        factory.setConfigurationURL(testDigesterFileOptional.toURL());
  +        Configuration config = factory.getConfiguration();
  +        assertTrue(config.getBoolean("test.boolean"));
  +        assertEquals("value", config.getProperty("element"));
       }
   
       private void checkUnionConfig() throws Exception
  
  
  
  1.1                  jakarta-commons/configuration/conf/testDigesterOptionalConfiguration.xml
  
  Index: testDigesterOptionalConfiguration.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1" ?>
  <!-- Configuration test file that demonstrates
       optional configurations -->
  
  <configuration>
    <properties fileName="test.properties"/>
    <xml fileName="test.xml" required="true"/>
    <hierarchicalXml fileName="nonExistingHierarchicalXML1.xml" required="false"/>
    <properties fileName="nonExistingProperties1.properties" required="no"/>
    <xml fileName="nonExistingXML1.xml" required="false"/>
    
    <additional>
      <properties fileName="nonExistingProperties2.properties" required="no"/>
      <hierarchicalXml fileName="nonExistingHierarchicalXML2.xml" required="false"/>
      <xml fileName="nonExistingXML2.xml" required="false"/>
    </additional>
  </configuration>
  
  
  
  1.18      +28 -7     jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java
  
  Index: ConfigurationFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ConfigurationFactory.java	18 Oct 2004 12:50:41 -0000	1.17
  +++ ConfigurationFactory.java	14 Nov 2004 19:06:32 -0000	1.18
  @@ -57,9 +57,12 @@
   
       /** Constant for the additional section.*/
       private static final String SEC_ADDITIONAL = SEC_ROOT + "additional/";
  -
  -    /** Constant for the name of the load method.*/
  -    private static final String METH_LOAD = "load";
  +    
  +    /** Constant for the optional attribute.*/
  +    private static final String ATTR_REQUIRED = "required";
  +    
  +    /** Constant for the fileName attribute.*/
  +    private static final String ATTR_FILENAME = "fileName";
   
       /** Constant for the default base path (points to actual directory).*/
       private static final String DEF_BASE_PATH = ".";
  @@ -275,21 +278,21 @@
               digester,
               matchString + "properties",
               new FileConfigurationFactory(PropertiesConfiguration.class),
  -            METH_LOAD,
  +            null,
               additional);
   
           setupDigesterInstance(
               digester,
               matchString + "xml",
               new FileConfigurationFactory(XMLConfiguration.class),
  -            METH_LOAD,
  +            null,
               additional);
   
           setupDigesterInstance(
               digester,
               matchString + "hierarchicalXml",
               new FileConfigurationFactory(HierarchicalXMLConfiguration.class),
  -            METH_LOAD,
  +            null,
               additional);
   
           setupDigesterInstance(
  @@ -488,6 +491,24 @@
           {
               FileConfiguration conf = (FileConfiguration) super.createObject(attributes);
               conf.setBasePath(getBasePath());
  +            conf.setFileName(attributes.getValue(ATTR_FILENAME));
  +            try
  +            {
  +                log.info("Trying to load configuration " + conf.getFileName());
  +                conf.load();
  +            }
  +            catch(ConfigurationException cex)
  +            {
  +                if(attributes.getValue(ATTR_REQUIRED) == null
  +                        || !PropertyConverter.toBoolean(attributes.getValue(ATTR_REQUIRED)).booleanValue())
  +                {
  +                    log.warn("Could not load optional configuration " + conf.getFileName());
  +                }
  +                else
  +                {
  +                    throw cex;
  +                }
  +            }
               return conf;
           }
       }
  
  
  
  1.40      +9 -7      jakarta-commons/configuration/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/project.xml,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- project.xml	14 Oct 2004 09:54:35 -0000	1.39
  +++ project.xml	14 Nov 2004 19:06:32 -0000	1.40
  @@ -155,16 +155,18 @@
         <id>ebourg</id>
         <email>smanux@lfjr.net</email>
       </developer>
  +	
  +	<developer>
  +		<name>Oliver Heger</name>
  +		<id>oheger</id>
  +		<email>oliver.heger@t-online.de</email>
  +		<organization>University Marburg</organization>
  +		<timezone>+1</timezone>
  +	</developer>
   
     </developers>
   
     <contributors>
  -
  -    <contributor>
  -      <name>Oliver Heger</name>
  -      <id>oheger</id>
  -      <email>oliver.heger@t-online.de</email>
  -    </contributor>
   
       <contributor>
         <name>J&ouml;rg Schaible</name>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message