use of org.apache.xpath.objects.XObject in project j2objc by google.
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 j2objc by google.
the class FuncExtFunction 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 {
if (xctxt.isSecureProcessing())
throw new javax.xml.transform.TransformerException(XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED, new Object[] { toString() }));
XObject result;
Vector argVec = new Vector();
int nArgs = m_argVec.size();
for (int i = 0; i < nArgs; i++) {
Expression arg = (Expression) m_argVec.elementAt(i);
XObject xobj = arg.execute(xctxt);
/*
* Should cache the arguments for func:function
*/
xobj.allowDetachToRelease(false);
argVec.addElement(xobj);
}
// dml
ExtensionsProvider extProvider = (ExtensionsProvider) xctxt.getOwnerObject();
Object val = extProvider.extFunction(this, argVec);
if (null != val) {
result = XObject.create(val, xctxt);
} else {
result = new XNull();
}
return result;
}
use of org.apache.xpath.objects.XObject in project j2objc by google.
the class FuncNormalizeSpace method executeCharsToContentHandler.
/**
* Execute an expression in the XPath runtime context, and return the
* result of the expression.
*
* @param xctxt The XPath runtime context.
*
* @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 void executeCharsToContentHandler(XPathContext xctxt, ContentHandler handler) throws javax.xml.transform.TransformerException, org.xml.sax.SAXException {
if (Arg0IsNodesetExpr()) {
int node = getArg0AsNode(xctxt);
if (DTM.NULL != node) {
DTM dtm = xctxt.getDTM(node);
dtm.dispatchCharactersEvents(node, handler, true);
}
} else {
XObject obj = execute(xctxt);
obj.dispatchCharactersEvents(handler);
}
}
use of org.apache.xpath.objects.XObject in project j2objc by google.
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));
}
use of org.apache.xpath.objects.XObject in project j2objc by google.
the class PredicatedNodeTest method executePredicates.
/**
* Process the predicates.
*
* @param context The current context node.
* @param xctxt The XPath runtime context.
*
* @return the result of executing the predicate expressions.
*
* @throws javax.xml.transform.TransformerException
*/
boolean executePredicates(int context, XPathContext xctxt) throws javax.xml.transform.TransformerException {
int nPredicates = getPredicateCount();
// System.out.println("nPredicates: "+nPredicates);
if (nPredicates == 0)
return true;
PrefixResolver savedResolver = xctxt.getNamespaceContext();
try {
m_predicateIndex = 0;
xctxt.pushSubContextList(this);
xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
xctxt.pushCurrentNode(context);
for (int i = 0; i < nPredicates; i++) {
// System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
XObject pred = m_predicates[i].execute(xctxt);
// System.out.println("pred.getType(): "+pred.getType());
if (XObject.CLASS_NUMBER == pred.getType()) {
if (DEBUG_PREDICATECOUNTING) {
System.out.flush();
System.out.println("\n===== start predicate count ========");
System.out.println("m_predicateIndex: " + m_predicateIndex);
// System.out.println("getProximityPosition(m_predicateIndex): "
// + getProximityPosition(m_predicateIndex));
System.out.println("pred.num(): " + pred.num());
}
int proxPos = this.getProximityPosition(m_predicateIndex);
int predIndex = (int) pred.num();
if (proxPos != predIndex) {
if (DEBUG_PREDICATECOUNTING) {
System.out.println("\nnode context: " + nodeToString(context));
System.out.println("index predicate is false: " + proxPos);
System.out.println("\n===== end predicate count ========");
}
return false;
} else if (DEBUG_PREDICATECOUNTING) {
System.out.println("\nnode context: " + nodeToString(context));
System.out.println("index predicate is true: " + proxPos);
System.out.println("\n===== end predicate count ========");
}
// only sets m_foundLast if on the last predicate
if (m_predicates[i].isStableNumber() && i == nPredicates - 1) {
m_foundLast = true;
}
} else if (!pred.bool())
return false;
countProximityPosition(++m_predicateIndex);
}
} finally {
xctxt.popCurrentNode();
xctxt.popNamespaceContext();
xctxt.popSubContextList();
m_predicateIndex = -1;
}
return true;
}
Aggregations