01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.query.algebra.evaluation.iterator;
07:
08: import info.aduna.iteration.CloseableIteration;
09: import info.aduna.iteration.ConvertingIteration;
10:
11: import org.openrdf.model.Value;
12: import org.openrdf.query.BindingSet;
13: import org.openrdf.query.QueryEvaluationException;
14: import org.openrdf.query.algebra.Extension;
15: import org.openrdf.query.algebra.ExtensionElem;
16: import org.openrdf.query.algebra.evaluation.EvaluationStrategy;
17: import org.openrdf.query.algebra.evaluation.QueryBindingSet;
18:
19: public class ExtensionIterator
20: extends
21: ConvertingIteration<BindingSet, BindingSet, QueryEvaluationException> {
22:
23: private final Extension extension;
24:
25: private final EvaluationStrategy strategy;
26:
27: public ExtensionIterator(
28: Extension extension,
29: CloseableIteration<BindingSet, QueryEvaluationException> iter,
30: EvaluationStrategy strategy)
31: throws QueryEvaluationException {
32: super (iter);
33: this .extension = extension;
34: this .strategy = strategy;
35: }
36:
37: @Override
38: public BindingSet convert(BindingSet sourceBindings)
39: throws QueryEvaluationException {
40: QueryBindingSet targetBindings = new QueryBindingSet(
41: sourceBindings);
42:
43: for (ExtensionElem extElem : extension.getElements()) {
44: Value targetValue = strategy.evaluate(extElem.getExpr(),
45: sourceBindings);
46:
47: if (targetValue != null) {
48: // Potentially overwrites bindings from super
49: targetBindings.setBinding(extElem.getName(),
50: targetValue);
51: }
52: }
53:
54: return targetBindings;
55: }
56: }
|