summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-06-05 15:00:02 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-06-05 15:00:02 +0200
commit8bb86312d4f07dcb343ca2d212f4020906dbdb52 (patch)
treeffff8c00bcbdbd2ade95d762d669ed2b6c7e47da /src/main/java/com/c2kernel
parent42adf60503b73c5106b30ba57fdeba13b3091169 (diff)
ObjectProperties.getInstance() - if the property contains a String then
attempt to instantiate an object from that classname, otherwise return the object.
Diffstat (limited to 'src/main/java/com/c2kernel')
-rw-r--r--src/main/java/com/c2kernel/utils/ObjectProperties.java14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/main/java/com/c2kernel/utils/ObjectProperties.java b/src/main/java/com/c2kernel/utils/ObjectProperties.java
index dd4a59d..731b009 100644
--- a/src/main/java/com/c2kernel/utils/ObjectProperties.java
+++ b/src/main/java/com/c2kernel/utils/ObjectProperties.java
@@ -150,6 +150,18 @@ public class ObjectProperties extends Properties {
Logger.msg(" "+name+" ("+getObject(name).getClass().getSimpleName()+"): "+getObject(name).toString());
}
}
-
+
+ public Object getInstance(String propName, Object defaultVal) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
+ Object prop = getObject(propName, defaultVal);
+ if (prop == null || prop.equals(""))
+ throw new InstantiationException("Property '"+propName+"' was not defined. Cannot instantiate.");
+ if (prop instanceof String)
+ return Class.forName((String)prop).newInstance();
+ return prop;
+ }
+
+ public Object getInstance(String propName) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
+ return getInstance(propName, null);
+ }
}