1 package com.icl.saxon.expr; 2 import com.icl.saxon.Context; 3 import com.icl.saxon.om.Axis; 4 import com.icl.saxon.om.NodeInfo; 5 import com.icl.saxon.om.NodeEnumeration; 6 import com.icl.saxon.om.AxisEnumeration; 7 import com.icl.saxon.pattern.NodeTest; 8 import com.icl.saxon.sort.LocalOrderComparer; 9 10 16 17 final class AxisExpression extends NodeSetExpression { 18 19 private byte axis; 20 private NodeTest test; 21 private NodeInfo contextNode = null; 22 23 30 31 public AxisExpression(byte axis, NodeTest nodeTest) { 32 this.axis = axis; 33 this.test = nodeTest; 34 } 35 36 40 41 public Expression simplify() { 42 return this; 43 } 44 45 50 51 public int getDependencies() { 52 if (contextNode==null) { 53 return Context.CONTEXT_NODE; 54 } else { 55 return 0; 56 } 57 } 58 59 64 65 public boolean isContextDocumentNodeSet() { 66 return true; 67 } 68 69 77 78 public Expression reduce(int dep, Context context) throws XPathException { 79 if (contextNode == null && (dep & Context.CONTEXT_NODE) != 0) { 80 AxisExpression exp2 = new AxisExpression(axis, test); 81 exp2.contextNode = context.getContextNodeInfo(); 82 return exp2; 83 } else { 84 return this; 85 } 86 } 87 88 93 94 public NodeEnumeration enumerate(Context context, boolean sort) throws XPathException { 95 NodeInfo start; 96 if (contextNode==null) { 97 start = context.getContextNodeInfo(); 98 } else { 99 start = contextNode; 100 } 101 AxisEnumeration enum = start.getEnumeration(axis, test); 102 if (sort && !enum.isSorted()) { 103 NodeSetExtent ns = new NodeSetExtent(enum, LocalOrderComparer.getInstance()); 104 ns.sort(); 105 return ns.enumerate(); 106 } 107 return enum; 108 } 109 110 114 115 public Value evaluate(Context context) throws XPathException { 116 NodeSetIntent nsi = new NodeSetIntent( 117 (NodeSetExpression)reduce(Context.CONTEXT_NODE, context), 118 context.getController()); 119 nsi.setSorted(Axis.isForwards[axis]); 120 return nsi; 121 } 122 123 126 127 public void display(int level) { 128 System.err.println(indent(level) + Axis.axisName[axis] + "::" + test.toString()); 129 } 130 } 131 132 133 134 | Popular Tags |