comparison 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
comparison
equal deleted inserted replaced
9231:082e8e808902 9232:5030c46d8cb4
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.artifacts.datacage.templating; 9 package org.dive4elements.river.artifacts.datacage.templating;
10 10
11 import org.dive4elements.artifacts.CallContext;
11 import org.dive4elements.artifacts.common.utils.XMLUtils; 12 import org.dive4elements.artifacts.common.utils.XMLUtils;
12 13
13 import org.dive4elements.river.utils.Pair; 14 import org.dive4elements.river.utils.Pair;
14 15
15 import java.lang.reflect.InvocationTargetException; 16 import java.lang.reflect.InvocationTargetException;
136 protected Deque<Pair<NamedConnection, ResultData>> connectionsStack; 137 protected Deque<Pair<NamedConnection, ResultData>> connectionsStack;
137 protected Deque<NodeList> macroBodies; 138 protected Deque<NodeList> macroBodies;
138 protected Deque<Object> groupExprStack; 139 protected Deque<Object> groupExprStack;
139 protected FunctionResolver functionResolver; 140 protected FunctionResolver functionResolver;
140 protected Map<String, XPathExpression> expressions; 141 protected Map<String, XPathExpression> expressions;
141 142 private final CallContext context;
142 143
143 public BuildHelper( 144
144 Node output, 145 public BuildHelper( final Node output, final List<NamedConnection> connections, final Map<String, Object> parameters, CallContext context ) {
145 List<NamedConnection> connections,
146 Map<String, Object> parameters
147 ) {
148 if (connections.isEmpty()) { 146 if (connections.isEmpty()) {
149 throw new IllegalArgumentException("no connections given."); 147 throw new IllegalArgumentException("no connections given.");
150 } 148 }
151 149
152 this.connections = connections; 150 connectionsStack = new ArrayDeque<Pair<NamedConnection, ResultData>>();
153 connectionsStack =
154 new ArrayDeque<Pair<NamedConnection, ResultData>>();
155 this.output = output;
156 frames = new StackFrames(parameters); 151 frames = new StackFrames(parameters);
157 owner = getOwnerDocument(output); 152 owner = getOwnerDocument(output);
158 macroBodies = new ArrayDeque<NodeList>(); 153 macroBodies = new ArrayDeque<NodeList>();
159 groupExprStack = new ArrayDeque<Object>(); 154 groupExprStack = new ArrayDeque<Object>();
155 expressions = new HashMap<String, XPathExpression>();
156 statements = new HashMap<String, CompiledStatement.Instance>();
157
158 this.connections = connections;
159 this.output = output;
160 this.context = context;
161
162 // Important call this at the end of constructor, it might call back
160 functionResolver = new FunctionResolver(this); 163 functionResolver = new FunctionResolver(this);
161 expressions = new HashMap<String, XPathExpression>(); 164 }
162 statements = 165
163 new HashMap<String, CompiledStatement.Instance>(); 166 public final CallContext getContext() {
164 } 167 return this.context;
165 168 }
169
166 public void build() throws SQLException { 170 public void build() throws SQLException {
167 try { 171 try {
168 // XXX: Thread safety is now established by the builder pool. 172 // XXX: Thread safety is now established by the builder pool.
169 //synchronized (template) { 173 //synchronized (template) {
170 for (Node current: rootsToList()) { 174 for (Node current: rootsToList()) {
1405 protected static Document getOwnerDocument(Node node) { 1409 protected static Document getOwnerDocument(Node node) {
1406 Document document = node.getOwnerDocument(); 1410 Document document = node.getOwnerDocument();
1407 return document != null ? document : (Document)node; 1411 return document != null ? document : (Document)node;
1408 } 1412 }
1409 1413
1410 public void build( 1414 public void build( final List<NamedConnection> connections, final Node output, final Map<String, Object> parameters, final CallContext context ) throws SQLException
1411 List<NamedConnection> connections,
1412 Node output,
1413 Map<String, Object> parameters
1414 )
1415 throws SQLException
1416 { 1415 {
1417 long startTime = System.currentTimeMillis(); 1416 long startTime = System.currentTimeMillis();
1418 try { 1417 try {
1419 BuildHelper helper = 1418 BuildHelper helper = new BuildHelper(output, connections, parameters, context);
1420 new BuildHelper(output, connections, parameters);
1421 helper.build(); 1419 helper.build();
1422 } 1420 }
1423 finally { 1421 finally {
1424 if (log.isDebugEnabled()) { 1422 if (log.isDebugEnabled()) {
1425 long stopTime = System.currentTimeMillis(); 1423 long stopTime = System.currentTimeMillis();

http://dive4elements.wald.intevation.org