Commons Configuration
  1. Commons Configuration
  2. CONFIGURATION-178

[configuration] Constructor for CompositeConfiguration which takes a list of Configurations

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      I have recently found a good case for CompositeConfiguration to have a
      constructor which takes a Collection of Configurations. I'm using the spring
      framework with my application, and I wanted to build a CompositeConfiguration
      bean out of several PropertiesConfigurations beans and a MapConfiguration bean.
      So I go along and declare beans for the properties and map configurations like so:

      <bean id="buildProperties"
      class="org.apache.commons.configuration.PropertiesConfiguration">
      <constructor-arg index="0"><value>build.properties</value></constructor-arg>
      </bean>

      <bean id="projectProperties"
      class="org.apache.commons.configuration.PropertiesConfiguration">
      <constructor-arg
      index="0"><value>project.properties</value></constructor-arg>
      </bean>

      <bean id="defaultProperties"
      class="org.apache.commons.configuration.MapConfiguration">
      <constructor-arg index="0">
      <map>
      <entry key="sync.facade.printService" value="mockPrintService"/>
      <entry key="sync.facade.fulfillService" value="mockFulfillService"/>
      <entry key="sync.facade.userService" value="mockUserService"/>
      <entry key="acegi.authenticationDao" value="mockAuthenticationDao"/>
      </map>
      </constructor-arg>
      </bean>

      Now, if you wanted to build a composite configuration out of these, normally
      you'd have to instantiate a new CompositeConfiguration, then call
      addConfiguration for each of the Configurations you'd want to add. However, in
      spring-land, this isn't quite possible, because you always deal with either
      bean-like properties (setters/getters) or constructor args. So, I propose adding
      a constructor does something to the effect of:

      public CompositeConfiguration(Collection configs) {
      Iterator i = configs.iterator();
      while (i.hasNext())

      { Configuration currentConfig = (Configuration)i.next(); addConfiguration(currentConfig); }

      }

      With this constructor, it allows you to configure our composite configuration
      like so:

      <bean id="compositeProperties"
      class="org.apache.commons.configuration.CompositeConfiguration">
      <constructor-arg index="0">
      <list>
      <ref bean="defaultProperties"/>
      <ref bean="buildProperties"/>
      <ref bean="projectProperties"/>
      </list>
      </constructor-arg>
      </bean>

      So now, you can inject this configuration into your other beans, or whatever you
      want. In my application, for example, I implemented a variation of
      PropertyPlaceholderConfigurer that is backed by a Configuration, instead of
      using properties files. I also use it to in some places to get at global type
      settings.

        Activity

        Hide
        Emmanuel Bourg added a comment -

        I added two new constructors accepting a collection, let me know how it works
        for you.

        You use of Commons Configuration with Spring is quite interesting, would you
        share it on our wiki ?

        http://wiki.apache.org/jakarta-commons/Configuration

        Show
        Emmanuel Bourg added a comment - I added two new constructors accepting a collection, let me know how it works for you. You use of Commons Configuration with Spring is quite interesting, would you share it on our wiki ? http://wiki.apache.org/jakarta-commons/Configuration

          People

          • Assignee:
            Unassigned
            Reporter:
            Joshua Nichols
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development