new StringReader(xmlContext.getString())));
// Evaluate the expresion using Xalan.
getXPathContext();
xpContext.reset();
XObject xOb = query.execute(xpContext, docNode, null);
if (!returnResults)
{
// We don't want to return the actual results, we just
// want to know if there was at least one item in the
// result sequence.
if ((xOb instanceof XNodeSet) &&
(((XNodeSet)xOb).nodelist().getLength() > 0))
{ // If we have a sequence (XNodeSet) of length greater
// than zero, then we know that at least one item
// "exists" in the result so return a non-null list.
return new ArrayList(0);
}
else if (!(xOb instanceof XNodeSet))
// we have a single atomic value, which means the result is
// non-empty. So return a non-null list.
return new ArrayList(0);
else {
// return null; caller will take this to mean we have an
// an empty sequence.
return null;
}
}
// Else process the results.
NodeList nodeList = null;
int numItems = 0;
if (!(xOb instanceof XNodeSet))
// then we only have a single (probably atomic) item.
numItems = 1;
else {
nodeList = xOb.nodelist();
numItems = nodeList.getLength();
}
// Return a list of the items contained in the query results.
ArrayList itemRefs = new ArrayList();
if (nodeList == null)
// result is a single, non-node value (ex. it's an atomic number);
// in this case, just take the string value.
itemRefs.add(xOb.str());
else {
for (int i = 0; i < numItems; i++)
itemRefs.add(nodeList.item(i));
}