summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-03-30 09:34:34 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-03-30 09:34:34 -0400
commit3a80c78e801cb6227f058db22e87dc58fd0fd7f2 (patch)
treebeaa483da2afe26d6897effc3b1780ee754b2a7b /BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java
parent7ef3a2d28fd731a0f378b07a7d7f0c04911a3e8f (diff)
Added error-checking and input validation
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java
index 1e67a72..f2d2cf8 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java
@@ -5,6 +5,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
+import org.slf4j.LoggerFactory;
+
import bjc.utils.funcdata.FunctionalList;
/**
@@ -33,6 +35,10 @@ public class FileComponentRepository<E extends IDescribedComponent>
* Create a new component repository sourcing components from files in
* a directory
*
+ * An exception thrown during the loading of a component will only
+ * cause the loading of that component to fail, but a warning will be
+ * logged.
+ *
* @param dir
* The directory to read component files from
* @param reader
@@ -47,9 +53,17 @@ public class FileComponentRepository<E extends IDescribedComponent>
// Do nothing with directories. They probably contain
// support files for components
} else {
- E comp = reader.apply(fle);
+ try {
+ E comp = reader.apply(fle);
+
+ comps.put(comp.getName(), comp);
+ } catch (Exception ex) {
+ LoggerFactory.getLogger(getClass())
+ .warn("Error found reading component from file "
+ + fle.toString()
+ + ". This component will not be loaded");
+ }
- comps.put(comp.getName(), comp);
}
}
}
@@ -58,9 +72,7 @@ public class FileComponentRepository<E extends IDescribedComponent>
public FunctionalList<E> getComponentList() {
FunctionalList<E> ret = new FunctionalList<>();
- comps.forEach((name, comp) -> {
- ret.add(comp);
- });
+ comps.forEach((name, comp) -> ret.add(comp));
return ret;
}
@@ -72,6 +84,6 @@ public class FileComponentRepository<E extends IDescribedComponent>
@Override
public String getSource() {
- return "Read from directory " + sourcePath + ".";
+ return "Components read from directory " + sourcePath + ".";
}
}