| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.accum; |
| 9 |
|
| 10 |
import net.sf.saxon.om.AxisInfo; |
| 11 |
import net.sf.saxon.om.NodeInfo; |
| 12 |
import net.sf.saxon.om.Sequence; |
| 13 |
import net.sf.saxon.pattern.AnyNodeTest; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
import net.sf.saxon.tree.iter.AxisIterator; |
| 16 |
import net.sf.saxon.tree.tiny.TinyNodeImpl; |
| 17 |
import net.sf.saxon.tree.util.Navigator; |
| 18 |
|
| 19 |
import java.util.Stack; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class PathMappedAccumulatorData implements IAccumulatorData { |
| 28 |
|
| 29 |
private IAccumulatorData originalData; |
| 30 |
private NodeInfo origin; |
| 31 |
|
| 32 |
PathMappedAccumulatorData(IAccumulatorData original, NodeInfo origin) { |
| 33 |
this.originalData = original; |
| 34 |
this.origin = origin; |
| 35 |
} |
| 36 |
|
| 37 |
@Override |
| 38 |
public Accumulator getAccumulator() { |
| 39 |
return null; |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
public Sequence<?> getValue(NodeInfo node, boolean postDescent) throws XPathException { |
| 44 |
return originalData.getValue(map(node), postDescent); |
| 45 |
} |
| 46 |
|
| 47 |
private NodeInfo map(NodeInfo node) { |
| 48 |
if (origin instanceof TinyNodeImpl && node instanceof TinyNodeImpl) { |
| 49 |
|
| 50 |
int nodeNrInSubtree = ((TinyNodeImpl)node).getNodeNumber(); |
| 51 |
return ((TinyNodeImpl)origin).getTree().getNode(nodeNrInSubtree + ((TinyNodeImpl)origin).getNodeNumber()); |
| 52 |
} else { |
| 53 |
|
| 54 |
Stack<Integer> path = new Stack<Integer>(); |
| 55 |
NodeInfo ancestor = node; |
| 56 |
while (ancestor != null) { |
| 57 |
path.push(Navigator.getSiblingPosition(ancestor, AnyNodeTest.getInstance(), Integer.MAX_VALUE)); |
| 58 |
ancestor = ancestor.getParent(); |
| 59 |
} |
| 60 |
NodeInfo target = origin; |
| 61 |
while (!path.isEmpty()) { |
| 62 |
int pos = path.pop(); |
| 63 |
AxisIterator kids = target.iterateAxis(AxisInfo.CHILD); |
| 64 |
while (pos-- > 0) { |
| 65 |
target = kids.next(); |
| 66 |
assert (target != null); |
| 67 |
} |
| 68 |
} |
| 69 |
return target; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
} |
| 75 |
|