1 16 19 package org.apache.xpath.patterns; 20 21 import org.apache.xml.dtm.Axis; 22 import org.apache.xml.dtm.DTM; 23 import org.apache.xml.dtm.DTMAxisTraverser; 24 import org.apache.xml.dtm.DTMFilter; 25 import org.apache.xpath.XPathContext; 26 import org.apache.xpath.axes.WalkerFactory; 27 import org.apache.xpath.objects.XObject; 28 31 public class ContextMatchStepPattern extends StepPattern 32 { 33 34 39 public ContextMatchStepPattern(int axis, int paxis) 40 { 41 super(DTMFilter.SHOW_ALL, axis, paxis); 42 } 43 44 58 public XObject execute(XPathContext xctxt) 59 throws javax.xml.transform.TransformerException 60 { 61 62 if (xctxt.getIteratorRoot() == xctxt.getCurrentNode()) 63 return getStaticScore(); 64 else 65 return this.SCORE_NONE; 66 } 67 68 83 public XObject executeRelativePathPattern( 84 XPathContext xctxt, StepPattern prevStep) 85 throws javax.xml.transform.TransformerException 86 { 87 88 XObject score = NodeTest.SCORE_NONE; 89 int context = xctxt.getCurrentNode(); 90 DTM dtm = xctxt.getDTM(context); 91 92 if (null != dtm) 93 { 94 int predContext = xctxt.getCurrentNode(); 95 DTMAxisTraverser traverser; 96 97 int axis = m_axis; 98 99 boolean needToTraverseAttrs = WalkerFactory.isDownwardAxisOfMany(axis); 100 boolean iterRootIsAttr = (dtm.getNodeType(xctxt.getIteratorRoot()) 101 == DTM.ATTRIBUTE_NODE); 102 103 if((Axis.PRECEDING == axis) && iterRootIsAttr) 104 { 105 axis = Axis.PRECEDINGANDANCESTOR; 106 } 107 108 traverser = dtm.getAxisTraverser(axis); 109 110 for (int relative = traverser.first(context); DTM.NULL != relative; 111 relative = traverser.next(context, relative)) 112 { 113 try 114 { 115 xctxt.pushCurrentNode(relative); 116 117 score = execute(xctxt); 118 119 if (score != NodeTest.SCORE_NONE) 120 { 121 if (executePredicates(xctxt, dtm, context)) 124 return score; 125 126 score = NodeTest.SCORE_NONE; 127 } 128 129 if(needToTraverseAttrs && iterRootIsAttr 130 && (DTM.ELEMENT_NODE == dtm.getNodeType(relative))) 131 { 132 int xaxis = Axis.ATTRIBUTE; 133 for (int i = 0; i < 2; i++) 134 { 135 DTMAxisTraverser atraverser = dtm.getAxisTraverser(xaxis); 136 137 for (int arelative = atraverser.first(relative); 138 DTM.NULL != arelative; 139 arelative = atraverser.next(relative, arelative)) 140 { 141 try 142 { 143 xctxt.pushCurrentNode(arelative); 144 145 score = execute(xctxt); 146 147 if (score != NodeTest.SCORE_NONE) 148 { 149 152 if (score != NodeTest.SCORE_NONE) 153 return score; 154 } 155 } 156 finally 157 { 158 xctxt.popCurrentNode(); 159 } 160 } 161 xaxis = Axis.NAMESPACE; 162 } 163 } 164 165 } 166 finally 167 { 168 xctxt.popCurrentNode(); 169 } 170 } 171 172 } 173 174 return score; 175 } 176 177 } 178 | Popular Tags |