1 16 19 package com.sun.org.apache.xpath.internal.functions; 20 21 import com.sun.org.apache.xml.internal.dtm.DTM; 22 import com.sun.org.apache.xml.internal.dtm.DTMIterator; 23 import com.sun.org.apache.xpath.internal.XPathContext; 24 import com.sun.org.apache.xpath.internal.axes.SubContextList; 25 import com.sun.org.apache.xpath.internal.compiler.Compiler; 26 import com.sun.org.apache.xpath.internal.objects.XNumber; 27 import com.sun.org.apache.xpath.internal.objects.XObject; 28 29 33 public class FuncPosition extends Function 34 { 35 private boolean m_isTopLevel; 36 37 41 public void postCompileStep(Compiler compiler) 42 { 43 m_isTopLevel = compiler.getLocationPathDepth() == -1; 44 } 45 46 54 public int getPositionInContextNodeList(XPathContext xctxt) 55 { 56 57 SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList(); 60 61 if (null != iter) 62 { 63 int prox = iter.getProximityPosition(xctxt); 64 65 return prox; 67 } 68 69 DTMIterator cnl = xctxt.getContextNodeList(); 70 71 if (null != cnl) 72 { 73 int n = cnl.getCurrentNode(); 74 if(n == DTM.NULL) 75 { 76 if(cnl.getCurrentPos() == 0) 77 return 0; 78 79 try 85 { 86 cnl = cnl.cloneWithReset(); 87 } 88 catch(CloneNotSupportedException cnse) 89 { 90 throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(cnse); 91 } 92 int currentNode = xctxt.getContextNode(); 93 while(DTM.NULL != (n = cnl.nextNode())) 95 { 96 if(n == currentNode) 97 break; 98 } 99 } 100 return cnl.getCurrentPos(); 103 } 104 105 return -1; 107 } 108 109 117 public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException 118 { 119 double pos = (double) getPositionInContextNodeList(xctxt); 120 121 return new XNumber(pos); 122 } 123 124 127 public void fixupVariables(java.util.Vector vars, int globalsSize) 128 { 129 } 131 } 132 | Popular Tags |