2

When i was working with Zend Framework, I used to have .ini configuration files, where I could do this:

[production]
setting1 = abc
setting2 = def

[development : production]
setting1 = ghi

And when I turned on the development application profile then the setting1 had a value of ghi, whereas in the prdouction mode it was abc. Is is possible to define such inherited settings in Apache Commons Configuration?

I know that I can define multiple configuration files and create a CompositeConfiuration from them, but how to tell the application that it should include only specific files in different modes? I do not also have an idea how to set these application profiles yet but another setting called PROFILE should do the work for me.

If possible, I would not want to split the settings in multiple files.

I can't find any information about how this should be done in Java.

fracz
  • 20,536
  • 18
  • 103
  • 149

1 Answers1

0

Apache Configuration reads the config options from a file into a memory data structure. Besides variable expansion, there is no further post processing by default. So your options are:

  • Put all options in a default config and then use individual "delta" configs that overwrite the defaults. Merge these individual files with CompositeConfiuration.

    This design follows Java's inheritance model: Base type which you extend to overwrite some value and add new ones.

  • Create a post processor that takes the huge config and turns that into a new config with your preferred merging rules applied.

  • Create a helper object to look up values by key in the config. That would allow you do the merging at lookup time.

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820