changeset 8086:7ede7904c8a5

Be more tolerant with not existing artifact configurations.
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 12 Aug 2014 10:57:53 +0200
parents 75e62ea0e307
children 2fcbcc9bb59a
files artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java
diffstat 1 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java	Mon Aug 11 17:18:36 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java	Tue Aug 12 10:57:53 2014 +0200
@@ -206,8 +206,8 @@
     protected void configureTransitions(Document config, RiverContext context) {
         TransitionEngine engine = new TransitionEngine();
 
-        Document[] artifacts = getArtifactConfigurations(config);
-        logger.info("Found " + artifacts.length + " artifacts in the config.");
+        List<Document> artifacts = getArtifactConfigurations(config);
+        logger.info("Found " + artifacts.size() + " artifacts in the config.");
 
         for (Document doc: artifacts) {
 
@@ -248,13 +248,13 @@
      *
      * @return an array of Artifact configurations.
      */
-    protected Document[] getArtifactConfigurations(Document config) {
+    protected List<Document> getArtifactConfigurations(Document config) {
         NodeList artifacts = (NodeList) XMLUtils.xpath(
             config, XPATH_ARTIFACTS, XPathConstants.NODESET);
 
         int count = artifacts.getLength();
 
-        Document[] artifactDocs = new Document[count];
+        ArrayList<Document> docs = new ArrayList<Document>(count);
 
         for (int i = 0; i < count; i++) {
             Element tmp = (Element) artifacts.item(i);
@@ -262,11 +262,18 @@
             String xlink = tmp.getAttribute(XPATH_XLINK);
             xlink        = Config.replaceConfigDir(xlink);
 
-            File artifactFile = new File(xlink);
-            artifactDocs[i]   = XMLUtils.parseDocument(artifactFile);
+            File file = new File(xlink);
+            if (!file.isFile() || !file.canRead()) {
+                logger.warn("Artifact configuration '" + file + "' not found.");
+                continue;
+            }
+
+            Document doc = XMLUtils.parseDocument(file);
+            if (doc != null) {
+                docs.add(doc);
+            }
         }
-
-        return artifactDocs;
+        return docs;
     }
 
 
@@ -279,8 +286,8 @@
     protected void configureStates(Document config, RiverContext context) {
         StateEngine engine = new StateEngine();
 
-        Document[] artifacts = getArtifactConfigurations(config);
-        logger.info("Found " + artifacts.length + " artifacts in the config.");
+        List<Document> artifacts = getArtifactConfigurations(config);
+        logger.info("Found " + artifacts.size() + " artifacts in the config.");
 
         for (Document doc: artifacts) {
             List<State> states = new ArrayList<State>();

http://dive4elements.wald.intevation.org