use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class UnionChildIterator method acceptNode.
/**
* Test whether a specified node is visible in the logical view of a
* TreeWalker or NodeIterator. This function will be called by the
* implementation of TreeWalker and NodeIterator; it is not intended to
* be called directly from user code.
* @param n The node to check to see if it passes the filter or not.
* @return a constant to determine whether the node is accepted,
* rejected, or skipped, as defined above .
*/
public short acceptNode(int n) {
XPathContext xctxt = getXPathContext();
try {
xctxt.pushCurrentNode(n);
for (int i = 0; i < m_nodeTests.length; i++) {
PredicatedNodeTest pnt = m_nodeTests[i];
XObject score = pnt.execute(xctxt, n);
if (score != NodeTest.SCORE_NONE) {
// Note that we are assuming there are no positional predicates!
if (pnt.getPredicateCount() > 0) {
if (pnt.executePredicates(n, xctxt))
return DTMIterator.FILTER_ACCEPT;
} else
return DTMIterator.FILTER_ACCEPT;
}
}
} catch (javax.xml.transform.TransformerException se) {
// TODO: Fix this.
throw new RuntimeException(se.getMessage());
} finally {
xctxt.popCurrentNode();
}
return DTMIterator.FILTER_SKIP;
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class StepPattern method executePredicates.
/**
* Execute the predicates on this step to determine if the current node
* should be filtered or accepted.
*
* @param xctxt The XPath runtime context.
* @param dtm The DTM of the current node.
* @param currentNode The current node context.
*
* @return true if the node should be accepted, false otherwise.
*
* @throws javax.xml.transform.TransformerException
*/
protected final boolean executePredicates(XPathContext xctxt, DTM dtm, int currentNode) throws javax.xml.transform.TransformerException {
boolean result = true;
boolean positionAlreadySeen = false;
int n = getPredicateCount();
try {
xctxt.pushSubContextList(this);
for (int i = 0; i < n; i++) {
xctxt.pushPredicatePos(i);
try {
XObject pred = m_predicates[i].execute(xctxt);
try {
if (XObject.CLASS_NUMBER == pred.getType()) {
int pos = (int) pred.num();
if (positionAlreadySeen) {
result = (pos == 1);
break;
} else {
positionAlreadySeen = true;
if (!checkProximityPosition(xctxt, i, dtm, currentNode, pos)) {
result = false;
break;
}
}
} else if (!pred.boolWithSideEffects()) {
result = false;
break;
}
} finally {
pred.detach();
}
} finally {
xctxt.popPredicatePos();
}
}
} finally {
xctxt.popSubContextList();
}
return result;
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class StepPattern method execute.
/**
* Execute an expression in the XPath runtime context, and return the
* result of the expression.
*
*
* @param xctxt The XPath runtime context.
* @param currentNode The currentNode.
* @param dtm The DTM of the current node.
* @param expType The expanded type ID of the current node.
*
* @return The result of the expression in the form of a <code>XObject</code>.
*
* @throws javax.xml.transform.TransformerException if a runtime exception
* occurs.
*/
public XObject execute(XPathContext xctxt, int currentNode, DTM dtm, int expType) throws javax.xml.transform.TransformerException {
if (m_whatToShow == NodeTest.SHOW_BYFUNCTION) {
if (null != m_relativePathPattern) {
return m_relativePathPattern.execute(xctxt);
} else
return NodeTest.SCORE_NONE;
}
XObject score;
score = super.execute(xctxt, currentNode, dtm, expType);
if (score == NodeTest.SCORE_NONE)
return NodeTest.SCORE_NONE;
if (getPredicateCount() != 0) {
if (!executePredicates(xctxt, dtm, currentNode))
return NodeTest.SCORE_NONE;
}
if (null != m_relativePathPattern)
return m_relativePathPattern.executeRelativePathPattern(xctxt, dtm, currentNode);
return score;
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class FuncQname 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 = getArg0AsNode(xctxt);
XObject val;
if (DTM.NULL != context) {
DTM dtm = xctxt.getDTM(context);
String qname = dtm.getNodeNameX(context);
val = (null == qname) ? XString.EMPTYSTRING : new XString(qname);
} else {
val = XString.EMPTYSTRING;
}
return val;
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class FuncRound 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 {
final XObject obj = m_arg0.execute(xctxt);
final double val = obj.num();
if (val >= -0.5 && val < 0)
return new XNumber(-0.0);
if (val == 0.0)
return new XNumber(val);
return new XNumber(java.lang.Math.floor(val + 0.5));
}
Aggregations