diff artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java @ 9232:5030c46d8cb4

Implemented xpath function that selectes the 'mean year' of a fixation-artifact. Needs to provide the ArtifactDatabase to the builder implementation.
author gernotbelger
date Fri, 06 Jul 2018 13:09:54 +0200
parents 175f113ed939
children
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java	Fri Jul 06 13:09:25 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java	Fri Jul 06 13:09:54 2018 +0200
@@ -8,6 +8,7 @@
 
 package org.dive4elements.river.artifacts.datacage.templating;
 
+import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.common.utils.XMLUtils;
 
 import org.dive4elements.river.utils.Pair;
@@ -138,31 +139,34 @@
         protected Deque<Object>                            groupExprStack;
         protected FunctionResolver                         functionResolver;
         protected Map<String, XPathExpression>             expressions;
+        private final CallContext context;
 
 
-        public BuildHelper(
-            Node                  output,
-            List<NamedConnection> connections,
-            Map<String, Object>   parameters
-        ) {
+        public BuildHelper( final Node output, final List<NamedConnection> connections, final Map<String, Object> parameters, CallContext context ) {
             if (connections.isEmpty()) {
                 throw new IllegalArgumentException("no connections given.");
             }
 
-            this.connections = connections;
-            connectionsStack =
-                new ArrayDeque<Pair<NamedConnection, ResultData>>();
-            this.output      = output;
+            connectionsStack = new ArrayDeque<Pair<NamedConnection, ResultData>>();
             frames           = new StackFrames(parameters);
             owner            = getOwnerDocument(output);
             macroBodies      = new ArrayDeque<NodeList>();
             groupExprStack   = new ArrayDeque<Object>();
-            functionResolver = new FunctionResolver(this);
             expressions      = new HashMap<String, XPathExpression>();
-            statements       =
-                new HashMap<String, CompiledStatement.Instance>();
+            statements       = new HashMap<String, CompiledStatement.Instance>();
+
+            this.connections = connections;
+            this.output      = output;
+            this.context = context;
+
+            // Important call this at the end of constructor, it might call back
+            functionResolver = new FunctionResolver(this);
         }
-
+        
+        public final CallContext getContext() {
+            return this.context;
+        }
+        
         public void build() throws SQLException {
             try {
                 // XXX: Thread safety is now established by the builder pool.
@@ -1407,17 +1411,11 @@
         return document != null ? document : (Document)node;
     }
 
-    public void build(
-        List<NamedConnection> connections,
-        Node                  output,
-        Map<String, Object>   parameters
-    )
-    throws SQLException
+    public void build( final List<NamedConnection> connections, final Node output, final Map<String, Object> parameters, final CallContext context ) throws SQLException
     {
         long startTime = System.currentTimeMillis();
         try {
-            BuildHelper helper =
-                new BuildHelper(output, connections, parameters);
+            BuildHelper helper = new BuildHelper(output, connections, parameters, context);
             helper.build();
         }
         finally {

http://dive4elements.wald.intevation.org