summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/configuration/Configurator.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-04-02 15:07:33 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-04-02 15:07:33 -0400
commita023de85aa08c8f2b8b2441c6b14064eabee2775 (patch)
tree94d04671b0a6af4881efc4ac686045fed6d88ce6 /BJC-Utils2/src/main/java/bjc/utils/configuration/Configurator.java
parent56d2fa54fd37ce09eef0019798c7fab824b56e74 (diff)
Began work on general configuration stuff.
I'll leave this sit for a while, and come back to it after some thought
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/configuration/Configurator.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/configuration/Configurator.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/configuration/Configurator.java b/BJC-Utils2/src/main/java/bjc/utils/configuration/Configurator.java
new file mode 100644
index 0000000..e116dea
--- /dev/null
+++ b/BJC-Utils2/src/main/java/bjc/utils/configuration/Configurator.java
@@ -0,0 +1,44 @@
+package bjc.utils.configuration;
+
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Bind the values in a prepared class to a config file
+ *
+ * @author ben
+ *
+ */
+public class Configurator {
+ /**
+ * Bind the values in a config file to the values in a class,
+ * substituting default values if none are appropriate
+ *
+ * @param <E>
+ * The type of the object to bind
+ * @param clasz
+ * The class of the object to bind
+ * @param inputSource
+ * The source to get input from
+ * @return A instance of the provided class, with values filled in from
+ * a config file
+ */
+ public static <E> E readConfig(Class<E> clasz,
+ InputStream inputSource) {
+ try {
+ Constructor<E> noArgConstructor = clasz.getConstructor();
+
+ E backingStore = noArgConstructor.newInstance();
+
+ return backingStore;
+ } catch (NoSuchMethodException | SecurityException
+ | InstantiationException | IllegalAccessException
+ | IllegalArgumentException | InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+
+ return null;
+ }
+ }
+}