I did that already using the jakarta commons configuration library.
All i did was extending the PropertyPlaceHolder with an property accepting 'org.apache.commons.configuration.Configuration'.
Next i overwrote the resolvePlaceholder with
Code:
protected String resolvePlaceholder(String placeholder, Properties properties) {
String value = null;
if ( true == this.configurationOverwrite && null != this.configuration ) {
value = resolvePlaceholder( placeholder, this.configuration );
}
if ( null == value ) {
value = super.resolvePlaceholder( placeholder, properties );
}
if ( null == value && null != this.configuration ) {
value = resolvePlaceholder( placeholder, this.configuration );
}
return( value );
}
That does the trick for a singel jakarta common configuration bean. To be a little bit more convenient i additionally provide an CompositeConfigurationWrapper which extends the CompositeConfiguration class to be a little bit more convenient in combining several configuration resources using the constructor-arg pattern.
Code:
public class CompositeConfigurationWrapper extends CompositeConfiguration {
protected static final Log log = LogFactory.getLog( CompositeConfigurationWrapper.class );
/**
* Standard constructor.
*
* Nothing special about this one.
*
*/
public CompositeConfigurationWrapper() {
super();
}
/**
* Constructor for usage in spring context definitions.
*
* @param configurations A list of org.apache.commons.configuration.Configuration instances.
*/
public CompositeConfigurationWrapper( List configurations ) {
super();
this.addConfigurations( configurations );
}
/**
* Setter for a list of configuration beans.
*
* @param configurations A list of org.apache.commons.configuration.Configuration instances.
*/
public void addConfigurations( List configurations ) {
if ( log.isDebugEnabled() ) {
log.debug( "[addConfigurations] BEGIN" );
}
synchronized( this ) {
for ( Iterator i = configurations.iterator(); i.hasNext(); ) {
super.addConfiguration( (Configuration)i.next() );
}
}
if ( log.isDebugEnabled() ) {
log.debug( "[addConfigurations] END" );
}
}
}
Cascading configuration using placeholders is now very easy.
greets
Sebastian