Author: lindner
Date: Mon Dec 8 14:13:02 2008
New Revision: 724511
URL: http://svn.apache.org/viewvc?rev=724511&view=rev
Log:
SHINDIG-767 | Patch from Ben Smith - PropertiesModule should be able to
property files other than the default
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java?rev=724511&r1=724510&r2=724511&view=diff
==============================================================================
---
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java
(original)
+++
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java
Mon Dec 8 14:13:02 2008
@@ -32,7 +32,8 @@
import java.util.Properties;
/**
- * Injects everything from the shindig.properties as a Named value.
+ * Injects everything from the a property file as a Named value
+ * Uses the default shindig.properties file if no other is provided
*/
public class PropertiesModule extends AbstractModule {
@@ -41,14 +42,31 @@
private final Properties properties;
public PropertiesModule() {
+ this.properties = readPropertyFile(DEFAULT_PROPERTIES);
+ }
+
+ public PropertiesModule(String propertyFile) {
+ this.properties = readPropertyFile(propertyFile);
+ }
+
+ public PropertiesModule(Properties properties) {
+ this.properties = properties;
+ }
+
+ @Override
+ protected void configure() {
+ Names.bindProperties(this.binder(), properties);
+ }
+
+ private Properties readPropertyFile(String propertyFile) {
+ Properties properties = new Properties();
InputStream is = null;
try {
- is = ResourceLoader.openResource(DEFAULT_PROPERTIES);
- properties = new Properties();
+ is = ResourceLoader.openResource(propertyFile);
properties.load(is);
} catch (IOException e) {
throw new CreationException(Arrays.asList(
- new Message("Unable to load properties: " + DEFAULT_PROPERTIES)));
+ new Message("Unable to load properties: " + propertyFile)));
} finally {
try {
if (is != null) {
@@ -58,15 +76,8 @@
// weird
}
}
- }
-
- public PropertiesModule(Properties properties) {
- this.properties = properties;
- }
-
- @Override
- protected void configure() {
- Names.bindProperties(this.binder(), properties);
+
+ return properties;
}
}