Decorator pattern in reading configuration

Almost all applications have some configuration properties they use for various purposes. Typically you have Key/Value pairs representing the property names and values. Therefore, internally, a Properties or other Map is a good representation for these configuration settings.

So while there's a good way to store this data internally, there are tons of meduims to read it from: XML files, Properties file, Servlet init parameters, etc. Additionally, there are several ways to read multiple files. For example, given a directory load all files below it. Or load all resource files.

Say you have someConfigurationLoader interface. I'm theorizing that you could use the Decorator pattern with XMLConfigurationLoader, PropertiesConfigurationLoader, ServletConfigurationLoader, MultipleFileConfigurationLoader, ResourceConfigurationLoader, etc.

I'm having trouble coming up with the implementation for decorators like the MultipleFileConfigurationLoader and it's making me think that the Decorator pattern isn't applicable here. What do ya'll think?

[1084 byte] By [iamiqrka] at [2007-10-2 0:04:16]
# 1

Hm, think the pattern you're looking for is something inbetween Proxy and Composite if I got yout problem right.

Your MultiFileLoader is the composite object which contains all individual loaders. MultiFileLoader implements the same interface all Loaders do and it's only task is to delegate calls to all it's delegatees.

Cheers,

Peter

Soylenta at 2007-7-15 16:03:42 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
Just forgot to say:There are already config solutions out there, for instance http://www.jconfig.org/ and http://jfig.sourceforge.net/
Soylenta at 2007-7-15 16:03:42 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
JFig looks like it's exactly what I need. Thanks.
iamiqrka at 2007-7-15 16:03:42 > top of Java-index,Other Topics,Patterns & OO Design...