diff flys-aft/src/main/java/de/intevation/aft/Sync.java @ 4077:97de7a552b79

Load DIPS XML flys-aft/trunk@3452 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 16 Dec 2011 16:21:59 +0000
parents dbd0b3b1b8b8
children 44dc38ca8492
line wrap: on
line diff
--- a/flys-aft/src/main/java/de/intevation/aft/Sync.java	Fri Dec 16 11:26:12 2011 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/Sync.java	Fri Dec 16 16:21:59 2011 +0000
@@ -6,16 +6,19 @@
 
 import org.w3c.dom.Document;
 
+import javax.xml.xpath.XPathConstants;
+
 import de.intevation.utils.XML;
 
 import de.intevation.db.ConnectionBuilder;
-import de.intevation.db.ConnectedStatements;
 
 public class Sync
 {
     public static final String FLYS = "flys";
     public static final String AFT  = "aft";
 
+    public static final String XPATH_DIPS = "/sync/dips/@file";
+
     public static final String CONFIG_FILE =
         System.getProperty("config.file", "config.xml");
 
@@ -35,30 +38,50 @@
             System.exit(1);
         }
 
+        String dipsF = (String)XML.xpath(
+            config, XPATH_DIPS, XPathConstants.STRING, null, null);
+
+        if (dipsF == null || dipsF.length() == 0) {
+            System.err.println("Cannot find path to DiPS xml in config.");
+            System.exit(1);
+        }
+
+        File dipsFile = new File(dipsF);
+
+        if (!dipsFile.isFile() || !dipsFile.canRead()) {
+            System.err.println("Cannot find '" + dipsF + "'");
+            System.exit(1);
+        }
+
+        Document dips = XML.parseDocument(dipsFile, Boolean.FALSE);
+
+        if (dips == null) {
+            System.err.println("Cannot load DiPs document.");
+            System.exit(1);
+        }
+
         ConnectionBuilder aftConnectionBuilder =
             new ConnectionBuilder(AFT, config);
 
         ConnectionBuilder flysConnectionBuilder =
             new ConnectionBuilder(FLYS, config);
 
-        ConnectedStatements aftStatements  = null;
-        ConnectedStatements flysStatements = null;
+        SyncContext syncContext = null;
         try {
-            aftStatements  = aftConnectionBuilder.getConnectedStatements();
-            flysStatements = flysConnectionBuilder.getConnectedStatements();
+            syncContext = new SyncContext(
+                aftConnectionBuilder.getConnectedStatements(),
+                flysConnectionBuilder.getConnectedStatements(),
+                dips);
             Rivers rivers = new Rivers();
-            rivers.sync(aftStatements, flysStatements);
+            rivers.sync(syncContext);
         }
         catch (SQLException sqle) {
             sqle.printStackTrace();
             System.err.println("syncing failed: " + sqle.getMessage());
         }
         finally {
-            if (aftStatements != null) {
-                aftStatements.close();
-            }
-            if (flysStatements != null) {
-                flysStatements.close();
+            if (syncContext != null) {
+                syncContext.close();
             }
         }
     }

http://dive4elements.wald.intevation.org