diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java @ 415:7c018f466d6d

Datacage: Added river parameter to meta data services. flys-artifacts/trunk@1879 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 10 May 2011 12:43:12 +0000
parents df02137b3b28
children c09c9e05ecfa
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java	Tue May 10 12:19:17 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java	Tue May 10 12:43:12 2011 +0000
@@ -26,24 +26,24 @@
     public static final String DC_NAMESPACE_URI =
         "http://www.intevation.org/2011/Datacage";
 
-    protected Document   template;
+    protected Document template;
 
     public class BuildHelper
     {
-        protected Document    output;
-        protected StackFrames frames;
-        protected Connection  connection;
+        protected Document                       output;
+        protected StackFrames                    frames;
+        protected Connection                     connection;
         protected Map<String, CompiledStatement> statements;
 
-        public BuildHelper() {
-            frames     = new StackFrames();
-            statements = new HashMap<String, CompiledStatement>();
-        }
-
-        public BuildHelper(Document output, Connection connection) {
-            this();
+        public BuildHelper(
+            Document            output,
+            Connection          connection,
+            Map<String, Object> parameters
+        ) {
             this.output     = output;
             this.connection = connection;
+            frames          = new StackFrames(parameters);
+            statements      = new HashMap<String, CompiledStatement>();
         }
 
         public void build(List<Node> elements) throws SQLException {
@@ -89,8 +89,10 @@
 
             String stmntText = stmntNode.item(0).getTextContent();
 
-            if (stmntText == null) {
-                log.warn("dc:context: no sql statement found");
+            if (stmntText == null
+            || (stmntText = stmntText.trim()).length() == 0) {
+                log.warn("dc:context: no sql statement found -> ignored");
+                return;
             }
 
             CompiledStatement cs = statements.get(stmntText);
@@ -167,6 +169,19 @@
             element.setAttribute(name, value);
         }
 
+        protected void convert(Node parent, Element current) {
+
+            String variable = expand(current.getAttribute("var"));
+            String type     = expand(current.getAttribute("type"));
+
+            if (frames.containsKey(variable)) {
+                Object object = TypeConverter.convert(
+                    frames.get(variable),
+                    type);
+                frames.put(variable, object);
+            }
+        }
+
         protected String expand(String s) {
             Matcher m = CompiledStatement.VAR.matcher(s);
 
@@ -202,6 +217,9 @@
                     else if ("text".equals(localName)) {
                         text(parent, (Element)current);
                     }
+                    else if ("convert".equals(localName)) {
+                        convert(parent, (Element)current);
+                    }
                     else {
                         log.warn("unknown '" + localName + "' -> ignore");
                     }
@@ -237,16 +255,20 @@
     public Document build(Connection connection)
     throws SQLException
     {
-        return build(connection, XMLUtils.newDocument());
+        return build(connection, XMLUtils.newDocument(), null);
     }
 
-    public Document build(Connection connection, Document output)
+    public Document build(
+        Connection          connection,
+        Document            output,
+        Map<String, Object> parameters
+    )
     throws SQLException
     {
         NodeList roots = template.getElementsByTagNameNS(
             DC_NAMESPACE_URI, "template");
 
-        BuildHelper helper = new BuildHelper(output, connection);
+        BuildHelper helper = new BuildHelper(output, connection, parameters);
 
         List<Node> elements = new ArrayList<Node>();
 

http://dive4elements.wald.intevation.org