use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.
the class FuncId method execute.
/**
* 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 {
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocument();
if (DTM.NULL == docContext)
error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
XObject arg = m_arg0.execute(xctxt);
int argType = arg.getType();
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
NodeSetDTM nodeSet = nodes.mutableNodeset();
if (XObject.CLASS_NODESET == argType) {
DTMIterator ni = arg.iter();
StringVector usedrefs = null;
int pos = ni.nextNode();
while (DTM.NULL != pos) {
DTM ndtm = ni.getDTM(pos);
String refval = ndtm.getStringValue(pos).toString();
pos = ni.nextNode();
usedrefs = getNodesByID(xctxt, docContext, refval, usedrefs, nodeSet, DTM.NULL != pos);
}
// ni.detach();
} else if (XObject.CLASS_NULL == argType) {
return nodes;
} else {
String refval = arg.str();
getNodesByID(xctxt, docContext, refval, null, nodeSet, false);
}
return nodes;
}
use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.
the class FuncPosition method getPositionInContextNodeList.
/**
* 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 org.apache.xml.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;
}
use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.
the class FuncSum method execute.
/**
* 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);
}
use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.
the class WalkerFactory method newDTMIterator.
/**
* 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;
}
use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.
the class FunctionPattern method execute.
/**
* Test a node to see if it matches the given node test.
*
* @param xctxt XPath runtime context.
*
* @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* {@link org.apache.xpath.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;
}
Aggregations