Created
May 15, 2012 15:06
-
-
Save danieldbower/2702482 to your computer and use it in GitHub Desktop.
ApacheCommonsConfigPropertySource for using Apache Commons Config with Spring Property Sources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bowerstudios.config; | |
import java.util.ArrayList; | |
import java.util.Iterator; | |
import java.util.List; | |
import org.apache.commons.configuration.Configuration; | |
import org.springframework.core.env.EnumerablePropertySource; | |
/** | |
* Allow use of Apache Commons Configuration Objects as Spring PropertySources | |
*/ | |
public class ApacheCommonsConfigPropertySource extends | |
EnumerablePropertySource<Configuration> { | |
public ApacheCommonsConfigPropertySource(final String name, | |
final Configuration source) { | |
super(name, source); | |
} | |
@Override | |
public Object getProperty(final String arg0) { | |
return source.getProperty(arg0); | |
} | |
@Override | |
public String[] getPropertyNames() { | |
final List<String> keys = new ArrayList<String>(); | |
final Iterator<String> keysIterator = source.getKeys(); | |
while (keysIterator.hasNext()) { | |
keys.add(keysIterator.next()); | |
} | |
return keys.toArray(new String[keys.size()]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still works with commons-configuration 2, just update the imports.