Here are the examples of the java api class com.sun.org.apache.xml.internal.dtm.DTMIterator taken from open source projects.
1. LocPathIterator#asNode()
Project: openjdk
File: LocPathIterator.java
File: LocPathIterator.java
/** * Return the first node out of the nodeset, if this expression is * a nodeset expression. This is the default implementation for * nodesets. Derived classes should try and override this and return a * value without having to do a clone operation. * @param xctxt The XPath runtime context. * @return the first node out of the nodeset, or DTM.NULL. */ public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { DTMIterator iter = (DTMIterator) m_clones.getInstance(); int current = xctxt.getCurrentNode(); iter.setRoot(current, xctxt); int next = iter.nextNode(); // m_clones.freeInstance(iter); iter.detach(); return next; }
2. FuncSum#execute()
Project: openjdk
File: FuncSum.java
File: FuncSum.java
/** * Execute the function. The function must return * a valid object. * @param xctxt The current execution context. * @return A valid XObject. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode()); double sum = 0.0; int pos; while (DTM.NULL != (pos = nodes.nextNode())) { DTM dtm = nodes.getDTM(pos); XMLString s = dtm.getStringValue(pos); if (null != s) sum += s.toDouble(); } nodes.detach(); return new XNumber(sum); }
3. FuncCount#execute()
Project: openjdk
File: FuncCount.java
File: FuncCount.java
/** * Execute the function. The function must return * a valid object. * @param xctxt The current execution context. * @return A valid XObject. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { // DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode()); // // We should probably make a function on the iterator for this, // // as a given implementation could optimize. // int i = 0; // // while (DTM.NULL != nl.nextNode()) // { // i++; // } // nl.detach(); DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode()); int i = nl.getLength(); nl.detach(); return new XNumber((double) i); }
4. FuncLast#getCountOfContextNodeList()
Project: openjdk
File: FuncLast.java
File: FuncLast.java
/** * Get the position in the current context node list. * * @param xctxt non-null reference to XPath runtime context. * * @return The number of nodes in the list. * * @throws javax.xml.transform.TransformerException */ public int getCountOfContextNodeList(XPathContext xctxt) throws javax.xml.transform.TransformerException { // assert(null != m_contextNodeList, "m_contextNodeList must be non-null"); // If we're in a predicate, then this will return non-null. SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList(); // System.out.println("iter: "+iter); if (null != iter) return iter.getLastPos(xctxt); DTMIterator cnl = xctxt.getContextNodeList(); int count; if (null != cnl) { count = cnl.getLength(); // System.out.println("count: "+count); } else count = 0; return count; }
5. XPathContext#createDTMIterator()
Project: openjdk
File: XPathContext.java
File: XPathContext.java
/** * Create a new <code>DTMIterator</code> that holds exactly one node. * * @param node The node handle that the DTMIterator will iterate to. * * @return The newly created <code>DTMIterator</code>. */ public DTMIterator createDTMIterator(int node) { // DescendantIterator iter = new DescendantIterator(); DTMIterator iter = new com.sun.org.apache.xpath.internal.axes.OneStepIteratorForward(Axis.SELF); iter.setRoot(node, this); return iter; // return m_dtmManager.createDTMIterator(node); }
6. FunctionPattern#execute()
Project: openjdk
File: FunctionPattern.java
File: FunctionPattern.java
/** * Test a node to see if it matches the given node test. * * @param xctxt XPath runtime context. * * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt, int context) throws javax.xml.transform.TransformerException { DTMIterator nl = m_functionExpr.asIterator(xctxt, context); XNumber score = SCORE_NONE; if (null != nl) { int n; while (DTM.NULL != (n = nl.nextNode())) { score = (n == context) ? SCORE_OTHER : SCORE_NONE; if (score == SCORE_OTHER) { context = n; break; } } // nl.detach(); } nl.detach(); return score; }
7. Expression#asNode()
Project: openjdk
File: Expression.java
File: Expression.java
/** * Return the first node out of the nodeset, if this expression is * a nodeset expression. * @param xctxt The XPath runtime context. * @return the first node out of the nodeset, or DTM.NULL. * * @throws javax.xml.transform.TransformerException */ public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { DTMIterator iter = execute(xctxt).iter(); return iter.nextNode(); }
8. FunctionPattern#execute()
Project: openjdk
File: FunctionPattern.java
File: FunctionPattern.java
/** * Test a node to see if it matches the given node test. * * @param xctxt XPath runtime context. * * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { int context = xctxt.getCurrentNode(); DTMIterator nl = m_functionExpr.asIterator(xctxt, context); XNumber score = SCORE_NONE; if (null != nl) { int n; while (DTM.NULL != (n = nl.nextNode())) { score = (n == context) ? SCORE_OTHER : SCORE_NONE; if (score == SCORE_OTHER) { context = n; break; } } nl.detach(); } return score; }
9. FunctionPattern#execute()
Project: openjdk
File: FunctionPattern.java
File: FunctionPattern.java
/** * Test a node to see if it matches the given node test. * * @param xctxt XPath runtime context. * * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt, int context, DTM dtm, int expType) throws javax.xml.transform.TransformerException { DTMIterator nl = m_functionExpr.asIterator(xctxt, context); XNumber score = SCORE_NONE; if (null != nl) { int n; while (DTM.NULL != (n = nl.nextNode())) { score = (n == context) ? SCORE_OTHER : SCORE_NONE; if (score == SCORE_OTHER) { context = n; break; } } nl.detach(); } return score; }
10. FuncPosition#getPositionInContextNodeList()
Project: openjdk
File: FuncPosition.java
File: FuncPosition.java
/** * Get the position in the current context node list. * * @param xctxt Runtime XPath context. * * @return The current position of the itteration in the context node list, * or -1 if there is no active context node list. */ public int getPositionInContextNodeList(XPathContext xctxt) { // System.out.println("FuncPosition- entry"); // If we're in a predicate, then this will return non-null. SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList(); if (null != iter) { int prox = iter.getProximityPosition(xctxt); // System.out.println("FuncPosition- prox: "+prox); return prox; } DTMIterator cnl = xctxt.getContextNodeList(); if (null != cnl) { int n = cnl.getCurrentNode(); if (n == DTM.NULL) { if (cnl.getCurrentPos() == 0) return 0; // a problem for current(). try { cnl = cnl.cloneWithReset(); } catch (CloneNotSupportedException cnse) { throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(cnse); } int currentNode = xctxt.getContextNode(); // System.out.println("currentNode: "+currentNode); while (DTM.NULL != (n = cnl.nextNode())) { if (n == currentNode) break; } } // System.out.println("FuncPosition- cnl.getCurrentPos(): "+cnl.getCurrentPos()); return cnl.getCurrentPos(); } // System.out.println("FuncPosition - out of guesses: -1"); return -1; }
11. WalkerFactory#newDTMIterator()
Project: openjdk
File: WalkerFactory.java
File: WalkerFactory.java
/** * Create a new LocPathIterator iterator. The exact type of iterator * returned is based on an analysis of the XPath operations. * * @param compiler non-null reference to compiler object that has processed * the XPath operations into an opcode map. * @param opPos The position of the operation code for this itterator. * * @return non-null reference to a LocPathIterator or derivative. * * @throws javax.xml.transform.TransformerException */ public static DTMIterator newDTMIterator(Compiler compiler, int opPos, boolean isTopLevel) throws javax.xml.transform.TransformerException { int firstStepPos = OpMap.getFirstChildPos(opPos); int analysis = analyze(compiler, firstStepPos, 0); boolean isOneStep = isOneStep(analysis); DTMIterator iter; // Is the iteration a one-step attribute pattern (i.e. select="@foo")? if (isOneStep && walksSelfOnly(analysis) && isWild(analysis) && !hasPredicate(analysis)) { if (DEBUG_ITERATOR_CREATION) diagnoseIterator("SelfIteratorNoPredicate", analysis, compiler); // Then use a simple iteration of the attributes, with node test // and predicate testing. iter = new SelfIteratorNoPredicate(compiler, opPos, analysis); } else // Is the iteration exactly one child step? if (walksChildrenOnly(analysis) && isOneStep) { // Does the pattern specify *any* child with no predicate? (i.e. select="child::node()". if (isWild(analysis) && !hasPredicate(analysis)) { if (DEBUG_ITERATOR_CREATION) diagnoseIterator("ChildIterator", analysis, compiler); // Use simple child iteration without any test. iter = new ChildIterator(compiler, opPos, analysis); } else { if (DEBUG_ITERATOR_CREATION) diagnoseIterator("ChildTestIterator", analysis, compiler); // Else use simple node test iteration with predicate test. iter = new ChildTestIterator(compiler, opPos, analysis); } } else // Is the iteration a one-step attribute pattern (i.e. select="@foo")? if (isOneStep && walksAttributes(analysis)) { if (DEBUG_ITERATOR_CREATION) diagnoseIterator("AttributeIterator", analysis, compiler); // Then use a simple iteration of the attributes, with node test // and predicate testing. iter = new AttributeIterator(compiler, opPos, analysis); } else if (isOneStep && !walksFilteredList(analysis)) { if (!walksNamespaces(analysis) && (walksInDocOrder(analysis) || isSet(analysis, BIT_PARENT))) { if (false || DEBUG_ITERATOR_CREATION) diagnoseIterator("OneStepIteratorForward", analysis, compiler); // Then use a simple iteration of the attributes, with node test // and predicate testing. iter = new OneStepIteratorForward(compiler, opPos, analysis); } else { if (false || DEBUG_ITERATOR_CREATION) diagnoseIterator("OneStepIterator", analysis, compiler); // Then use a simple iteration of the attributes, with node test // and predicate testing. iter = new OneStepIterator(compiler, opPos, analysis); } } else // to work right. if (isOptimizableForDescendantIterator(compiler, firstStepPos, 0)) // && getStepCount(analysis) <= 3 // && walksDescendants(analysis) // && walksSubtreeOnlyFromRootOrContext(analysis) { if (DEBUG_ITERATOR_CREATION) diagnoseIterator("DescendantIterator", analysis, compiler); iter = new DescendantIterator(compiler, opPos, analysis); } else { if (isNaturalDocOrder(compiler, firstStepPos, 0, analysis)) { if (false || DEBUG_ITERATOR_CREATION) { diagnoseIterator("WalkingIterator", analysis, compiler); } iter = new WalkingIterator(compiler, opPos, analysis, true); } else { // return new MatchPatternIterator(compiler, opPos, analysis); if (DEBUG_ITERATOR_CREATION) diagnoseIterator("WalkingIteratorSorted", analysis, compiler); iter = new WalkingIteratorSorted(compiler, opPos, analysis, true); } } if (iter instanceof LocPathIterator) ((LocPathIterator) iter).setIsTopLevel(isTopLevel); return iter; }